Jump to content

C++ Language/Overview

From Wikibooks, open books for an open world

Like many programming languages, C++ uses a "variable" to name a memory location which can store some value. A running C++ program executes an assignment statement iX=1; to assign value 1 into variable iX. But first, each variable has a "type" (its way of using its memory bits to represent its values, such as int) which must be specified by the programmer "defining" that variable within some "scope".

Assignment is only one example of a statement; a sequence of statements can be grouped into a code block (written within braces). The execution of that code block can be conditional, depending on the result of testing a "relational expression" (e.g., the equality of two sub-expressions in if (iX + iY == 33) {block}). Generally, a program's execution linearly flows from first statement to last statement, but that program flow can jump around as controlled by loops or by "calling a function". Information can be "passed" into the function (via its "parameters"), and/or returned from the function (by a return 123; statement).

C++ enables object-oriented programming (OOP), where an "object" is an instance of a type whose data is a combination of "data members" (as had already been listed in some "class" definition). That class definition also describes "member functions", whose usage is designed to manipulate a specific instance of those data members (i.e., to manipulate a specific object).