Modifiers in C++
Modifiers in C++ are basically used to modify or add a special meaning to the basic data-types. While defining a variable we generally
used them with the predefined
datatype to modify its range and make it more precise based on the user requirement.
Different modifiers provided by C++ are:
- Signed
- Unsigned
- Long
- Short
Syntax for using the modifiers is as below:
< modifier-type>< data-type>< variable name>
We can also use by combinig two modifier type. Example usage is as below.
Ex. long int
long unsigned int
Now let's see the details of modifiers based on different data-types
Modifiers for Integer type:
In case of integers we can use the signed, unsigned, long and short modifiers.
Ex. short int, long int etc.
Below is the detail of the size and range of integer type modifiers.
Modifier Type | Size (In bytes) | Value Range |
---|---|---|
signed | 4 | -2,147,483,648 to 2,147,483,647 |
unsigned | 4 | 0 to 4,294,967,295 |
short | 2 | -32,768 to 32,767 |
long | 4 | -2,147,483,648 to 2,147,483,647 |
unsigned short | 2 | 0 to 65,535 |
unsigned long | 4 | 0 to 4,294,967,295 |
Floating Point Modifiers:
In the float datatypes we can use long modifiers.
Ex. long float.
Below is the detail of the size and range of float type modifiers.
Modifier Type | Size (In bytes) | Value Range |
---|---|---|
float | 4 | 3.4E +/- 38 |
double | 8 | 1.7E +/- 308 |
long double | 8 | 1.7E +/- 308 |
Character Modifiers:
In the character datatypes we can apply signed and unsigned modifiers.
Ex. unsigned char.
Below is the detail of the size and range of float type modifiers.
Modifier Type | Size (In bytes) | Value Range |
---|---|---|
char or signed char | 1 | -128 to 127 |
unsigned char | 1 | 0 to 255 |
Type Qualifiers:
Type qualifiers generally provides includes more informations about our defined variables. There are three types of qualifiers in C++.
- const
- volatile
- restrict
Details of them is as below.
Type Qualifier | Description. |
---|---|
const | const qualifier is used to provide the constantness to the variable, so that its value cannot be changed. |
volatile | volatile qualifier is used in such special case where value of the variables need to be changed. It indicate the compiler that the variable value can be changed any time in the manner not directly specified in the program |
restrict | restrict qualifier indicates that two pointers cannot point to overlapping memory regions |