Write a c program using constants

 Constants in c  :



Constants declaration in c :

Constants in c is a variable that cannot modified through the code .

1 . Using const keyword

2 . Using #define keyword 

1.using const keyword 

Syntax : const datatype variable =

Example : const float pi= 3.14

2. Using #define 

The #define preprocessor is also used to define constant.

#define datatype variable 

Write a c program using constants

//Write a c program to demonstrate using constant keyword. Using const

#include<stdio.h>

int main()

{

const float pi=3.14;

printf("the value of pi is %f",pi);

}

//Write a c program to demonstrate using constant keyword. Using #define

#include<stdio.h>

#define pi 3.14

int main()

{

printf("the value of pi is %f",pi);

}

Post a Comment

Please Select Embedded Mode To Show The Comment System.*

Previous Post Next Post