C++ Data Type Modifiers

In this tutorial you will learn about the C++ Data Type Modifiers and its application with practical example.

C++ Data Type Modifiers

In C++, modifiers is used to modify or add special meaning to the base types. It is used as prefix to primitive data types to alter their predefined meaning.

In C++, we have following data type modifiers –

  • signed
  • unsigned
  • long
  • short

The modifiers can be used with primitive data types to make them more precise and to modify their range.

Integer Type Modifiers

The signed, unsigned, long, and short modifiers can be used with integer types. The signed and unsigned modifiers can also be used as prefix to long or short modifiers. For example, unsigned long int.

Type Approximate Size
(in byte)
Minimal Range
short 2 -32768 to 32767
unsigned short 2 0 to 65,535
signed short 2 same as short
int 2 -32768 to 32767
unsigned int 2 0 to 65,535
signed int 2 same as int
long 4 -2,147,483,648 to 2,147,483,647
unsigned long 4 0 to 4,294,967,295
signed long 4 same as long

Character Type Modifiers

The signed and unsigned modifiers can be applied to char type.

Type Approximate Size
(in bytes)
Minimal Range
char 1 -128 to 127
unsigned char 1 0 to 255
signed char 1 same as char

Float Type Modifiers

The long modifier can be applied to double type.

Type Approximate Size
(in bytes)
Minimal Range Digits of Precision
float 4 3.4 × 10-38 to 3.4 × 1038 – 1 7
double 8 1.7 × 10-308 to 1.7 × 10308 – 1 15
long double 10 3.4 × 10-4932 to 3.4 × 104932 – 1 19

 

Type Qualifiers in C++

In C++, type qualifiers are used to provide additional information about the variables.

Qualifier Meaning
const Objects of type const cannot be changed by your program during execution
restrict A pointer qualified by restrict is initially the only means by which the object it points to can be accessed. Only C99 adds a new type qualifier called restrict.
volatile The modifier volatile tells the compiler that a variable’s value may be changed in ways not explicitly specified by the program.

In this tutorial we have learn about the C++ Data Type Modifiers and its application with practical example. I hope you will like this tutorial.