+ 5
How do you do (cout << 3>5?5>4?40:20:30;)
what does the question mark and colon mean in this code
2 Réponses
+ 46
C and C-like languages has a special ternary operator (?:) for conditional expressions with a function that may be described by a template like this:
condition ? evaluated-when-true : evaluated-when-false
+ 4
to make it easier to read, you can write as the code like that
if(3>5){
if(5>4) cout <<40;
else cout << 20;
}
else cout<<30;
hope this can help you