C++ Expressions
C++ expressions are program statements that combine the C++ operators to perform some action. Below are several examples of valid C++ expressions (note: the examples assume the variables appearing in the expressions have been previously declared, if they were not, the compiler would complain of undeclared variables):
- x = 4 + 5; // assign the sum of 4 and 5 to the variable x
- x++; // increment x to the next value, e.g, if x was 9 before this statement, then x will be 10 after it
- x = y + z; // assign to x the sum of y and z, e.g., if x=2, y=3, and z=4 before, then x=7, y=3 and z=4 after
- x += y + z; // add to x the sum of y and z, e.g., if x=2, y=3, and z=4 before, then x=9, y=3 and z=4 after
- x < y; // this is a boolean expression, because the result is a true or false value, rather than a number
- x < y && y >= z; // this boolean expression asks, "is x less than y AND y larger then or equal to z?"