0
How is the output calculated for this code?
int a = 10, b = 20; int c= b/a? a:b; printf("%d", c); //Please help that how it is calculated//
2 ответов
+ 10
It's ternary operator.
Question? answer1:answer2
So, your code should be like this
int c = b/a? a:b;
For a true question, it evaluates answer1 and returns its value; otherwise, it evaluates answer2 and returns its value.
Here, 20/10 is 2.
So, it's a true statement because any number evaluates true except zero.
That's why output is 10 which is a.
+ 1
Syntax error
Run it in code Playground and find out yourself