Discussion
What will be the output of
int x=5; printf("%d", x++);
Answer: A
The output is 5.
x++ is the post-increment operator: the expression's value is the current value of x, and x is increased only afterwards. So printf receives 5 and prints 5, and x becomes 6 once the statement is done.
6 would be printed by the pre-increment ++x, which increments first and then uses the new value. 4 would need a decrement, and the code is valid C, so there is no error.
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