Wednesday - September 13, 2023
#C, C++ and C# #Algorithm #Blog #C Program

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 in c, type qualifiers in c geeksforgeeks, how many data type qualifiers in c, what are different types of qualifiers, explain type qualifier, type qualifiers and type modifiers in c, size qualifiers in c, volatile qualifier in c, qualifiers in c geeksforgeeks, ox2fa which type of constant it is, signed and unsigned qualifiers in c, type modifiers in c, restrict qualifier in c, the c language defines fundamental data types, quantifiers c programming, which of the following does not store a sign?, what is a lvalue and rvalue?, type qualifiers in c geeksforgeeks, volatile qualifier in c, restrict type qualifier in c,

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

.