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.

Nancy said:   1 decade ago
Can two if expressions be combined in the format given above?

Abhishek rai said:   1 decade ago
@ Karthi........ Output: Have a nice day


Post your comments here:

Your comments will be displayed after verification.