Constants in C are fixed values that do not change during program execution. They can be of various types like integer, floating-point, or character.
Declaring Constants:
- Using
#define
(Preprocessor Directive): - Using
const
Keyword:
Types of Constants:
- Integer Constants:
10
,0xA
(Hexadecimal). - Floating-point Constants:
3.14
,2.718
. - Character Constants:
'A'
,'@'
. - String Constants:
"Hello"
.
Example:
Constants ensure data integrity by preventing unintended modifications.