Tuesday 19 March 2013

if(a,b,x,y)


    main(){
  int a= 0;int b = 20;char x =1;char y =10;
  if(a,b,x,y)
        printf("hello");
 }
Answer:
hello
Explanation:
The comma operator has associativity from left to right. Only the rightmost value is returned and the other values are evaluated and ignored. Thus the value of last variable y is returned to check in if. Since it is a non zero value if becomes true so, "hello" will be printed.


Blog Author: Vijay Kumar

Go to: Java Aptitude


No comments:

Post a Comment