Two Categories of Constants in C
Primary Constants
These are the basic constants we use directly in a C program.
Types of Primary Constants:
-
Integer Constant → Example:
5
,-10
,100
-
Float Constant → Example:
3.14
,-2.5
-
Character Constant → Example:
'A'
,'z'
,'9'
-
String Constant → Example:
"Hello"
,"C programming"
Used for storing direct values in variables like:
char ch = 'A'; // 'A' is a character constant
Secondary Constants
These are user-defined or derived constants.
Types of Secondary Constants:
-
Symbolic Constants → Created using
#define
Example:#define PI 3.14
-
Enumerations (enum) → Set of named integer constants
Example:
In Simple Words:
Category | What it is | Example |
---|---|---|
Primary | Basic constant values | 10 , 'A' , "C" |
Secondary | Defined by the user/programmer | #define , enum |
0 टिप्पणियाँ:
Post a Comment