return statement in ternary operator c++
Solution 1:
The second and third arguments to the ternary operator are expressions, not statements.
return a
is a statement
Solution 2:
Your syntax is incorrect. It should be
if (a >=0)
return a;
else
return -a;
or the way you wanted it:
return a >=0 ? a : -a;
Solution 3:
What's the difference between the two?
One is correct syntax, the other is not.