Constants

Home / C Programming / Constants

Constants


In C programming, constants are fixed values that do not change during program execution. They are used to represent literal values in the code. Constants can be of different types, such as integer constants, floating-point constants, character constants, and string constants. Here's a brief explanation of each type:

Integer Constants: Integer constants represent whole numbers without fractional parts. They can be specified in decimal, octal, or hexadecimal format. For example:

Decimal: 42, 0, -10

Octal: 052 (prefix 0), 077 (prefix 0)

Hexadecimal: 0x2A (prefix 0x), 0xFF (prefix 0x)

Floating-Point Constants: Floating-point constants represent real numbers with fractional parts. They can be specified in decimal or exponential notation. For example:

Decimal: 3.14, 0.1, -2.5

Exponential: 1.23e-4 (1.23 x 10^(-4)), 2.5E3 (2.5 x 10^3)

Character Constants: Character constants represent individual characters enclosed in single quotes (''). They can be ASCII characters, escape sequences, or special characters. For example:

'A', '9', '!', '\n' (newline), '\t' (tab), '\', etc.

String Constants: String constants represent a sequence of characters enclosed in double quotes (""). They can be a combination of characters, escape sequences, or special characters. For example: