If I do something like return a ? b : c;
or return a && a2 && a3;
Could it ever be evaluated as just return a
and then the function just returns immediately before evaluating the rest?
Operator precedence determines which operation is performed first in an expression with more than one operators with different precedence. Operators Associativity is used when two operators of same precedence appear in an expression. Associativity can be either Left to Right or Right to Left.
A return statement ends the execution of a function, and returns control to the calling function. Execution resumes in the calling function at the point immediately following the call. A return statement can return a value to the calling function.
Java has two operators for performing logical And operations: & and &&. Both combine two Boolean expressions and return true only if both expressions are true.
The precedence of operators in C dictates the order in which the operators will be evolved in an expression. Associativity, on the other hand, defines the order in which the operators of the same precedence will be evaluated in an expression. Also, associativity can occur from either right to left or left to right.
return
is a statement, not an expression. So it can never be misinterpreted the way you think.
The statement is always of the form return [some expression];
(and the expression is optional). The expression, if present, is evaluated first, and its value is bound to the return value of the function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With