C Programming - Control Instructions - Discussion
Discussion Forum : Control Instructions - Find Output of Program (Q.No. 13)
13.
What will be the output of the program?
#include<stdio.h>
int main()
{
int x=1, y=1;
for(; y; printf("%d %d\n", x, y))
{
y = x++ <= 5;
}
printf("\n");
return 0;
}
Discussion:
46 comments Page 3 of 5.
Lakshmi said:
1 decade ago
Thanks to panchan Raut
Renuka said:
1 decade ago
Can anyone please explain what is "for(; y; printf("%d %d\n", x, y))" ?
Sonam said:
1 decade ago
Why is the value of x not assigned in y?
coz, y=x++<=5.......????
what should have been the syntax to assign the value of x to y??
coz, y=x++<=5.......????
what should have been the syntax to assign the value of x to y??
Teja said:
1 decade ago
@pavani.
Incremented x value must be <=5 and we are using post increment. So before executing inc/dec in for loop body will be executed first.
Incremented x value must be <=5 and we are using post increment. So before executing inc/dec in for loop body will be executed first.
Ggf said:
1 decade ago
@yash.
You are wrong as per for loop rule first initialize then condition check then move over increment.
You are wrong as per for loop rule first initialize then condition check then move over increment.
Shankra said:
1 decade ago
Thanks panchanana raut.
Pavani said:
1 decade ago
Incremented x value must be less than 5. How could it become 6 and x?
Ranjana said:
1 decade ago
Because x got post incremented at each step.
Yash said:
1 decade ago
At first when x=1 and y=1 then the for loop condition is true then why there is no 1 1 in the output. I think in the result there is also 1 1 there.
I think the result will be :
1 1
2 1
3 1
4 1
5 1
6 1
7 0
Why the result is not like that? Please explain.
I think the result will be :
1 1
2 1
3 1
4 1
5 1
6 1
7 0
Why the result is not like that? Please explain.
Mohit singhal said:
1 decade ago
We can increase the value of x until the condition of y not become false.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers