Special Characters

& has a number of distinct meanings. When it precedes the name of a variable without following the name of a type, it means “the address of the following variable”. For example, &Str means “the address of the variable Str”. When & follows a type name and precedes a variable name, it means that the variable being declared is a reference — that is, another name for a preexisting variable. In this book, references are used only in argument lists, where they indicate that the variable being defined is a new name for the caller's variable rather than a new local variable.

% is the “modulus” operator, which returns the remainder after dividing its left-hand argument by its right-hand argument.

:: is the scope resolution operator, which is used to tell the compiler the scope of a variable. We can prefix it to the name of a global variable to prevent the compiler from confusing it with a variable of the same name from the standard library. It is also used to specify the namespace or class of a variable or function, when placed between the namespace or class name and the variable or function name.

< is the “less than” operator, which returns the value true if the expression on its left has a lower value than the expression on its right; otherwise, it returns the value false. Also see operator < in the index.

<< is the “stream output” operator, used to write data to an ostream. Also see operator << in the index.[1]

[1] As is often the case in C++, this operator (and the corresponding stream input operator, >>) have other almost completely unrelated meanings besides the ones defined here. I'm only bringing this up so that you won't be too surprised if and when you run into these other meanings in another textbook.

<= is the “less than or equal to” operator, which returns the value true if the expression on its left has the same or a lower value than the expression on its right; otherwise, it returns the value false. Also see operator <= in the index.

= is the assignment operator, which assigns the value on its right to the variable on its left. Also see operator = in the index.

== is the “equals” operator, which returns the value true if the expression on its left has the same value as the expression on its right; otherwise, it returns the value false. Also see operator == in the index.

> is the “greater than” operator, which returns the value true if the expression on its left has a greater value than the expression on its right; otherwise, it returns the value false. Also see operator > in the index.

>= is the “greater than or equal to” operator, which returns the value true if the expression on its left has the same or a greater value than the expression on its right; otherwise, it returns the value false. Also see operator >= in the index.

>> is the “stream input” operator, used to read data from an istream. Also see operator >> in the index.

[ is the left square bracket; see square brackets for usage.

] is the right square bracket; see square brackets for usage.

[ ] is used after the delete operator to tell the compiler that the pointer for which delete was called refers to a group of elements rather than just one data item, e.g., when deleting an array of chars. This is one of the few times when we have to make that distinction explicitly rather than leaving it to context.

{ is the left curly brace; see curly braces for usage.

} is the right curly brace; see curly braces for usage.

!= is the “not equals” operator, which returns the value true if the expression on its left has a value different from the expression on its right; otherwise, it returns the value false. Also see operator != in the index.

&& is the “logical AND” operator. It produces the result true if the expressions on both its right and left are true; if either of those expressions is false, it produces the result false. However, this isn't the whole story. There is a special rule in C++ governing the execution of the && operator: If the expression on the left is false, then the answer must be false and the expression on the right is not executed at all. The reason for this short-circuit evaluation rule is that in some cases you may want to write a right-hand expression that will only be valid if the left-hand expression is true.

++ is the increment operator, which adds 1 to the variable to which it is affixed.

+= is the “add to variable” operator, which adds the value on its right to the variable on its left.

-= is the “subtract from variable” operator, which subtracts the value on its right from the variable on its left.

// is the comment operator; see comment for usage.

|| is the “logical OR” operator. It produces the result true if at least one of the two expressions on its right and left is true; if both expressions are false, it produces the result false. However, there is a special rule in C++ governing the execution of the || operator: if the expression on the left is true, then the answer must be true and the expression on the right is not executed at all. The reason for this short-circuit evaluation rule is that in some cases you may want to write a right-hand expression that will only be valid if the left-hand expression is false.

A #define statement is a preprocessor directive that defines a preprocessor symbol. While this statement can be used to define constant values for general use, it has been mostly superseded except as part of the include guard mechanism.

An #endif statement is a preprocessor directive that terminates a section of conditional code. It is used in this book as part of the include guard mechanism.

An #ifdef statement is a preprocessor directive that begins a section of conditional code. It has the opposite effect from the #ifndef directive.

An #ifndef statement is a preprocessor directive that tells the preprocessor to check whether a particular preprocessor symbol has been defined. If not, the following source code is treated normally. However, if the specified preprocessor symbol has been defined, the following source code is skipped by the rest of the compiler as though it were not present in the source file. The #ifndef statement is used in this book as part of the include guard mechanism.

An #include statement is a preprocessor directive that has the same effect as that of copying all of the code from a specified file into another file at the point where the #include statement is written. For example, if we wanted to use definitions contained in a file called xstream.h in the implementation file test.cpp, we could insert the include statement #include "xstream.h" in test.cpp rather than physically copying the lines from the file xstream.h into test.cpp.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset