What is the Literals & constant In C++ In Programming language?


Literals are data items that never change their value during a program run. C++ allows several kind of literal:

(a) Integer constants

Integer constants are the whole numbers without any fractional part. An integer constant must have at least one digit that must contain any decimal point.

C++ allow 3 type of integer constants:

Decimal( base 10)
Octal (base 8)
Hexadecimal( base 16 )

(b) Character constants

A character constant is one or more characters enclosed in single quotes, as in ‘z’.

A character constant in C++ must contains one or more character and must be enclosed in single quotation marcs.

(c) Floating Constants

Floating constants are also called real constants. Real constants are the numbers having fractional part.

These may be written in one of the two forms called fractional form or the exponent form.

(d) String literals

Multiple character constants can be dealt with in two ways in C++.

If encoded in single quotes, these are treated as character constants and if encoded in double quotes, these are treated as string constants.

A strin literals is a sequence of characters surrounded by double quotes.


The following characters are used as punctuator in C++:

Bracket [ ]

Parenthesis ( )

Braces { }

comma ,

Semicolon ;

colon :

Ellipsis …

Equal =

Pound sign #