How do you do (cout << 3>5?5>4?40:20:30;) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

How do you do (cout << 3>5?5>4?40:20:30;)

what does the question mark and colon mean in this code

11th Aug 2017, 1:01 AM
HJ🐓TDM
2 Answers
+ 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
11th Aug 2017, 1:12 AM
Adi Pratama
Adi Pratama - avatar
+ 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
11th Aug 2017, 2:58 AM
懵懂蔡
懵懂蔡 - avatar