WEB DEVELOPER SITE
PYTHONPHP7JAVA
 

C++ Modifier Types



C++ allows you to place modifiers before the char, int, and double data types. Modifiers are used to change the meaning of the basic type, so it is more suitable for the needs of various situations.

The data type modifiers are listed below:

  • signed
  • unsigned
  • long
  • short
The

modifiers signed, unsigned, long, and short can be applied to integers, signed and unsigned can be applied to character types, long can be applied to doubles.

The

modifiers signed and unsigned can also be prefixed with the long or short modifier. For example: unsigned long int.

C++ allows shorthand notation to be used to declare unsigned short integers or unsigned long integers. You can write int, just write the word unsigned, short or unsigned, long, and int is implied. For example, the following two statements declare unsigned integer variables.

unsigned x;
unsigned int y;

To understand the difference between C++ and signed unsigned integer modifiers, let's run the following short program:

Example

There are following example :-

#include <iostream >
using namespace std;
 
/* This program shows the difference between
   * signed and unsigned integers.
*/
int main() {
   short int i;           // a signed short integer
   short unsigned int j;  // an unsigned short integer

   j = 2000;

   i = j;
   cout << i << " " << j;

   return 0;
}

Type qualifiers in C++

The

type qualifier provides additional information about the variable.

Objects of type The
qualifiermeaning
constconst cannot be modified during program execution.
volatile modifier volatile tells the compiler not to optimize volatile variables, allowing programs to read variables directly from memory. For general variable compilers, variables are optimized, and the values of variables in memory are placed in registers to speed up read and write efficiency.
restrictThe pointer modified by restrict is the only way to access the object it points to. Only C99 adds a new type qualifier restrict.