#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;
}
Asked
Active
Viewed 45 times
-2

Dmitry Bychenko
- 180,369
- 20
- 160
- 215

Sanjoy Halder
- 1
- 1
-
1`n = y == 1 ? 0 : 1;` ? – Dmitry Bychenko Oct 13 '17 at 14:50
-
n = ( y == 1 ) ? 0 : 1; for readability. – Burstful Oct 13 '17 at 14:53
-
2`n = y != 1`? ;-) – alk Oct 13 '17 at 14:56
1 Answers
0
The ?: operator doesn't quite work like that. What you want to do is something like:
n = ((y == 1) ? 0 : 1);
In the more general case, if you want to perform actions based on a condition, use an if
. The ?: operator is more for returning values based on the condition.

Steve
- 1,747
- 10
- 18