C++

C++ Modifier Types.

C++ Modifier Types.

Here, we look into C++ modifiers. C++ allows the char, int, and double data types to have modifiers to be added before the type field so as to change the behaviour of  base data type. We have already discussed them when describing data types.  A modifier is used to change the meaning of the base type as per the need or requirement of the function or program. There are mainly 4 types of data types of modifiers

  1. signed
  2. unsigned
  3. long
  4. short

The modifiers signed, unsigned, long, and short are usually used to modify integer base types. In addition, signed and unsigned can be applied to char, and long can be applied to double. Please note that the modifiers signed and unsigned can also be used as prefix to long or short modifiers. For example, unsigned long int. 

In C++, you can use a shorthand notation for declaring unsigned, short, or long integers by using the words unsigned, short, or long (without writing int). It automatically implies int. For e.g. both the below declaration are same from compiler point of view.

unsigned counter; 
unsigned int counter;

Apart from them, there are some additional type qualifiers in C++. const qualifier before a variable make it immutable i.e. const objects cannot be changed by your program during execution. The volatile modifier tells the compiler that a variable's value may be changed in ways not explicitly specified by the program and so it must not store it into memory and instead cache it in its registers. The restrict is a new qualifier that got added in C++ in C99 revision. restrict when applied to a pointer pointing to any C++ object, then the only way to access this object is via this pointer.