Discussion
What is the output of this C code?
int main()
{
int a = 10, b = 10;
if (a = 5)
b--;
printf("%d, %d", a, b--);
}
Answer: C
Correct answer: a = 5, b = 9
if (a = 5) assigns 5 to a, and the value of that assignment, 5, is non-zero and so true. The body runs, taking b from 10 to 9. The printf then shows a as 5 and, because b-- is a post-decrement, the value passed is the current 9 - the decrement to 8 happens after the value has been handed over, and nothing prints afterwards.
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