Discussion
#include <stdio.h>
int main()
{
unsigned int i = 65000;
while (i++ != 0);
printf("%d", i);
return 0;
}
Answer: B
Correct answer: 1
i++ yields the old value and then increments, so the loop keeps going while the old value is non-zero. Starting at 65000 the variable climbs to the maximum for an unsigned int and then wraps round to 0 - wrapping is defined behaviour for unsigned types. On that pass the test sees 0 and stops, but i has already been incremented once more, to 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