Type Qualifiers

Type qualifiers give one of two properties to an identifier. The const type qualifier declares an object to be nonmodifiable. The volatile type qualifier declares an item whose value can legitimately be changed by something beyond the control of the program in which it appears, such as a concurrently executing thread.

The two type qualifiers, const and volatile, can appear only once in a declaration. Type qualifiers can appear with any type specifier; however, they cannot appear after the first comma in a multiple item declaration. For example, the following declarations are legal:

typedef volatile int VI;
const int ci;

These declarations are not legal:

typedef int *i, volatile *vi;
float f, const cf;   

Type qualifiers are relevant only when accessing identifiers as l-values in expressions. See L-Value and R-Value Expressions in Chapter 4 for information about l-values and expressions.

Syntax

type-qualifier :

const
volatile

The following are legal const and volatile declarations:

int const *p_ci;       /* Pointer to constant int */
int const (*p_ci);     /* Pointer to constant int */
int *const cp_i;       /* Constant pointer to int */
int (*const cp_i);     /* Constant pointer to int */
int volatile vint;     /* Volatile integer        */

If the specification of an array type includes type qualifiers, the element is qualified, not the array type. If the specification of the function type includes qualifiers, the behavior is undefined. Neither volatile nor const affects the range of values or arithmetic properties of the object.

This list describes how to use const and volatile.