< C++ Tutorial

C++ constant and literals

← Previous Next →


Constant refers to variables having fixed values that the program can't change during its execution.
These fixed values are also called literals.


Constant definition in C++

const keyword is used to define a constant variable.

Example :

const int employeeId = 121 ;
const float salary = 20145.50 ;


Types of literals:

  • Integer literals

    10    // decimal number
    0b0100   // binary number
    0x20e   // octal hexadecimal
    0123   // octal
  • Float literals

    10.23
    1003E-2
  • Character literals

    'a'
    'A'
  • String literals

    "Hello"
    "George"
← Previous Next →