Condition Statement MCQ 4 : Multiple conditions inside if statement

May 24, 2010 No Comments » Hits : 222





If – Else MCQ : Multiple Conditions Separated by Comma Operator

#include<stdio.h>
void main()
{
int a=1,b=2;
if(printf("%d",printf("123")),0)
  {
  printf("Connected");
  }
else
  {
  printf("Disconnected");
  }
}

Options :

  1. 123Connected
  2. 1233Connected
  3. 123Disconnected
  4. 1233Disconnected
Output
1233Disconnected

Why ?

printf("%d",printf("123"))
  1. This is Example of nested Printf
  2. Inner  printf will return number of Character Printed to Outer Printf so 1233 will be surly Printed.
  3. If statement will execute else part because if(1233,0). will results in if (0) – ” In Short Comma Operator Returns Rightmost Operand”so “Disconnected” will be printed

Incoming search terms: