Const keyword is used in C language to declare a variable
constant. It declare a variable as a constant that is the value of the
variables does not change during the execution of a program.
We can create a variable as a constant with the help of keyword const at the time of initialization. The value of the constant variable is declared at the time of initialization.
We can create a variable as a constant with the help of keyword const at the time of initialization. The value of the constant variable is declared at the time of initialization.
Syntax:
const datatype variable_name = value;
It can not be modified.
Ex:
Program: Calculate the
area of a circle
#include<stdio.h>
#include<conio.h>
void
main()
{
const
float PI = 3.14; //PI declare as a constant variable
float
area, radius;
printf(“Enter
Radius to calculate the area: “);
scanf(“%f”,&radius);
area
= PI * radius * radius;
printf(“Area
of Circle = %f”,area);
getch();
}
Output:
Enter
Radius to calculate the area: 5
No comments:
Post a Comment