Output for c program


What will be the output of the following C program?

int main()
char c = ‘A’;
int x=5, y=10, res1, res2;
res1=c++ || x++ ||–y;
res2 = ++x && --c && ++y;
printf("%d %d %d %c", res1, res2, x+y , c);
return 0;
What is the output?


The answer will be: “A 11 18 A”.
res1= ‘A’ or 5 or -10
That will yeild ‘A’ itself.
And now, the values of c and x will become ‘B’ and ‘6’.
Now, res2= 7 and A and 10 that will yeild 11
And now, values of x, c and y will become 7, ‘A’ and 11.
Hence, on printing the values of res1, res2, x+y and c, the output generated will be A 11 18 A.