Hey guys, what is up. I hope you all are good and are doing quite well. In this particular post, we will be talking about what is the data type and type modifiers in C++.
Data type helps us to know which type of data is it represents. It determines to identify the type of operations and data associated with it.
There are 3 types of data types:
Those data types that are not composed of other data types are called fundamental data types. These are predefined in C++ and can be used directly.
It is defined with integer int. Integers are whole numbers. These data types have no fractional part. To declare a variable, we write:
<data type> <variable name>; Example – int number;
It is defined with the keyword char. It is used to store characters in C++. These data types are often called integer data types as they are internally stored as integers by their ASCII value. To declare a variable, we write:
<data type> <variable name>; Example – char name;
A number having only a fractional part is a floating-point number. It is defined using the word float. To declare a variable using a float, we write –
<data type> <variable name>; Example – float radius;
ADVANTAGES OF FLOAT DATA TYPES OVER INTEGER DATA TYPES ARE:
They are also known as double-precision floating-point numbers. It is defined by the keyword double. Double is used similarly to that of the float data type. It is slower than float.
This datatype specifies an empty set of values and is used for return-type functions that do not return/restore any value. No object of type void can be declared.
Data types that are built from fundamental data types are called derived data types and these are not predefined. These are:
Derived data types are defined by the user or programmers according to their needs and are known as user-defined derived data types. These are:
We use a modifier to change the size and value of the base data type to fit various situations more precisely. Fundamental data types except void can be modified using modifiers.
The list of modifiers are as follows:
SIGNED:
It is the default float, char, and integers. It can store all real numbers that mean both positive and negative numbers.
UNSIGNED:
It is used with integer data types such as int and char. It doubles up the range of the positive side. Negative numbers are not acceptable.
LONG:
It can be used for both int and double data types. It increases the range and size of the variable. For example, Long int takes 4 bytes while long double takes 10 bytes.
SHORT:
Short is used with int data types. It is only a clarifier. It is similar to an integer.
TYPE | SIZE (IN BYTES) | MINIMAL RANGE |
Char | 1 | -128 to 127 |
Unsigned char | 1 | 0 to 255 |
Signed char | 1 | -128 to 127 |
Short | 2 | -32768 to 32767 |
Unsigned short | 2 | 0 to 65,535 |
Signed short | 2 | -32768 to 32767 |
Int | 2 | -32768 to 32767 |
Unsigned int | 2 | 0 to 65,535 |
Signed int | 2 | -32768 to 32767 |
Long | 4 | -2,147,483,648 to 2,147,483,647 |
Unsigned long | 4 | 0 to 4,294,967,295 |
Signed long | 4 | -2,147,483,648 to 2,147,483,647 |
What our customers say about us