Expressions
Any statement that returns a value is an expression in C++. |
There it is, plain and simple. If it returns a value, it is an expression. All expressions are statements.
The myriad pieces of code that qualify as an expression might surprise you. Here are three examples:
3.2 // returns the value 3.2 PI // float const that returns the value 3.14 SecondsPerMinute // int const that returns 60
Assuming that PI is a const equal to 3.14 and SecondsPerMinute is a constant equal to 60, all three of these statements are expressions.
The complicated expression
x = a + b;
not only adds a and b and assigns the result to x, but yields the value ...
Get Sams Teach Yourself C++ in 24 Hours, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.