O'Reilly logo

SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Performing and Displaying a Calculation

Now you are ready to move ahead and enhance the example you worked with in the last lesson. This time, you are replacing a line, not adding one. Have a look at Listing 3.1.

Listing 3.1. The Example Performs a Calculation
 1: #include <iostream>
 2:
 3: using namespace std;
 4:
 5: int main(int argc, char* argv[])
 6: {
*7:    // Should print the number 6
*8:    cout << ((6/2)+3) << endl;
 9:    return 0;
10: }

This program displays the value 6, which is the result of calculating ((6/2)+3).

Expressions

((6/2)+3) is an example of an expression. In this case, the expression uses literal numbers, operators (/ and +), and ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required