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 results-driven tech professional with 8+ years of experience in web and mobile development, leadership, and emerging technologies.
After completing his Master’s in Computer Applications (MCA), he began his journey as a programming mentor, guiding 100+ students and helping them build strong foundations in coding. In 2019, he founded Owlbuddy.com, a platform dedicated to providing free, high-quality programming tutorials for aspiring developers.
He then transitioned into a full-time programmer, where his hands-on expertise and problem-solving skills led him to grow into a Team Lead and Technical Project Manager, successfully delivering scalable web and mobile solutions. Today, he works with advanced technologies such as AI systems, RAG architectures, and modern digital solutions, while also collaborating through a strategic partnership with Technobae (UK) to build next-generation products.
