Programming‎ > ‎C‎ > ‎

const

1. What is the use of const volatile.
    const means the program can not modify the value.
    volatile means the value may be arbitrarily modified outside the program.
    the two are separate and not mutually exclusive.
    this const volatile <type> <varname> will thus satisfy both requirements and prevent an optimizing compiler from incorrectly optimizing the code, that it would do if only 'const' were used.
    If a variable is both const and volatile, the two modifiers can apprear in either order.

2. What do the following declarations mean?
    const int a;               // constant integer
    int const a;               // constant integer
    const int *a;             // pointer to the constant integer
    int * const a;            // constant pointer to an integer
    int const * a const;    // constant pointer to a constant integer

Comments