Literals in C

Literals in c are fixed values whose values cannot be changed during the execution of a program. Literal contains memory but no reference to it.

There are four types of literals in C programming, they are as follows:

  • Integer literal
  • Float literal
  • Character literal
  • String literal

Integer literal

Integer literal represent only integer values. It can be decimal, octal, hexadecimal constant.

Decimal number

It is designed by representing the digits between 0 to 9. For example 34,99,…

Octal number

It is defined as a number in which 0 is followed by digits such as 0 to 7. For example 013,016,…

Hexadecimal number

It is defined as a number in which 0x or 0X is followed by the hexadecimal digits( 0-9,a-z,A-Z).

An integer literal can have suffix that is a combination of U and L for unsigned and long respectively.

Float literal

It contains only floating-point values or real numbers. It must be specified either in decimal or in exponential form. Float literal contains various parts such as integer part, real part, exponential part, fractional part.

Decimal form

The decimal form must contain either decimal point, exponential part, or both. It can be prefixed by the ‘+’ or ‘-‘ symbol, which specifies the positive or negative numbers. For example +8.6,-4.5,…

Exponential form

It contains two parts, mantissa and exponent. The signed exponent is introduced by either e or E. For example 1e4,-6e4,…

Character literal

A Character literal contains a single character enclosed within single quotes. For example ‘m’, ‘p’,…

We can represent escape sequences in single quotes to form character literal. For example ‘\n’,…

We can also represent octal or hexadecimal numbers as escape sequence characters to form character literal. For example ‘\097’ ,…

String literal

A string literal represents multiple characters enclosed within double quotes. It ends with ‘\0’ which gets automatically inserted. For example “Scholarsoul”,”Hello”,…

People also ask for

What are constants in C?

Constants represent fixed values whose values can not be changed during the execution of the program.