Discussion
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.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development