This is too basic I think, but how do both of these work?
return true; // 1
and
return (true); // 2
Similar: sizeof
, exit
My guess:
If return was a function,
1
would be erroneous.So, return should be a
unary operator
that can also take in brackets... pretty much likeunary minus
:-5
and-(5)
, both are okay.
Is that what it is - a unary operator?
It means the same thing there that it means anywhere else. It is the logical or operator. It is not so much "in a return", as much as you evaluate that expression and then return the result of it. It means the return statement returns either 0 or 1 .
An operator function is a user-defined function, such as plus() or equal(), that has a corresponding operator symbol. For an operator function to operate on the opaque data type, you must overload the routine for the opaque data type.
Here are some differences between an operator and a function: An operator does not push its parameters onto the stack, but a function pushes its parameters onto the stack. The compiler knows about the operation of the operators, but is not aware of the output of the function.
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.
return
is a keyword that manipulates control flow. In that it's similar to if
, for
etc. It can be used with or without an expression (return;
returns from a void
function). Of course, as with all expressions, extra parentheses are allowed. (So return (42);
is similar to int i = (4*10+2);
, in both cases the parentheses are redundant, but allowed.)
sizeof
is a keyword that is an operator, similar to new
, delete
, +
, ->
, ::
, etc.
std::exit()
is an identifier that denotes a function of the C standard library (which never returns to the caller).
return
is just a language/control flow construct. It's certainly not a function, since it's syntactically irreducible, and it's not really an operator either, since it has no return value.
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