c/language/const

Each individual type in the C has several qualified versions of that type, corresponding to one, two, or all three of the const,, and, for pointers to object types,  qualifiers. This page describes the effects of the const qualifier.

Objects with const-qualified types may be placed in read-only memory by the compiler, and if the address of a const object is never taken in a program, it may not be stored at all.

semantics apply to expressions only; whenever a const lvalue expression is used in context that does not require an lvalue, its  qualifier is lost (note that volatile qualifier, if present, isn't lost).

The lvalue expressions that designate objects of const-qualified type and the lvalue expressions that designate objects of struct or union type with at least one member of const-qualified type (including members of recursively contained aggregates or unions), are not modifiable lvalues. In particular, they are not assignable:

A member of a const-qualified structure or union type acquires the qualification of the type it belongs to (both when accessed using the operator or the  operator).

If a function type is declared with the const type qualifier (through the use of ), the behavior is undefined.

A pointer to a non-const type can be implicitly converted to a pointer to const-qualified version of the same or. The reverse conversion can be performed with a cast expression.

Note that pointer to pointer to is not convertible to pointer to pointer to ; for two types to be compatible, their qualifications must be identical.

Any attempt to modify an object whose type is const-qualified results in undefined behavior.