Explain a Type Qualifiers
Type Qualifiers
Q) List four type qualifiers.
- A type qualifier is written along with declaring a variable. If specifies the additional qualification of the variable. Following are the type qualifiers in C:
- const  signed  unsigned  long  short  volatile
Image Source ~ Crafted With ©Ishwaranand – 2020 ~ Image by ©Ishwaranand |
For 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;
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
Last updated on Sunday - May 21st, 2023