T - 9 - CPP Declarations
T - 9 - CPP Declarations
C++
Tokens
Keywords
There are 95 keywords reserved in C++. Some of the main Keywords are:
Pointer
Structure
IDENTIFIERS
Union
Array
Function
Rules for defining identifiers are follows:
• The constants in c++ are applicable to the values that do not change during
execution of a program.
• Constants often represent fixed values used frequently in the code, such as the
value of pi or the maximum size of an array.
• To define a constant in C++, you use the const keyword followed by the data type
and the constant's name and then initialize it with a value.
• The value of a constant cannot be changed once it has been defined.
C++ constants
1. Symbolic constants
• A symbolic constants is defined in the same way as a variable.However , once the
constant is initialized , the assigned value cannot be altered.
• We can define the symbolic constants in C++ in three ways.
1. Using the ‘const’ keyword
2. Using ‘#define’ preprocessor directive.
3. Using “enum” keyword
• Here is an example:
const double PI = 3.14159;
• In this example, the constant PI is of type double and is initialized with the value of
pi. You can then use the constant PI in your code wherever you need to use the
value of pi.
• Using constants instead of regular variables is important when you need to
represent fixed values in your code.
2. Numerical Constants
2.1: Integer constants
Example:
3. Character constants
3.1: single character constants
• A character constants in c++ represented with a single character and it is enclosed
within single quotes.
• Each character constant has a particular integer value associated it.
• Each character is represented with different ASCII value.
• A character can also be represented with single digit or single special symbol or
white space, all enclosed within a pair of single quote marks.
Example:
‘a’ , ‘8’ , ‘&’
OPERATORS
• An operator is a symbol that operates on a value to perform specific mathematical or
logical computations
• An operator operates the operands.
For example,
int c = a + b;
• Here, ‘+’ is the addition operator. ‘a’ and ‘b’ are the operands that are being ‘added’.
• The new operators are in C++
o >> ( insertion operator)
o << ( Extraction operator )
o :: ( Scope access (or resolution ) operator)
o ::* ( pointer to member decelerator)
o ->* ( deference pointers to pointers to class members)
o .* ( deference pointers to class members )
o Delete ( memory release operator)
o New ( memory allocation operator )
STRING
• String represented by an array of characters. String constants are enclosed in double
quotes.
• Following are the valid examples of string constants.
Example
“person” , Tamilnadu” , “india”