A C++ expression is a value or combination of values and operators, and EVERY C++ expression has a value!
x < 3 and has value true or 1 if x < 3
x = 8; value of the expression is resulting in the value 8 which in boolean logic is true. this expression statement has a SIDE EFFECT, it assigns 8 to x.
++x + 15, has also as side effect that x is incremented.
From expression to statement is a short step; you just add the semicolon.
age = 100
is an expression, whereas
age = 100;
is a statement. Any expression becomes a statement if you add a semicolon, but the result might not make programming sense. For example:
rodents + 6; // valid, but useless statement
The program just add six to the variable rodents, but that is it, it does not store the result in rodents.
A smart compiler might even skip the statement!
Abonneren op:
Reacties posten (Atom)
Geen opmerkingen:
Een reactie posten