Constants in C

It is an variable whose value can not be changed at the execution time of program. In general constant can be used to represent as fixed values in a C program.


Types of Constants in C

If any single character (alphabet or numeric or special symbol) is enclosed between single qotes ' ' known as single character constant.

If set of characters are enclosed between double cotes " " known as string character constant.

How to create constant in C

There are two ways to define constant in C programming.

1) const keyword

2) #define preprocessor

1) C const keyword

The const keyword is used to define constant in C programming.


const float PI=3.14;

Example of making constant using const keyword

  fig

2) C #define preprocessor

The #define preprocessor is also used to define constant

Let's see an example of #define to define a constant.


#include   
#define PI 3.14  
void main() {  
   printf("%f",PI);  
getch();
}  
3.140000
woman avatar