The list of terms below is provided to supplement or elaborate on the terms and definitions provided in the course textbook. Students are advised to also review the textbook to develop a fuller understanding of these and other important terms related to each chapter. The terms below are ordered based on their logical position in the learning process while studying programming rather than in alphabetical order. As such, the list can be read as a whole to help review the concepts introduced in the related chapters. Note that many of the terms also contain links to other terminology in this glossary or other locations. Readers can find any term on this page quickly by using their browser's Find on this page feature (activated by the keystoke combination Ctrl+F in most broswers).
' (a blank space). Storage locations for character data are declared using the keyword char.5-2), it is referred to as a "binary operator".
When the symbol appears preceding only one item (such as the value 2 in the formula -2), it is referred to as a "unary operator".00000101, and the numeral (symbol) '5' is "coded" as 00110101..cpp"..obj". Such files cannot be loaded into memory and run until a linker/loader program prepares them for that event by linking them together with any other necessary object code files.;) rather than a period. C++ source code is simply a set of statements. Similar to a sentence in English, a statement can extend over more than one line of type and is terminated only by the proper punctuation (a semicolon).#include" compiler directive. Header files typically end with a filename extension of ".h". ), form feeds (\f), new-lines (\n), raw carriage returns (\r), horizontal tabs (\t), and vertical tabs (\v). In C++ source code, all of these characters are interpreted as the same unless they are quoted. In other words, one space is interpreted the same as three blank lines.return cannot be declared a programmer as an identifier. (See also the related, but different terms "keyword" and "standard identifier" that follow.)cout that are so useful that they have been included as library functions within most compiler programs.&) as in &X which refers to the address of storage location X as opposed to its contents.=) in an expression. Note that the = symbol is not used in the C++ language to test for equality. That is accomplished with the == relational operator.int N=2;#include <iostream>{ }.const ahead of the data type in a declaration statement.#define" directive at the top of the source code (to allow easy location and revision later.) Note that directives are not terminated with a semicolon.float (for typical numbers) and double (for numbers such as 1.2345678901234E+205 that involve extreme precision or magnitude).#include <string>The reserved word string (all lowercase) is used in C++ to declare data as string class. A string object named TITLE could be defined using the statement:
string TITLE;
bool below.) Early versions of C++ (and many other languages) represented the true and false values using the integer values 1 for true and 0 for false. Modern C++ recognizes the words true and false as Boolean values. C++ and many other languages will treat 0 as false and any non-zero integer value as true.His name is "Joe".cout << "His name is \"Joe\".";|"), underscore ("_"), or small filled box (" ") that is displayed on a computer screen (sometimes blinking) to indicate where the next output action will take place.\n inside of double quotes. For example, to output the word "Hello" followed by a carriage return on the screen, usecout << "Hello\n"; ). Note that compiler directives are not considered to be C++ source code and so they are not terminated with a semicolon.<< can be used in C++ as a stream insertion operator to send streams of data (typically characters) to the cout object. (See also the >> stream extraction operator discussed in Chapter 3.)cout is a stream object (see above) used in C++ to display output on a console. It is used in combination with the << stream insertion operator as in the statement below:cout << "The amount to pay is:" << PAYMENT << endl;
X = -5; the minus sign acts as a unary operator and operates on a single operand (the literal 5). X = A/B; the slash acts as a binary operator and operates on a pair of operands (the variables A and B).+ (addition), - (negation or subtraction), * (multiplication), / (division), and % (modulus, a.k.a. remainder).>> can be used in C++ as a stream extraction operator to extract streams of data (typically characters) from the cin stream object. (See also the << stream insertion operator discussed in Chapter 2.)cin is a stream object used in C++ to store input from a keyboard into a variable and then advance the cursor to the next line when the user presses the Enter key. It is used in combination with the >> stream extraction operator as in the second statement below:cout << "What is the price? "; cin >> PRICE;
get member function of the cin object (see above) is accessed as:
cin.get() (also note the use of parentheses to denote get as a function).cin.get is a "member function" (see above) of the cin stream object used in C++ to store single character input from a keyboard into a character variable. It is useful in reading whitespace characters that can be misinterpreted by the cin object as delimiters separating multiple items of input. For information about techniques for inputting literal whitespace characters, read the web page entitled Console Input of Character Data in C++.cin.ignore is a member function of the cin stream object used in C++ to skip single or multiple characters of input in the keyboard input buffer to avoid having them processed. It is useful in avoiding whitespace characters that can be misinterpreted by the cin object as delimiters separating multiple items of input.getline is a function used in C++ to store keyboard input containing whitespace characters into a single string variable rather than treating the whitespaces as delimiters between separate strings. It typically is used in combination with the cin stream object and requires the inclusion of the following compiler directive to be used in a program::#include <string>
X+3. A+B/C as A+(B/C) as opposed to (A+B)/C . The division operation will preceed the addition because division has a higher order of precedence. For more information on expressions and order of precedence, see the web page entitled Expressions & Operators in C++. A*B/C as (A*B)/C as opposed to A*(B/C) because the associativity of multiplication and division (both of the same precedence) is "left" (meaning performed from left to right). The multiplication operation will be done first because it is left of the division operation. On the other hand, C++ compilers evaluate the expression X=Y=2 as X=(Y=2) as opposed to (X=Y)=2 because the associativity of the assignment operation is "right" (meaning performed from right to left). The assignment of 2 to Y will be done first because it is right of the assignment of X. pow (4.0, 2.0) , with 2.0 as the exponent.C = static_cast<float>(A) / B; C = A / static_cast<float>(B);Trying to type cast the result instead of the operands would be pointless because the truncation would have already taken place. So it would be ineffective to try:
C = static_cast<float>(A / B);For more information about type casting, read the [Type Casting page at CPlusPlus.com].
+= (increase by), -= (decreased by), *= (multiplied by), /= (divided by), and %= (replaced by remainder). For example, the expression N+=2 means the same as N=N+2.cout and a collection of optional stream manipulators as described in section 3.7 of your textbook.cout stream object to specify that a line of output should end. It peforms the same action as inserting the special escape sequence \n into a string being output. For example, the statement:cout << "My Program" << endl;and the statement:
cout << "My Program\n";will both display the words "My Program" one a single line and then carriage return to the next line.
cout stream object to specify the desired minimum width of an output field for the next item in the output stream. If the output item is larger than the width specified, the setw manipulator is overriden and the entire item is displayed. If the output item is smaller than the width specified, the setw manipulator will align item to the right side of the output field (padding the unused positions with blank spaces) unless overriden by the use of the left (alignment) stream manipulator. For example, the statement:cout << setw(8) << 123.45 << endl;will display the value 123.45 in a width of 8 characters with (2 spaces padded in front of the digit 1).
cout statements, output precision is controlled by using the setprecision() (see below) stream manipulator ahead of the value to be displayed in the output stream. When the setprecision() manipulator is used in combination with the fixed() manipulator, it controls only the quantity of digits that appear after the decimal point.cout stream object to contol output precision. For example, the statement:cout << setprecision(4) << 246.7912 << endl;will display the value 246.8 (rounded at the 4th digit position). When used with the
setw() manipulator, a low value specified for the setprecision() manipulator can cause the computer to use scientific notation in the output of the value. When used with the fixed manipulator, the setprecision() manipulator changes to specify the number of digits to the right of the decimal point, rather than the total on both sides of it. The effects of the setprecision() manipulator are persistent, affecting all items in the output stream following its use.cout stream object to output digits in "fixed point" (referred to by some as "decimal") notation. For example, the statement:cout << setprecision(2) << fixed << 123.9182 << endl;will display the value 123.92 (rounded at the 2nd digit position right of the decimal point). The effects of the
fixed manipulator are persistent, affecting all items in the output stream following its use.cout stream object to horizontally align all following output to the left side of the output field by padding the unused positions with blank spaces. Note that the default horizontal alignment for the C++ cout stream object is "right", regardless of data type.cout stream object to horizontally align all following output to the right side of the output field by padding the unused positions with blank spaces. Note that the default horizontal alignment for the C++ cout stream object is "right", regardless of data type.cout stream object to pad numeric output with trailing zeros until all digits specified by the setprecision() manipulator have been output (even for numbers with fewer digits than specified). For example, the statement:cout << setprecision(6) << showpoint << 123.4 << endl;will display the value 123.400 (padding the last 2 digit positions of the 6 specified with spaces). The effects of the
showpoint manipulator are persistent, affecting all items in the output stream following its use.{ and }.true or false, or they can be the result of relational expressions or logical expresssions.X==A+B) involving relational operators that compare items of data (possibly including literals, variables or arithmetic expressions) and produce a Boolean (true or false) result.&& for "and", || for "or" and ! for "not" are those used to combine conditions into logical expressions such as (X==0 && Y>10) to produce a single Boolean (true or false) result.if and else statements. For example, given an integer variable named I and a string object named MSG, a selection structure that would normally be coded asif (I<0) MSG="Negative"; else MSG="Non-negative";could be written in a single compact statement as
I<0 ? MSG="Negative" : MSG="Non-negative";
char data, but not floating point or string data. For more information see the Ordinal Data page.if (I<0) cout << "Negative";Note that
if statements can be paired with else statements (see below) to implement selection structures with two legs, or they can be nested to implement selection structures with more than two legs.else statement can be used only in conjustion with a preceding if statement and does not repeat the conditional test from that statement. For example, to code an algorithm step that reads "if variable I is less than zero, then display the word 'Negative', otherwise display 'Non-negative'", the pair of C++ statements would be: if (I<0) cout << "Negative";
else cout << "Non-negative";
while (condition)
{block-of-statements-to-perform;} do {block-of-statements-to-perform;}
while (condition);break and continue as described in section 5.12 of your textbook. But these should be used only with great care.T = T + N; where the variable T "accumulates" the value in variable N. The value in N is added to the value in T and the result is stored back in T replacing its original values.++ and -- used either preceeding or trailing a counter. In the expression Y=++X the value of X is increased by one and then the new value of X is assigned to Y. In the expression Y=X++ the original value of X is assigned to Y and then the value of X is increased by one. Increment and decrement operators can be used only on ordinal data such as integers or characters.fstream using the preprocessing directive:#include <fstream>;That file contains code that allows programmers to define file stream objects that can be manipulated to access data files using one of three data types:
ifstream inputFile;
inputFile.open("mydata.txt");
Input data could then be read from the file using its file stream object in a manner similar to the use of the cin stream object (introduced in Chapter 3). The statement below would read a value using its file stream object "inputFile" into an integer variable named N:inputFile >> N;The following source code would open a data file named "mydata.txt" using an output file stream object (arbitrarily) named "outputFile" for future output statements:
ofstream outputFile;
outputFile.open("mydata.txt");
Output data could be written to the file using its file stream object in a manner similar to the use of the cout stream object (introduced in Chapter 2). The statement below would write from an integer variable named N to its file stream object "outputFile":outputFile << N;File stream objects can be both defined and opened in a single statement using code as follows:
ifstream inputFile("mydata.txt");
or ofstream outputFile("mydata.txt");C:\Temp\mydata.txt". Because the C++ language interprets the character "\" as the start of an escape sequence, C++ programmers must remember to "escape" that character when referring to it by writing it as "\\". As such, the path to the file mentioned earlier would be written in C++ as: "C:\\Temp\\mydata.txt".outputFile.close();
main" (all lowercase) and program execution always begins with it. Any function can call (execute) other functions. A function must be declared in the source code ahead of where it is called. This can be accomplished by writing the source code for the entire child (called) function ahead of its parent (calling) function, or by writing a "function prototype" statement (see below) ahead of the calling function.return is used for two purposes in C++: (1) to place a value (its argument) in the function's identifier, and (2) to immediately terminate a function and pass control back to its parent function.
A function that returns a value through its identifier is called by a statement that treats the function name
as a data object (having an action performed upon it). On the otherhand, a function that does not return a value through its identifier is called by a statement that treats the function name as a verb (a command starting the statement). For more information,
read the notes about Functions and Parameter Passing.& (ampersand) immediately after the data type indicator (as in: int &). The blank space is optional. The data type indicated for the reference variable must match the data type of its related actual parameter.
For example, the declaration for a reference variable named NICKNAME as an alias for an actual parameter of type int would be:int &NICKNAME;In the declaration above, the identifier NICKNAME acts as a "reference to an integer". Although the ampersand (
&) touches the identifier, it is not part of it. Note that the identifier is just NICKNAME, not &NICKNAME.
This topic is closely relate to the terms in Chapter 9 about pointers. N[0] through N[9] would be:int N[10];Arrays can be any data type, but all elements of an array must be the same data type. The quantity of elements can be expressed as a literal (as shown in brackets above
[10]) or using named constants or symbolic constants (as in the segment of code below): #define SIZE 10
int N[SIZE];
int T[5][3];All elements of all sets of elements in an array must be the same data type. The quantity of elements can be expressed as literals (as shown above) or using named constants or symbolic constants (as in the segment of code below):
#define ROWS 5
#define COLS 3
int T[ROWS][COLS];
#include <vector>As with arrays, each individual storage location within a vector is called an element and each individual element is referenced using a subscript. And vector elements also are numbered starting at zero. The statement in C++ to declare a vector of ten integer storage locations labeled
N[0] through N[9] would be:vector<int> N(10);Note the use of parentheses () in the statement above around the vector size (10). Remember that array sizes are specified within brackets []. To declare the vector above with specifying its initial size, simply omit the parenthesized size, as in:
vector<int> N;Like arrays, vectors can be any data type, but all elements of a vector must be the same data type. The quantity of elements can be expressed as a literal (as shown in parentheses above
(10)) or using named constants or symbolic constants (as in the segment of code below): #define SIZE 10
vector<int> N(SIZE);
at returns the value of a vector element at specified subscript.capacity returns the maximum number of elements that may be stored in a vector without allocating additional memory. (Similar to the size member function below which reports memory usage rather than allocation)clear clears the vector of all its elements, removing the ability to reference them, but without deallocating the memory used by the vector, which is reserved for further growth of the vector).empty returns the Boolean value true if the vector is empty (ie. contains zero elements); otherwise returns false.pop_back removes the top (last) element from a vector, reducing its size by 1.push_back appends a new element to the top (end) of a vector (increasing its size by 1) and assigns the new element a value specified as this member function's argument.reverse reverses the order of the elements, in a vector.resize increases the size of a vector by the the number of elements specified as the first argument to this member function and initalizes the new elements to a value specified as its second argument.size returns the quantity of elements contained within a vector. (Similar to the capacity member function above which reports memory allocation rather than usage.)swap swaps the contents of the vector with a different vector, specified as this member function's argument.int *IPTR;In the declaration above, the data type is "pointer to an integer"; not just "pointer". Although the star touches the identifier, it is not part of it. The identifier is just IPTR, not *IPTR. It is a common practice by programmers to include the letters "PTR" (or just "P") at the end of the identifer when declaring pointers to help readers realize that they are pointers. Pointers should not be confused with reference variables mentioned with the terms in Chapter 6 about functions and parameter passing. For more information about pointers, read the page Pointers and Indirection.
IPTR = &I;the following statement could be used to indirectly assign the value in I to variable X:
X = *IPTR;For more information about indirection, read the page Pointers and Indirection.
S[0] through S[19] to hold a string of 20 symbols would be:char S[20]; /* Declare a string named S to hold no more than 20 characters */
#include <string>Some of the most popular string functions are:
| Usage Example | Explanation of Purpose |
|---|---|
strlen(S) |
Return the length of the string S |
strcpy(T,"Source") |
Copies the string "Source" into the string (character array) T |
strcmp(A,B) |
Compares the contents of string A to string B and returns a: 0 if they are equivalent under ASCII rules, negative integer if string A precedes B, and positive value if string B precedes string A |
strcat(A,B) |
Concatenates (appends) string B onto the end of string A |
'\0' which is sometimes read aloud as "whack zero". Note the use of single quotes (apostrophes) to indicate a character literal.