Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Write a if condition which executes both if and else statements

–2 votes
asked Mar 27, 2018 by myl smart (100 points)

8 Answers

0 votes
answered Mar 27, 2018 by MaHi
 if(!printf("hello ")) {
    printf("hello");
  } else {
    printf("world");
  }

commented Mar 28, 2018 by John Gabriel (310 points)
That does not execute both statements.
commented Mar 29, 2018 by Blerand
int i=0;
    a:
    
    if(i==0)
    {       printf("Hello World IF STATEMENT \n");
            i++;
            goto a;
        
    }
        
    else
    {       printf("Hello World ELSE STATEMENT \n");
        
    }
0 votes
answered Mar 28, 2018 by John Gabriel (310 points)
You can't do this and there is no logical reason to do it.
0 votes
answered Mar 28, 2018 by Balaji Krishnamurty
This is not possible. It would go against the definition of the "if" statement.
0 votes
answered Mar 29, 2018 by David
if(!printf("hello "))
 {
    printf("hello");
    printf("world");
  }
0 votes
answered Mar 30, 2018 by anonymous

int a;

if (a%2==0)

printf("even");

else

printf("odd");

0 votes
answered Mar 31, 2018 by Car
if (1

#define else if(1)){

 // block a} else { //block b};
0 votes
answered Apr 6, 2018 by kodathalasudarshan reddy (340 points)
we can do using fork() system call

if(fork())

printf("printf in if loop");

else

printf("printf in else loop");
0 votes
answered Apr 6, 2018 by kodathalasudarshan reddy (340 points)
we can do using fork system call

#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>

main ()
{
  if (fork ())

    printf ("printf in if loop\n");

  else

    printf ("printf in else loop\n");

}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...