C – Type Qualifiers
Types of C type qualifiers:
There are two types of qualifiers available in C language. They are,
1. const
2. volatile
1. const keyword:
- Constants are also like normal variables. But, only difference is, their values can’t be modified by the program once they are defined.
- They refer to fixed values. They are also called as literals.
- They may be belonging to any of the data type.
• Syntax: const data_type variable_name;
1. Example program using const keyword in C:
#include <stdio.h>
void main()
{
const int height = 100;
const float number = 3.14;
printf(“value of height :%d \n”, height );
printf(“value of number : %f \n”, number );
}
2. volatile keyword:
• When a variable is defined as volatile, the program may not change the value of the variable explicitly.
• But, these variable values might keep on changing without any explicit assignment by the program. These types of qualifiers are called volatile.
• For example, if global variable’s address is passed to clock routine of the operating system to store the system time, the value in this address keep on changing without any assignment by the program. These variables are named as volatile variable.
• Syntax:
volatile data_type variable_name; (or) volatile data_type *variable_name;
1. Example program using const keyword in C:
#include <stdio.h>
void main()
{
const int height = 100;
const float number = 3.14;
printf(“value of height :%d \n”, height );
printf(“value of number : %f \n”, number );
}
No comments:
Post a Comment