Difference Between Constants and Literals
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:
Constant |
Literals |
---|---|
Constants are variables that cannot be modified once declared. | Literals are the fixed values that define themselves. |
Constants are defined by using the const keyword in C. They store literal values in themselves. | They themselves are the values that are assigned to the variables or constants. |
We can determine the address of constants. | We cannot determine the address of a literal except string literal. |
They are lvalues. | They are rvalues. |
Example: const int c = 20. | Example: 24,15.5, ‘a’, “Geeks”, etc. |
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.