Table of Contents
What are Qualifiers in C?
The Qualifiers are the keywords which are applied to the data types or type modifiers in C.
A qualifier applied to basic data types to alter or modify its sign or size.
There are three types of type qualifiers namely, Size Qualifiers (short, long) and Sign Qualifiers (signed,
unsigned) and the type qualifiers.
Let us see one by one in detail.
1. Size Qualifiers
Size qualifiers are prefixed with basic data types to modify, (either increase or decrease) the number of storage classes in C space allocated to a variable.
The Size qualifier in C language is used to alter the size of a primitive data type. C supports two size qualifiers,
short and long.
The Size qualifier is generally used with an integer type. In addition, double type supports long qualifier.
Rules Regarding size qualifier as per ANSI C standard:
Size of short integer type short int is at least 2 bytes and must be less than or equal to the size of int.
The size of integer int is at least 2 bytes and must be greater than or equal to the size of short.
The size of long integer types long int is at least 4 bytes and must be greater than or equal to the size of int.
i.e., short int <= int <=long int
The precision of long double must be greater than or equal to double. The precision of double must be greater or equal to the precision of float.
i.e. float <= double <= long double
Note: short int may also be abbreviated as short and long int as long. But, there is no abbreviation for long double.
2. Sign Qualifiers
There are two types of Sign Qualifiers i.e., Signed and Unsigned Qualifiers in C.
Sign qualifier in C is used to specify signed nature of integer types.
It specifies whether a variable can hold a negative value or not. Sign qualifiers are used with int and char type.
C supports two sign qualifier, signed and unsigned. A signed qualifier specifies a variable can hold both positive as well as negative integers. An unsigned qualifier specifies a variable will only positive integers.
In a t-bit signed representation of n, the most significant (leftmost) bit is reserved for the sign, “0” means positive, “1” means negative.
The remaining t-1 bits store the (t-l)-bit representation of the magnitude (absolute value) of n (i.e., of |n|).
The 7-bit binary representation of 57 is (0111001)2.
The 8-bit signed magnitude representation of 57 is (00111001)2.
The 8-bit signed magnitude representation of – 57 is (10111001)2.
The use of qualifier signed on integer or character is optional because default declaration int or char assumes signed int or signed char.
An unsigned int has the same memory requirements as an ordinary int. However, in the case of an ordinary int (or a short int or a long int), the leftmost bit is reserved for the sign.
With an unsigned int, all of the bits are used to represent the numerical value. Thus, an unsigned can be approximately twice as large as an ordinary int.
For example, if an ordinary int can vary from -32,768 to +32,767 (which is typical for a 2-byte int), then an unsigned int will be allowed to vary from 0 to 65,535.
The unsigned qualifier can also be applied to other qualified ints, e.g., unsigned short int or unsigned long int we declare long and unsigned to increase range of values of an integer.
The following table shows the applicability of qualifiers to basic types.
3. Type Qualifiers
Type Qualifiers consists of two keywords i.e., const and volatile.
The const keyword is like a normal keyword but the only difference is that once they are defined, their values can’t be changed.
They are also called as literals and their values are fixed.
Syntax: const data_type variable_name
Once the variable is defined as volatile, the program can’t change the value of the variable. These variable values may go on changing by the program.
These type of qualifiers are called as volatile Qualifier in C.
Syntax: volatile data_type variable_name
So in this lesson, we have studied three types of qualifiers in C. These qualifiers are also known as identifiers in C. To learn qualifiers in c in Hindi click here.