What will be the output of the program?
#include <stdio.h>
int main()
{
int a=0, b=1, c=3;
*((a) ? &b : &a) = a ? b : c;
printf("%d, %d, %d\n", a, b, c);
return 0;
}
Answer: C
Correct answer: 3, 1, 3
Both conditionals test a, which is 0 and therefore false. The left-hand side selects &a, so the assignment targets a; the right-hand side selects c, which is 3. So a becomes 3 while b and c are untouched, giving 3, 1, 3. Note that a conditional expression can be dereferenced to form an lvalue like this only because both branches are pointers.
Please log in or register to report this question.