C Constants
C Constants refer to fixed values whose values remain the same during the whole program. Constants can be of any of the basic data types like an integer constant, a floating constant, a character constant, or a string literal.
Difference between constants and variables
Constants are also like normal variables. But, the only difference is, Constants values can’t be modified by the program once they are defined. While we can change the value of variables.
Types of C Constants:
Here is the list of all types of Constants supported in C language.
Constant | Type of Value Stored |
---|---|
Integer Constant | It stores integer value |
Floating Constant | It stores float value |
Character Constant | It stores character value |
String Constant | It stores string value |
Declaration of Constant in C:
Here is the list which will help you to understand how to declare constants:
Declaration | Explanation |
---|---|
const int a = 10; | read as “a is an integer which is constant” |
int const a = 10; | read as “a is a constant integer” |
Example of C Constant:
Let’s see an Example of C program:
#include
int main()
{
int const x=10;
float const y=20.50;
char const c='w';
x=20; // not allowed
y=10.40; // not allowed
c='v'; // not allowed
return 0;
}
Congratulations! Chapter Finished. Learn more about the similar topics:
Exercises & Assignments |
---|
No Content Found. |
Interview Questions & Answers |
---|
No Content Found. |