What will be the output of the program?
#include <stdio.h>
int main()
{
int x = 10, y = 20;
if(!(!x) && x)
printf("x = %d\n", x);
else
printf("y = %d\n", y);
return 0;
}
Answer: C
Correct answer: x = 10
!x is 0 since x is non-zero, and !(!x) is therefore 1 - the double negation normalises any non-zero value to 1. The condition 1 && 10 is true, so the first branch runs and prints the value of x, which the logical operators never altered: 10.
Please log in or register to report this question.