New:Embedded & IoT Bootcamp
Tutorial 5 of 13 in series

Constants

Constants in C.

Abhishek Sharma 2026-05-22 Programming / C Language / Basics
38%

Constants

In C programming, a constant is a value that cannot be changed during the execution of a program. Constants are used to represent fixed values that are known at compile time and do not change throughout the program. They can be defined using the const keyword or by using preprocessor directives.

Using const keyword

The const keyword is used to declare a variable as a constant. Once a variable is declared as const, its value cannot be modified after it has been initialized. Here’s an example:

#include <stdio.h>
int main() {
    const int MAX_SIZE = 100; // MAX_SIZE is a constant
    printf("The maximum size is: %d\n", MAX_SIZE);
    
    // MAX_SIZE = 200; // This will cause a compilation error because MAX_SIZE is a constant
    
    return 0;
}

In this example, MAX_SIZE is declared as a constant integer with a value of 100. Attempting to change the value of MAX_SIZE will result in a compilation error.

Keep learning

Related tutorials from across the library.

All tutorials
Tutorial2026-05-23

Intro

Understand the fundamentals of the C programming language.

Programming / C Language / Basics

CProgramming Basics
Tutorial2026-05-23

Identifiers

Understand Identifiers in C programming language.

Programming / C Language / Basics

CProgramming Basics
Tutorial2026-05-23

Keywords

Understand Keywords in C programming language.

Programming / C Language / Basics

CProgramming Basics