Types of Constants in C

The type of the constant is the same as the data type of the variables. Following is the list of the types of constants

  • Integer Constant
  • Character Constant
  • Floating Point Constant
  • Double Precision Floating Point Constant
  • Array Constant
  • Structure Constant

We just have to add the const keyword at the start of the variable declaration.

Constants in C

The constants in C are the read-only variables whose values cannot be modified once they are declared in the C program. The type of constant can be an integer constant, a floating pointer constant, a string constant, or a character constant. In C language, the const keyword is used to define the constants.

In this article, we will discuss about the constants in C programming, ways to define constants in C, types of constants in C, their properties and the difference between literals and constants.

Similar Reads

What is a constant in C?

As the name suggests, a constant in C is a variable that cannot be modified once it is declared in the program. We can not make any change in the value of the constant variables after they are defined....

How to Define Constant in C?

We define a constant in C language using the const keyword. Also known as a const type qualifier, the const keyword is placed at the start of the variable declaration to declare that variable as a constant....

Example of Constants in C

C // C program to illustrate constant variable definition #include   int main() {       // defining integer constant using const keyword     const int int_const = 25;       // defining character constant using const keyword     const char char_const = 'A';       // defining float constant using const keyword     const float float_const = 15.66;       printf("Printing value of Integer Constant: %d\n",            int_const);     printf("Printing value of Character Constant: %c\n",            char_const);     printf("Printing value of Float Constant: %f",            float_const);       return 0; }...

Types of Constants in C

...

Properties of Constant in C

The type of the constant is the same as the data type of the variables. Following is the list of the types of constants...

Difference Between Constants and Literals

The important properties of constant variables in C defined using the const keyword are as follows:...

Defining Constant using #define Preprocessor

...

FAQs on C Constants

The constant and literals are often confused as the same. But in C language, they are different entities and have different semantics. The following table lists the differences between the constants and literals in C:...