C Programming - Control Instructions - Discussion

Discussion Forum : Control Instructions - Point Out Correct Statements (Q.No. 1)
1.
Which of the following statements are correct about the below program?
#include<stdio.h>
int main()
{
    int i = 10, j = 20;
    if(i = 5) && if(j = 10)
        printf("Have a nice day");
    return 0;
}
Output: Have a nice day
No output
Error: Expression syntax
Error: Undeclared identifier if
Answer: Option
Explanation:

"Expression syntax" error occur in this line if(i = 5) && if(j = 10).

It should be like if((i == 5) && (j == 10)).

Discussion:
12 comments Page 2 of 2.

Saggs said:   7 years ago
The original question gives output:

main.c: In function 'main':
main.c:5:18: error: expected identifier before 'if',
if(i = 5) && if(j = 10).

Saggs said:   7 years ago
@Juhi.

You must assign value calculated from if(i == 10) && if(j == 20) expression to some variable or put it in another if like if(if(i == 10) && if(j == 20)){/* code goes here*/}.


Post your comments here:

Your comments will be displayed after verification.