Character Set

Characters are used to form the words, numbers and expressions. The characters in C++ are grouped into the following categories: - 

Keywords and Identifiers 

C++ word is classified as either a keyword or an identifier. All identifiers have fixed meaning and these meanings cannot be changed. Keywords serve as the basic building blocks for program statements. The list of all keywords is listed below. All keywords must be written in lowercase.

Identifiers refer to the names of variables, functions and arrays. These are user - defined names and consist of a sequence of letters and digits. 

Examples of identifiers: - 

Data Types

A data type defines a set of values that a variable can store along with a set of  operations that can be performed on that variable. C++ has five basic built in data types: -. 

Character (char)
Integer (int)  
Floating point (float)  
Double floating point (double) 
Valueless (void) 

Void has three uses: -. 
 
To declare explicitly a function as returning no value.
To declare explicitly a function as having no parameters.
To create generic pointers. 
C++ also supports several aggregate types including structures, unions, enumeration and user defined types.

Type Modifiers 
 
Excepting type void, the basic data types may have various modifiers preceding
them. A modifier is used to alter the meaning of the base type to fit the needs of
various situations more precisely. The list of modifiers is shown here: - 
 
signed 
unsigned 
long 
short 

Modifiers can be applied to character and integer base types. However, long can also be applied to double.  


Constants

Constants in C++ refer to fixed values that do not change during the execution of a program. C++ supports several types of constants as shown below: - 

 Numeric Constants 
 
1. Integer Constants
2. Floating point (real) Constants 
 Character Constants
 
1. Single Character Constants
2. String Constants

The following rules apply to all numeric constants: -, non-digit characters and blanks cannot be included within a constant. A constant can be preceded by a minus sign.  

Integer Constants 
 
An integer constant refers to a sequence of digits. There are three types of integers, namely, decimal, octal and hexadecimal.  
 
Decimal integers consist of a set of digits from 0 through 9. The decimal integers can be positive or negative.  

Example:
1234    
0
+456
-4238
 
Octal integers consist of any combination of digits from 0 through 7, with a leading zero.  
Example: 
089
0456 
0  
0555 
 
Hexadecimal integers consist of a sequence of digits 0 through 9 and alphabets from A (a) through F (f). These integers are preceded by 0x or 0X. The letters 'A' (a) through 'F ' (f) represent the integers 10 through 15. 
 
Example:
0X3
0XBC
0x76f 

The largest integer value that can be stored is machine dependent. It is 32767 on 16 bit machine and 2,147,483,647 on 32_bit machine. It is also possible to store large integer constants on these machines
by appending modifiers such as U, L, UL to the constants.

Example: 
23456U(u)   unsigned integer 
987654321UL(ul)  unsigned long integer  
928374L(l)  long integer  

Floating-Point Constants
 
Floating-point constants are represented by numbers containing fractional parts like in 549.4545. Floating-point constants are also sometimes called as real number constants. 
 
Example:
0.00098 
3210.67
-56.890
+345.9 

A real number may also be expressed in exponential notation. For example, the value 2345.78 may be written as 23.4578e2 in exponential notation. e2 means multiply by100. The number 3e-2 would mean 3*1/100. 

Some of the valid floating - point constants are: - 

0.  (digit after the decimal point can be omitted) 
.00045  (digit before the decimal point can be omitted)
7.31245e +3 (the notation e3 can also be written as e + 3) 
2E-8  (e or E is allowed)  
 
Some of the invalid floating - point constants are: - 
 
12  (decimal point or an exponent must be present)  
1,067.89 (comma is not allowed) 
3.89e+1.5 (exponent must be an integer)
5E 12  (no embedded spaces are allowed) 
Exponential notation is useful for representing numbers that are very large or very small in magnitude. For example, 45000000000 can be written as 45e9. Similarly, 0.000000454 is equivalent to -4.54e-7.

Single Character Constants
 
A character constant is a single character enclosed within a pair of single quotes. 
 
Example:
'A'
'3'
'?'
';' 
' ' 
Character constants have integer values called ASCII values. For example, the character constant '3' has an ASCII value of 83.Therefore, it is not the same as the integer value 3. Some of the character constants and their corresponding ASCII values are: -     
     
Constant          ASCII value
    'a'         97 
      'A'         65   
   '&'         38 
     ';'            59 

String Constants

A string constant is a sequence of characters enclosed within a pair of double quotes. The string constant may also include special characters, numbers and blank spaces.  

Example:
 
" Hello!"
" I'm going for shopping today. Will you come?" 
" 549, The Mall, Shimla."  
" 4321-1234"
" O"
 
String constant "O" differs from the character constant 'O'. The string constant does not have an integer value like a character constant has. A string constant is always followed by a null character ('\0').

The following program accepts your name, address and phone number as string constants and displays them: -

#include <iostream.h>

void main(void)
{
    cout<<" Name:   Rajeev\n";
    cout<<" Address: 549, ABIDS, Hyderabad\n";
    cout<<" Contact:  040-211717\n";
The output is: 
 
 Name:     Rajeev
 Address: 549, ABIDS, Hyderabad
 Contact:  040-211717 

Escape Sequences  
 
Certain non printing characters, as well as the backslash (\) and the apostrophe ('), can be expressed in terms of escape sequences. An escape sequence always begins with a backward slash and is followed by one or more special characters. For example, a newline can be referred to as \n. Such escape sequences always represent single characters, even though they are written in terms of two or more characters. The commonly used escape sequences are listed below: -
                 
Particular interest is the escape sequence \0. This represents the null character, which is used to signify the end of a string. Null character is not equivalent to the character constant ' 0 '.