Data Type Modifiers in C++

In this tutorial, we are going to learn about data type modifiers which are special words know as modifiers that are used to modify the meaning of the predefined built-in data types except for void data type and expand them to a much larger set.

Data Type Modifiers in C++

Except for the void data type, the basic data types may have various modifiers preceding them. We use modifiers to alter the meaning of the base data types to fir them in various situations more precisely.

There are the following modifiers available in the C++ programming language :

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

We can also use these modifiers with character and integer data types, we can also apply long to double, and please note that if we use a long float that simply means double.

Let us discuss the types of modifiers we can use with each fundamental data type.

A. Integer Type Modifiers:

C++ offers three types of modifiers for an integer are short, int, and long that can represent three different integer sizes. We can use both signed and unsigned versions of them. The prefix unsigned makes the integer type not hold negative values. For example short represent the range of integers from -32768 to+32767, then if use the unsigned version which will result in a change of range which will be 0 to 65535. The advantage of this is that it increases the largest value that the variable can hold.

The below table summarizes different integer types, their sizes, and the minimal range they can hold.

 TYPE  Approximate Size (in bytes)  Minimal Range

short

unsigned short

signed short

2

2

2

-32768 to 32767

 0 to 65,535

 same as short

int 

unsigned int

signed int

4

4

4

-2147483648 to 2147483647 

0 to 4294967295 

same as int

long

unsigned long

signed long

8 bytes or (4bytes for 32 bit OS)

8 bytes

8 bytes

-9223372036854775808 to 9223372036854775807

0 to 18446744073709551615

same as long

B. Character Type Modifiers:

Character types are very similar to integer types as inside memory it actually holds numbers that are equivalent codes of character/symbols. A single byte can represent the whole range of 256 known characters. The char can also be signed or unsigned. 

The below table summarizes different character types, their sizes, and the minimal range they can hold.

 TYPE Approximate Size (in bytes) Minimal Range

char

unsigned char

signed char

1

1

1

-128 to 127 or 0 to 255

0 to 255

-128 to 127

C.  Floating-point Type Modifiers:

In C++ we have the following three floating-point types: float, double ( It is the same as long float ), and long double. These types are described in terms of the number of significant figures they can represent and the minimum allowable range of exponents.

The below table summarizes different floating-point types, their sizes, and the minimal range they can hold.

 TYPE Approximate Size (in bytes) Minimal Range Precision

float

double

long double

4

8

10

1.2E-38 to 3.4E+38

2.3E-308 to 1.7E+308

3.4E-4932 to 1.1E+4932

7 decimal places

15 decimal places

19 decimal places

Some implementation may allow you to apply unsigned to the floating-point types for example unsigned double, which reduces the portability of your program and it is not good practice and generally not recommended.

Note: The latest release of  C++ has a new integral type long long int which is at least 8 bytes long.

Now, this the end of this tutorial we will learn about the Derived data types in the next tutorial.

like
0
dislike
0
love
0
funny
0
angry
0
sad
0
wow
0