C Programming - Control Instructions - Discussion

Discussion Forum : Control Instructions - Point Out Correct Statements (Q.No. 8)
8.
Which of the following statements are correct about the below program?
#include<stdio.h>
int main()
{
    int n = 0, y = 1;
    y == 1 ? n=0 : n=1;
    if(n)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}
Error: Declaration terminated incorrectly
Error: Syntax error
Error: Lvalue required
None of above
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
22 comments Page 3 of 3.

Praween kumar said:   7 years ago
y==1?n=0:n=1; <=> (y==1?n=0:n)=1;

Here, within parenthesis is an expression so, we can't assign value in an expression.
(1)

Rajesh katta said:   6 years ago
Here the ternary operator is used so that it will need the left-hand side value like in the form of ternary syntax.


Post your comments here:

Your comments will be displayed after verification.