4.3.8.1 Const Type Qualifier

The const type qualifier is used to tell the compiler that an object is read only and should not be modified. If any attempt is made to modify an object declared const, the compiler will issue a warning or error.

Provided that no other storage qualifiers are used, const-qualified objects (excluding autos and parameters) are by default linked into the program space, however this can be changed by using the -mno-const-data-in-progmem option (see 3.6.1.5 Const-data-in-progmem Option). Such objects can also be made absolute, allowing them to be easily placed at a specific address in the program memory, see 4.4.4.1 Absolute Objects In Program Memory.

Objects qualified with const are accessed as if they were qualified with __memx, see 4.3.9.1 Memx Address Space Qualifier. If the definition of const-qualified objects also uses storage qualifiers, such as __flash or __flashn (see 4.3.9.2 Flash Qualifier and 4.3.9.3 Flashn Qualifiers) the read access strategy implied by these qualifiers take precedence over that implied by const.

Usually a const object must be initialized when it is declared, as it cannot be assigned a value at any point at runtime. For example:

const int version = 3;

will define version as being a read-only int variable, holding the value 3.