C Programming - Control Instructions - Discussion
Discussion Forum : Control Instructions - Point Out Correct Statements (Q.No. 6)
6.
Which of the following statements are correct about the below C-program?
#include<stdio.h>
int main()
{
int x = 10, y = 100%90, i;
for(i=1; i<10; i++)
if(x != y);
printf("x = %d y = %d\n", x, y);
return 0;
}
1 : | The printf() function is called 10 times. |
2 : | The program will produce the output x = 10 y = 10 |
3 : | The ; after the if(x!=y) will NOT produce an error. |
4 : | The program will not produce output. |
Discussion:
70 comments Page 5 of 7.
Syed said:
1 decade ago
Nice explanation given by Kavya
Thanks....
Thanks....
Munni said:
1 decade ago
Nice explanation kavya.
Nitika said:
1 decade ago
Hmmm. Right kavya.
Karthik said:
1 decade ago
Good explanation kavya.
Siva said:
1 decade ago
Good explanation Kavya.
Imran said:
1 decade ago
X=10, y=10 , then how if(x != y) statement will execute ?
Vini said:
1 decade ago
I have a doubt. Because the if inside the for loop is not satisfying. So how could it be. ?
DAJ said:
1 decade ago
Very good kavya.
Sri said:
1 decade ago
Thanks Kavya. Very good explanation.
Kiran said:
1 decade ago
Step1: x and y are intialized to 10 and 10 repectively. 100%90 does not affect on variable Y.
step2: the for loop condition is true and it repeats upto i<10.
Step3: if condition is statisfied in for loop statement block, It will executes without any output upto the condition in for loop is fails.
step4: printf statement is executes independently which is x =10 and y = 10. which is doesn't affect on for loop.
The option 2 and 3 are correct.
step2: the for loop condition is true and it repeats upto i<10.
Step3: if condition is statisfied in for loop statement block, It will executes without any output upto the condition in for loop is fails.
step4: printf statement is executes independently which is x =10 and y = 10. which is doesn't affect on for loop.
The option 2 and 3 are correct.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers