Getting Started With C

Declaring Variable as Constant

In C, you can declare a variable as a constant using the const keyword. Once a variable is declared as const, its value cannot be changed throughout the program. Here's an example:

Program.c


In this example, num is declared as a constant integer with the value 5. If you try to change the value of num later in the program (e.g., num = 10;), the compiler will generate an error because num is declared as a constant.

Resources :

Featured
Special title treatment

With supporting text below as a natural lead-in to additional content.

Q1. 1. What is the primary advantage of declaring variables as constants in C?

Q2. How is a constant variable declared in C?