Discussion
What will be the output of the program?
#include <stdio.h>
int main()
{
unsigned int i = 65535; /* Assume 2 byte integer*/
while(i++ != 0)
printf("%d",++i);
printf("\n");
return 0;
}
Answer: A
Correct answer: Infinite loop
i++ tests the old value and then increments, and the body increments again with ++i. Starting from 65535, the test takes i to 0, the body takes it to 1, and thereafter the value seen by the test is always odd - 1, 3, 5, … Wrapping round at 65536 lands on 1 again, never on 0, so the condition is never false.
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