C Programming - Control Instructions - Discussion
Discussion Forum : Control Instructions - Find Output of Program (Q.No. 19)
19.
What will be the output of the program?
#include<stdio.h>
int main()
{
char j=1;
while(j < 5)
{
printf("%d, ", j);
j = j+1;
}
printf("\n");
return 0;
}
Discussion:
24 comments Page 3 of 3.
Pratik Gupta said:
1 decade ago
thanks @padhu
Padhu said:
2 decades ago
In C char types are treated as int by the compiler. Hence they can be used in place of int (<255 for unsigned). This is the reason why char can be used inside switch statement.
Meera said:
2 decades ago
j is a declared as a char data type.Then how the while loop executes?and how we are assigning that int value to char type?
Ashok said:
2 decades ago
while(1<5) it is true enters the loop
prints j values as 1
j value is incremented by 1 i.e now j value is 2
while(2<5) it is true enters the loop
prints j values as 2
j value is incremented by 1 i.e now j value is 3
while(3<5) it is true enters the loop
prints j values as 3
j value is incremented by 1 i.e now j value is 4
while(4<5) it is true enters the loop
prints j values as 4
j value is incremented by 1 i.e now j value is 5
while(5<5) it is false exits from loop
prints j values as 1
j value is incremented by 1 i.e now j value is 2
while(2<5) it is true enters the loop
prints j values as 2
j value is incremented by 1 i.e now j value is 3
while(3<5) it is true enters the loop
prints j values as 3
j value is incremented by 1 i.e now j value is 4
while(4<5) it is true enters the loop
prints j values as 4
j value is incremented by 1 i.e now j value is 5
while(5<5) it is false exits from loop
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers