Reputation: 19
Suppose, I want to do this using ternary operator:
if(i=='r') r=true;
else if(i=='b') b=true;
else if(i=='g') g=true;
Here, r,b,c are bool type variable declared:
bool r=false,g=false,b=false;
I want to replace if and else statements using ternary operator. How can I do this? I have tried in this way:
(i=='r'?r=true : i=='g'? g=true:i=='b'? b=true:false);
Is it okay? How is this statement compiled?
Upvotes: 0
Views: 161