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.
Angelica said:
1 decade ago
Will it run even if the for loop has no opening and closing curly brace?
Kavi said:
1 decade ago
If condition does not contain semicolon (;). How its not producing error? any one please explain it.
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.
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.
Srinath said:
1 decade ago
I don't now after if condition put semicolon in C you clearly explain thank you kavya.
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.
KAPIL DEOL said:
1 decade ago
Because for will execute only 1 statement that's why it will execute only if but 'if' is terminated by ;.
Then it will print 10 10.
Then it will print 10 10.
Amit said:
1 decade ago
B is true.
As in the above Code,
Till the For statement, the flow is normal & variable values are(x=10, y=100%90=10)
So after the For loop The if Condition is Checked i.e.
if(x!=y)i.e (10!=10)
Which proves to be false , it puts us in dilemma that what will be the output.
But thanks to the ; So that if loop gets terminated here only.
And Controls moves to the next line & values of X & Y gets printed i.e 10 & 10.
As in the above Code,
Till the For statement, the flow is normal & variable values are(x=10, y=100%90=10)
So after the For loop The if Condition is Checked i.e.
if(x!=y)i.e (10!=10)
Which proves to be false , it puts us in dilemma that what will be the output.
But thanks to the ; So that if loop gets terminated here only.
And Controls moves to the next line & values of X & Y gets printed i.e 10 & 10.
Mohan said:
1 decade ago
@Rajsri.
As per your point it looks good, but the spaces given below the loop and starts with Printf() statement doesn't mean that it included the for statement it's just an indentation we are following for avoiding the confusion.. Since ; (semicolon)which is at the end of IF statement which will not generate the error but it keeps looping until the statement becomes false,once it becomes false it comes to the next line and continues its processing.
As per your point it looks good, but the spaces given below the loop and starts with Printf() statement doesn't mean that it included the for statement it's just an indentation we are following for avoiding the confusion.. Since ; (semicolon)which is at the end of IF statement which will not generate the error but it keeps looping until the statement becomes false,once it becomes false it comes to the next line and continues its processing.
Rajsri said:
1 decade ago
The printf() statement is under for loop or if condition?
If it is under for loop, the explanation is correct but as per the spaces given in the code, it looks so that it is under the if() , if it is under the if condition as ; terminates the if, the compiler must never go to the printf().
Am I missing something? Someone please explain?
If it is under for loop, the explanation is correct but as per the spaces given in the code, it looks so that it is under the if() , if it is under the if condition as ; terminates the if, the compiler must never go to the printf().
Am I missing something? Someone please explain?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers