C Programming Reference
 
C Programming Reference >> C  Programming Reference Question Bank >>

19/07/07 - 560 Views - Ratings :   3.5 of 5 / 2 Votes

Level - Beginner
      

Question -

What will be  the output of the following code and why?


#include <stdio.h>
void main()
{
int x,y;
x = 5;
y = ++x * ++x;
printf("Value of x = %d and Value of y = %d\n",x,y);
}
Answer -
Value of  of x = 7 and Value of y = 49
Explanation -

Not a very tough question. Important thing to note that in any expression pre increment operator has a higher prority than arithemetic operator as a result value of x is increment is first two times then value of y is evaluated. So y = 7*7 = 49.

This question will result in same output for most of the compilers, but some rare compiler may produce an entire diffrenent parse tree resulting in an undefined result.

Reader Comments -

Author Comments
Add Comments 


Name :    
Reply :   


Rating :

Code :
Code

 

 
© 2006 cencyclopedia.com