Constant in C means the content whose value does not change at the time of execution of a program.
Definition :
[box]Constant means “Whose value cannot be changed“[/box]
Explanation :
- Initially 5 is Stored in memory location and name x is given to it
- After We are assigning the new value (3) to the same memory location
- This would Overwrite the earlier value 5 since memory location can hold only one value at a time
- The value of ‘3’,’5′ do not change ,so they are constants
- In Short the ‘Values of Constant Does not Change‘.
Different Types of C Constants :
Constant | Type of Value Stored |
---|---|
Integer Constant | Constant which stores integer value |
Floating Constant | Constant which stores float value |
Character Constant | Constant which stores character value |
String Constant | Constant which stores string value |
How to Declare Constant in C :
We can declare constant using const variable. Suppose we need to declare constant of type integer then we can have following two ways to declare it –
const int a = 1; int const a = 1;
above declaration is bit confusing but no need to worry, We can start reading these variables from right to left. i.e
Declaration | Explanation |
---|---|
const int a = 1; | read as “a is an integer which is constant” |
int const a = 1; | read as “a is a constant integer” |
No comments:
Post a Comment