Conditonal Operator | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
13th Jan 2018, 3:51 PM
I'm_Groot
I'm_Groot - avatar
5 Antworten
+ 2
This behavior is caused by operator precedence rules in C++. conditional operator has higher precedence than , (comma) operator. so the whole conditional statement is interpreted as two statements and not one. Since the condition is true, "hi" is printed twice. The last print "bye" is separated out and will always be executed irrespective of the condition. check my code to understand how the statement is evaluated
13th Jan 2018, 4:15 PM
Ravi Chandra Enaganti
Ravi Chandra Enaganti - avatar
+ 4
It's because of operator precedence . check your updated code .. https://code.sololearn.com/c2VQ5sIhE2cq/?ref=app
13th Jan 2018, 5:24 PM
Somasundaram R
Somasundaram R - avatar
+ 2
https://code.sololearn.com/cfm5vjaguOi1/?ref=app
13th Jan 2018, 4:18 PM
Ravi Chandra Enaganti
Ravi Chandra Enaganti - avatar
+ 1
I put the two outputs (with by) after the colon into parentheses ( ) and it worked
13th Jan 2018, 4:10 PM
michal
+ 1
conditional operator are also known as ternary operator. It acts upon 3 opprents and is represented by ? = Question mark : = Colon ; = Semi-colon In conditional operator if condition evaluates true then it will execute the expression after question mark otherwise, it will execute after colon.
4th Feb 2018, 2:54 PM
Shivam Saurabh
Shivam Saurabh - avatar