x

C++ Type Qualifiers

PREV    NEXT 

C++ Type Qualifiers:


What are type Qualifiers?

In C++, the type qualifier is added to a variable because it adds an extra quality like specifying constant-ness to a variable. It also provides one or two properties to an identifier. They can come with any type specifier but they cannot come after first comma at the time of multiple item declaration. The type qualifiers add refinement to the type object that is being declared. Basically, the type qualifiers specify something about how it is accessed or where it is stored.

There are three types of type qualifiers

  • const
  • volatile
  • mutable

Let us have a brief description about the type qualifiers

Const

 The const type qualifier defines the type is constant. An object whose type is const type qualifier is a const object. This type of object cannot be modified and if it is tried then there will be a compile time error.


 Volatile

 The volatile type qualifier defines the type is volatile. The object whose type is volatile qualifier is volatile object. The volatile qualifier tells the compiler that a variable value can be changed in ways not explicitly specified by the program.

Mutable

Mutable type qualifier is applied on non-static class members of non-reference and non-const type and mutable members of const class instances are modifiable and it specifies that the member does not affect the external visible state of the class.

PREV    NEXT 



Like it? Please Spread the word!