Type qualifiers and Program area & circumference
Type Qualifiers in c
Type qualifiers are keywords that you may use in the C programming language to change the characteristics of a variableβs data type. These qualifiers are intended to give more specific instructions on how to access or utilize the variable. In C, const and volatile are the two primary type qualifiers.
Qualifier for Const Type:
When a variable has been initialized, the const qualifier is used to say that its value cannot be altered. It read only a variable.
Declaring a variable as const instructs the compiler that any attempt to change the value of the variable should cause a compilation fault.
Example:
const int x = 10;
x = 20; // This will result in a compilation error because x is const.
qualifier for volatile Type:
The volatile qualifier tells programmers that a variableβs value is subject to change at any point without their intervention.
It is frequently applied to variables that can be affected by outside forces, such as hardware or other program elements that are not expressly within the present codeβs control.
The compiler is told not to cache or optimize the value of a variable when it is designated volatile since it may change suddenly.
Example:
volatile int sensorValue;
// The value of sensorValue may change due to external factors, so it should not be optimized by the compiler.
In some circumstances, type qualifiers are crucial for verifying the accuracy of the code and improving its efficiency. They assist in making your code more reliable and explicit about how variables should be handled by the compiler and the environment where the program is being executed.
List four type qualifiers in c.
- A type qualifier is written along with declaring a variable. If it specifies the additional qualification of the variable. Following are the type qualifiers in C:
- constΒ signedΒ unsignedΒ longΒ shortΒ volatile

Type Qualifiers e.g.Β
- unsigned int K;
- unsigned specify that we want the variable without a sign. It does not allow negative values. So variable βKβ can contain only a positive value.
Creating Constants
Q) Explain with an example of how constants are created.
- A constant is an entity whose value cannot be changed during the execution of the program. In C constants are created using const keyword. Following is the syntax for creating constantly.
- Const data_type constant_name = value;
E.g.
- const int MAX = 30;
- const float PI = 3.14;
Program area & circumference in c
Q) Write a program to accept the radius of the circle. Calculate & display the area & circumference of the circle
#include <stdio.h>
void main()
{
const float PI=3.14;Β /* PI is constant */
int r;
float area, circum;
printf("enter values of radius : ");
scanf("%d", &r);
area = PI*r*r;
circum = 2*PI*r;
printf("nArea = %f", area);
printf("nCircumference = %f", circum);
}
Output:
Enter values of radius: 10
Area = 314.000000
Circumference = 62.800000