(b) Briefly explain two categories of constants in C.

, , No Comments

 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:

c
int a = 10; // 10 is an integer constant 

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:

    c
    enum day { SUN, MON, TUE };

In Simple Words:

CategoryWhat it isExample
PrimaryBasic constant values10, 'A', "C"
Secondary Defined by the user/programmer#define, enum



0 टिप्पणियाँ:

Post a Comment