Qualifiers in C Programming
For Complete YouTube Video: Click Here
In this class, we will try to understand Qualifiers in C Programming.
We covered all the essential data types like int, float, double, and char in our discussion on data types.
The Qualifiers are the keywords applied to the data types to change their meaning.
Types of Qualifiers:
There are three types of qualifiers.
- Size Qualifier
- Sign Qualifier
- Type Qualifier
In this class, we will not discuss type qualifiers.
The image below shows the clear view of different types of qualifiers.
The short and long are the keywords used for size qualifiers.
The signed and unsigned are the keywords for sign qualifiers.
Similarly, const and volatile are the for type qualifiers.
Size Qualifier in C
Size Qualifiers are prefixed to the primary data types to increase or decrease the space allocated to the variable.
The point to be noted is that the size allocated to a data type depends on the compiler and the machine on which the compiler is installed.
In our examples, we consider the allocation of 4 bytes for int, 4 bytes for float, 8 bytes for double, and 1 byte for char.
The image below shows the memory allocation of the data type int a = 14 with 4 bytes.
If we declare a variable as short int a = 14, the compiler will allow 2 bytes only.
Similarly, if we declare using a long qualifier, the compiler will allow 4 bytes only.
In short, we can understand it as short <= int >= long.
In the case of float, assigning short or long qualifiers does not make any difference. The size remains as 4 bytes.
Similarly, double with a long keyword will increase the size from 8 bytes to 16 bytes.
For char, the size will remain as 1 byte for short or long.
Sign Qualifiers in C
Sign Qualifier is used to specify the signed nature of the integer.
Declaring an integer variable means it can store a positive number or a negative number.
By default, integer variable declaration int a = 14 means the variable can store signed or negative numbers.
On the other hand, we can use the unsigned qualifier to allow only positive numbers to be stored.