List
C++ Basics
Variables Part I
Operators
Variables Part II
Control Flow
Arrays, Strings, Pointers, and References
Functions
Basic object-oriented programming
Operator overloading
Composition
Inheritance
Virtual Functions
Input and output (I/O)
Templates
Exceptions
The Standard Template Library
std::string
1.1 — Structure of a program
A computer program is a sequence of instructions that tell the computer what to do .
Statements and expressions
The most common type of instruction in a program is the statement. A statement in C++ is the smallest independent unit in the language. In human language, it is analogous to a sentence. We write sentences in order to convey an idea. In C++, we write statements in order to convey to the compiler that we want to perform a task. Statements in C++ are terminated by a semicolon .
There are many different kinds of statements in C++. The following are some of the most common types of simple statements:
int x is a declaration statement. It tells the compiler that x is a variable. All variables in a program must be declared before they are used. We will talk more about variables shortly. x = 5 is an assignment statement. It assigns a value (5) to a variable (x). cout << x; is an output statement. It outputs the value of x (which we set to 5 in the previous statement) to the screen.