C Programming - Control Instructions - Discussion

Discussion Forum : Control Instructions - General Questions (Q.No. 2)
How many times the while loop will get executed if a short int is 2 byte wide?
int main()
    int j=1;
    while(j <= 255)
        printf("%c %d\n", j, j);
    return 0;
Infinite times
255 times
256 times
254 times
Answer: Option

The while(j <= 255) loop will get executed 255 times. The size short int(2 byte wide) does not affect the while() loop.

59 comments Page 1 of 6.

Abhijeet Dhumal said:   9 months ago
Answer is 255.

I agree with the given answer.

Abdulla.S said:   2 years ago
Suppose the size of the short int is 5 bytes, then what would happen? please explain to me.

Aditya Gupta said:   5 years ago
But if we put char j instead of short int j. Why it runs infinite times then, When the both acquire same space of 2 bytes?

Vikas kumar said:   6 years ago
Answer is an infinite loop like from range of 0 to 128 then from -1to 128 and goes on repeating and after compiling and executing the program it gives an infinite loop.

Priya said:   6 years ago
int a;

Why it results in an infinite loop? Please explain.

Nagabhushan said:   7 years ago
int k=1;
while (k<n)

How many times the loop repeats?

Please tell me the answer.

Vishal zadafiya said:   7 years ago
Loop will execute infinite time because int by default signed ao its range is -127 to 128 first it's execute 1 to 128 then 0 to 127 and again start 1 to 128.

Sowjanya said:   7 years ago
Thank you all for your suggestions.

Tara said:   7 years ago
The loop will execute for infinity times, like 0 to 128.

Then -128 to -1 again from 0-128, the loop repeats.

Vibhan said:   7 years ago
Sorry friends but get excited 256 because it check while loop at the time when j value is 256. So while statement execute 256 times.

Post your comments here:

Your comments will be displayed after verification.