C Programming - Control Instructions - Discussion
Discussion Forum : Control Instructions - General Questions (Q.No. 2)
2.
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: Option
Explanation:
The while(j <= 255) loop will get executed 255 times. The size short int(2 byte wide) does not affect the while() loop.
Discussion:
59 comments Page 1 of 6.
Abhijeet Dhumal said:
1 year ago
Answer is 255.
I agree with the given answer.
I agree with the given answer.
Abdulla.S said:
3 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:
7 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:
7 years ago
int a;
for(a=1;a<=32767;a++)
printf("%d",a);
Why it results in an infinite loop? Please explain.
for(a=1;a<=32767;a++)
printf("%d",a);
Why it results in an infinite loop? Please explain.
(1)
Nagabhushan said:
7 years ago
int k=1;
while (k<n)
{
k=3k;
}
How many times the loop repeats?
Please tell me the answer.
while (k<n)
{
k=3k;
}
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:
8 years ago
Thank you all for your suggestions.
Tara said:
8 years ago
The loop will execute for infinity times, like 0 to 128.
Then -128 to -1 again from 0-128, the loop repeats.
Then -128 to -1 again from 0-128, the loop repeats.
Vibhan said:
8 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:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers