In this program what I am adding a number to the z based on some criteria where if x == 10 add 20 else 30. I tried with ternary operator but the it is giving me wrong answer after removal of extra brackets
Code 1 - Using ternary operator with extra brackets ###
int x=10;
int z = 10 + ((x == 10)? 20: 30); // used brackets here
std::cout << z << std::endl; // output = 30, it is correct
Code 2 - Using ternary operator without extra brackets (Wrong result) ###
int x=10;
int z = 10 + (x == 10)? 20: 30; // not used brackets here
std::cout << z << std::endl; //output = 20; expected is 30