Utility Functions and C Language Reference > C Language Reference > Alphabetical List of Functions > const

const

Example: const

Defines a variable which cannot be modified by any other part in the code. You place the keyword const in front of any variable declaration. If the keyword volatile is placed after const, then this allows external routines to modify the variable (such as hardware devices). This also forces the compiler to retrieve the value of the variable each time it is referenced rather than possibly optimizing it in a register.

Constant numbers can be defined in the following way:

Constant type Description
Hexadecimal digits Where hexadecimal digits is any digit or any letter A through F or a through f.
Decimal digits Any number where the first number is not zero
Octal constant Any number where the first number must be zero.
Floating numbers

A fractional number, optionally followed by either e or E, then the exponent. The number may be suffixed by:

  • U or u: Unsigned.
  • L or l: Long.
  • F or f: A literal of float type.
  • LL or ll: A literal of long long type.

U and L/LL can be combined.