C++ Constants

C++ Constants


Constants are data storage locations. Unlike variables, and as the name implies, constants do not change. You must initialize a constant when you create it, and you cannot assign a new value later. You can use the const keyword.

When the pointer variable point to a const value:

Syntax:

  const data_type* var_name;

Example:

Output : 14

Constants can be of any of the basic data types and can be divided into Integer Numerals, Floating-Point Numerals, Characters, Strings and Boolean Values .

You should always declare the variable as constant when you have values that are unlikely to change: