Modifier and Qualifier in C++


Modifiers in C++

Modifier in C++ are used to alter the meaning of a predefined data types. It changes the storage space of the data type i.e. it either increases or decreases the storage space. Different data types and their modifiers can be listed as follows:

Integer Type Modifier in C++

There are mainly 4 types of Integer type modifiers. These are:

  • Signed: Signed modifier accepts both positive and negative values. It has the syntax as:
    signed int variable_name; or signed int variable_name=value;For example:

    In the above example, the signed integer variable x can hold both positive and negative values.
  • Unsigned: Unsigned modifier accepts only positive values. It has the syntax as:
    unsigned int variable_name; or
    unsigned int variable_name=value;
    For example:

    In the above example, the unsigned integer variable x can hold positive value only. Hence, the 2nd example is wrong because it assigns negative value to x.
  • Long: Long is used to increase the size of the integer data type to 2 more bytes. It has the syntax as follows:
    long int variable_name; or long int variable_name=value;
    For example:

    In the 1st example, x occupies 2 bytes of memory, but in the 2nd example x occupies 4 bytes of memory.
  • Short: In the different operating system, integer variable takes different memory space. To make it fixed, short is used. It has the syntax as:
    short int variable_name; or short int variable_name=value;
    For example:

    In the 1st example, x may take 2 bytes or 4 bytes. But, in the 2nd example, x will always take 2 bytes only.

Floating Point Modifier in C++

Double is an another floating point data type and there is only one floating point modifier i.e. long. It has the syntax as:

For example:

Character Type Modifier in C++

Character data type has 2 modifiers – signed and unsigned. Signed modifier represents the range from -128 to 127 and unsigned modifier ranges from 0 to 255. It has the syntax as follows:

Important: Modifiers can be combined as follows:

  • signed can be combined with short. For example:
  • signed can be combined with long. For example:
  • unsigned can be combined with short. For example:
  • unsigned can be combined with long. For example:

Type of qualifier in C++

Qualifiers in C++  are used to provide additional information about the data type they precede. It is of mainly 3 types:

  • Volatile: when a variable is declared as volatile, this means the variable value may be changed in a way which is not explicitly specified in the program.
  • Const: when a variable is declared as const, then its value cannot be changed during the execution of the program.
  • Restrict: Pointer variable uses the restrict qualifier. When a pointer is declared as restrict, it means it can access only that variable which is pointed by the pointer.
Close Menu