In this tutorial, we will learn about Constants in C. Constants are fixed values. It means after defining a variable we can not change value. These fixed values are also called literals.
Page Contents
Defining Constants in C:
There are two simple ways in C to define constant −
- Using #define preprocessor.
- Using const keyword.
The #define Preprocessor
Please check out the following syntax to define a constants using a #define preprocessor.
#define identifier value
Please check out the following example program.
#include <stdio.h>
#define pi 3.14
int main() {
printf("Pi : %f", pi);
return 0;
}
Output:
Pi : 3.140000
The const keyword:
There is another way to create constants in C is using const keyword. Please check out the following example program.
#include <stdio.h>
int main() {
const float pi = 3.14;
printf("Pi : %f", pi);
return 0;
}
Output:
Pi : 3.140000

Parvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.