Discussion
What is the output of this C code?
void main()
{
int a = 5, b = -7, c = 0, d;
d = ++a && ++b || ++c;
printf("\n%d%d%d%d", a, b, c, d);
}
Answer: D
Correct answer: 6 -6 0 1
Evaluate left to right, remembering that any non-zero value is true.
++amakesa6, which is true.++bmakesb-6 - non-zero, so also true.- The
&&is therefore true, so||short-circuits and++cnever runs:cstays 0. dgets the value of the whole expression, 1.
Output: 6 -6 0 1.
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