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.
Please log in or register to report this question.