Discussion
How many times the while loop will get executed if a short int is 2 byte wide?
#include <stdio.h>
int main()
{
int j=1;
while(j <= 255)
{
printf("%c %d\n", j, j);
j++;
}
return 0;
}
Answer: B
Correct answer: 255 times
j runs from 1 and the loop continues while j <= 255, so it executes for j equal to 1, 2, …, 255 - 255 passes. The width of a short is a red herring: j is declared int, and 255 is nowhere near the limit of either type.
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