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.
Shankra said:
1 decade ago
Thanks panchanana raut.
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.
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.
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??
Renuka said:
1 decade ago
Can anyone please explain what is "for(; y; printf("%d %d\n", x, y))" ?
Lakshmi said:
1 decade ago
Thanks to panchan Raut
Sai said:
1 decade ago
Thank you Kiran.
6 < = 5 is false, then why = 0, and x increments to 1 i.e., x = 7,
In this you are saying that when it false it will take y=0 but already the why is initialized with 1 how it will take ?
6 < = 5 is false, then why = 0, and x increments to 1 i.e., x = 7,
In this you are saying that when it false it will take y=0 but already the why is initialized with 1 how it will take ?
Piyush jain said:
1 decade ago
The For statement is something like this
For(i=0 ; i<10 : printf("\n"))
{
....
}
Which is Equivalent to
i=0;
while(1)
{
if(i<10)
{
blah blah blah
}
Else break;
printf("\n");
}
For(i=0 ; i<10 : printf("\n"))
{
....
}
Which is Equivalent to
i=0;
while(1)
{
if(i<10)
{
blah blah blah
}
Else break;
printf("\n");
}
Manju said:
1 decade ago
y=x++<=5; is the statement, when x evaluates to b 2 why x value is not assigned to y ? why y is still 1?
Gauravkumar said:
1 decade ago
@Yash.
Execution of loop takes this form.
Step 1 : Initialization.
Step 2 : Condition checking.
Step 3 : Execute body of loop.
Step 4 : Increment.
Execution of loop takes this form.
Step 1 : Initialization.
Step 2 : Condition checking.
Step 3 : Execute body of loop.
Step 4 : Increment.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers