More About C++ Statements
A C++ program is a collection of functions, and each function is a collection of statements. C++ has several kinds of statements, so let's look at some of the possibilities. Listing 2.2 provides two new kinds of statements. First, a declaration statement creates a variable. Second, an assignment statement provides a value for that variable. Also, the program shows a new capability for cout.
Listing 2.2. fleas.cpp
// fleas.cpp -- display the value of a variable #include <iostream> using namespace std; int main() { int fleas; // create an integer variable fleas = 38; // give a value to the variable cout << "My cat has "; cout << fleas; // display the value of fleas cout << " fleas.\n"; return 0; } |
A blank line separates ...
Get C++ Primer Plus, Fourth 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.