What is an enum
in C?
a) A user-defined type that assigns names to integer constants
b) A function to manipulate strings
c) A pointer to a function
d) A loop control statement
Answer:
a) A user-defined type that assigns names to integer constants
Explanation:
An enum
(short for enumeration) in C is a user-defined data type that assigns names to integer constants, making the code more readable and easier to maintain. Each name in an enum
corresponds to an integer value, with the default starting at 0 and increasing by 1 for each subsequent name unless explicitly defined.
Enums are useful for representing a set of related constants, such as days of the week, states, or modes, improving code clarity by replacing numeric values with descriptive names.