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.
Karthi said:
1 decade ago
Initial value of j is 1 and the last condition of the while statement is j=225. so the loop get executed 225 times. It does not change according to declaration.
Vivek kkumar said:
1 decade ago
I could not understand.
Nayana said:
1 decade ago
Hi vivek in the program the initital value of j=1 the statement in the while condition will execute until j value will become 255. so the statement will execute 255 times
Ravitheja said:
1 decade ago
Thnks to all. Karthi please chek your values in this discussion.
Rachit said:
1 decade ago
Loop will execute from j=0 to 224 at j=225 loop will terminated so it will execute upto 225 times from 0 to 224.
I think it makes it more clear.
I think it makes it more clear.
Fanta said:
1 decade ago
The body of the while loop will execute 255 times. But the while condition will execte one more time to became condition false.
It takes 256.
It takes 256.
Dhronan said:
1 decade ago
@fanta
you are right but see they didn't say while statement, they said while loop, so you ought consider the whole loop statements.
you are right but see they didn't say while statement, they said while loop, so you ought consider the whole loop statements.
Jaya said:
1 decade ago
In printf, why there are using %c. I can't understand please explain..
Asha said:
1 decade ago
I can't understand using of %c please explain.
Swathi said:
1 decade ago
%c %d means short integer, according to this concept it won't affect while.
Hence while loop get executed by 255 times...understand.
Hence while loop get executed by 255 times...understand.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers