926 views
0 0 votes
void main( )
{ 
    int a=3,b=1;
     if( b>a, a>b) printf(“%d”,--b);
    else printf(“%d”, a++); 
}

"Two things are infinite: the universe and human stupidity; and I'm not sure about the universe."

1 Answer

1 1 vote

Consider the Line in program

 if( b>a, a>b)

Here b>a will evaluated false  and a>b will evaluated true

So conditional statement becomes

 if( 0, 1)
In the C and C++ programming languages, the comma operator (represented by the token ,) 
is a binary operator that evaluates its first operand and discards the result, 
and then evaluates the second operand and returns this value (and type).

Note:Comma operator returns the value of the rightmost operand when multiple comma operators are used .

So it will return 1 to if statement as condition a>b will evaluated true so if statement will be executed  return printf(“%d”,--b); value.

,Here b=1

So output:0

• edited by
Position:
Show:

Related questions

9 9 votes
3 3 answers
434
434 views
GO Classes asked Jun 17
434 views
What is the output of the following code?#include <stdio.h void update(int n, int *p) { if (n <= 0) return; *p = *p + n; update(n - 2, p); *p = *p + n; } int main() { int...
6 6 votes
2 2 answers
368
368 views
GO Classes asked Jun 17
368 views
What is the output of the following code?#include <stdio.h int fun(int n) { int x = n; if (n <= 0) return 0; x = x + 2; return x + fun(n - 2); } int main() { printf("%d",...
6 6 votes
2 2 answers
408
408 views
GO Classes asked Jun 17
408 views
How many times is $\texttt{fun()}$ called when the following code is executed? (Count the first call also).#include <stdio.h int fun(int n) { if (n <= 1) return 1; return...
6 6 votes
3 3 answers
375
375 views
GO Classes asked Jun 17
375 views
What is the output of the following code?#include <stdio.h int fun(int n) { if (n <= 1) return n + 1; if (n % 2 == 0) return fun(n - 1) + fun(n - 2); return fun(n - 2) + ...