What is qualifier or modifier of data type in C programming?


Qualifier or modifier of data type qualifies the primary data types. There are five group of qualifier in C.
Group
Qualifier
Default qualifier
1
auto, register, static, auto
extern, typedef
auto

2
signed, unsigned         
signed
3
short, long              
not short, not long*
4
const
not const*
5
volatile
not volatile*

Note: * indicates C language has not any special keyword for not const, not volatile, not short and long. For example:

int a; Here variable a is not short and not long but an another data type between short and long.
int b; Here variable b is not const variable.

(There is another type qualifier near, far, huge, which qualify only pointer type data type, interrupt is also qualifier of data) We can write all five (one for each group) qualifiers for same data type. If we will not write then it will take its default quantifier. We can write quantifier in any order. We cannot write two qualifier of the same group. For example:

1.
#include<stdio.h>
int main(){
      short unsigned volatile const int a=5;
      printf(“%u”,a)
      return 0;
}

What will be output if you will execute above code?
Output: 5
Explanation: It is right to write:

short unsigned volatile const int a=5;

Since all the qualifiers belong to the different groups.

Group
Qualifier
1
auto (default)
2
unsigned
3
short
4
const
5
volatile

2.
#include<stdio.h>
int main(){
      static auto int a=5;
      a++;
      printf(“%d”,a);
      return 0;
}

What will be output if you will execute above code?

Output: Compiler error
Explanation: Since static and auto both belongs to group one. We cannot write two qualifier of the same group.

4 comments:

Abhishek Singh said...

C99 adds another qualifier, called restrict.

Shekhar Prasad said...

As per my understanding in C the statement "There are five group of qualifier in C" is wrong...
There are only 2 type qualifier "Const and Volatile" . and "signed, unsigned,short, long" are the type modifier. and "auto, register, static, extern, typedef" are the storage class specifier as mentioned in Dennis Richie's "The C Programming Language".

Unknown said...

Thank U

Unknown said...

Yes shekhar you are right...