Constant
Constant is also a value or variable,but only difference is their values cannot be change by the program once they are defined.Constant are also referd a fixed values and constants may be belonging to any of the data type.
Type of Constant :-
S. No. | Constant | Example |
---|---|---|
1. | Integer Constant | |
2. | Real or floating-point Constant | '10.2','26.8','424.9' etc. |
3. | Octal Constant | |
4. | Hexadecimal Constant | |
5. | Character Constant | 'a','b','n' etc. |
6. | String Constant | 'c program','hello world' etc. |
There are two ways to define constant
- Const keyword
- #define Preprocessor
- Const keyword: In C const keyword are used to declare the constants with a specific typeconst type variable = value;
For Example :-#include<stdio.h> void main() { const int height = 100; printf("The value of height is :%d", height); return 0; }
Now the value of height cannot be changed.
Output
The value of height is : 100
If you change the value of height, you will get an error at the compile time.
- #define Preprocessor: The #define Preprocessor directive is used to define constant substitution and #define preprocessor are use with specific type
#define identifier valueLet’s see the example of #define
#include<stdio.h> #define height=100 int main(){ printf("%d",height); }
Output
100
Submit your review | |
The Technical Funda
Average rating: 0 reviews