f(-1);
int f(int a) {
return (a%2) ? (a%2) : (a*2);
}
Consider the above function f()
, a%2
is returned if a%2
is evaluated to non-zero.
QUESTION : Are there any advance operator or expression that can merge the condition and return value and form something like
return (a%2) OR (a*2) // underlying logic is return (a%2) ? (a%2) : (a*2);
I understand that I have provided one possible solution return (a%2) ? (a%2) : (a*2);
already but I want to explorer more on C++ so I ask this question. This question is simply a Yes/No question. I am expecting answers other then using if-else statement
My thought :
a%2
in a condition is evaluated and converted to type bool
so it is no way to cast back to corresponding int
value.