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 3 of 7.
Saikumar said:
1 decade ago
Because that x=10 y=1 the valve is printed is true and.
The condition if(x!=y) will not produce any error it is correct.
So 2, 3 options are correct for this above question.
The condition if(x!=y) will not produce any error it is correct.
So 2, 3 options are correct for this above question.
Srinath said:
1 decade ago
I don't now after if condition put semicolon in C you clearly explain thank you kavya.
Nadeem Khan said:
1 decade ago
Can anybody tell me 100%90 will give remainder or quotient.
Because in my opinion %--> sign is used for getting remainder (Modular sign).
& /--> slash sign is used for dividing.
Because in my opinion %--> sign is used for getting remainder (Modular sign).
& /--> slash sign is used for dividing.
Bala said:
1 decade ago
Initially the value of x=10 and y=100%90 is provided, The condition if(x!=y) then x=10, y=10 then condition is true. So always print the output.
Angelica said:
1 decade ago
Will it run even if the for loop has no opening and closing curly brace?
Madhu said:
1 decade ago
How can it generate option B. First of all there is an error occurred since there is ";" after 'if'.
Can you justify your answer?
Can you justify your answer?
Deepanshu said:
1 decade ago
If statement cannot be terminated by semi-colon.
Hare.. said:
1 decade ago
@Deepanshu and @Kavi.
"if (x != y) ;" it will exits and doesn't show you the error in turbo-C compiler.
It is Close with semicolon means that ';' immediately terminates if statement then that if statement immediate braces or block are treated as anonymous block.
"if (x != y) ;" it will exits and doesn't show you the error in turbo-C compiler.
It is Close with semicolon means that ';' immediately terminates if statement then that if statement immediate braces or block are treated as anonymous block.
Hare.. said:
1 decade ago
@Angelica.
Here we are using only one for loop, so it isn't necessary to write curly braces. But in case if we use more than one for loop then curly braces are must.
Here we are using only one for loop, so it isn't necessary to write curly braces. But in case if we use more than one for loop then curly braces are must.
Sujan said:
1 decade ago
But the condition says that i<10 rite? So how can we get x and y as 10?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers