What is an enum in C?
a) A user-defined data type consisting of named integer constants
b) A built-in data type for storing floating-point numbers
c) A function that returns multiple values
d) A variable that stores a string
Answer:
a) A user-defined data type consisting of named integer constants
Explanation:
An enum
(enumeration) in C is a user-defined data type that consists of a set of named integer constants. Enumerations are used to assign names to integral constants to make a program easier to read and maintain. For example, an enum might be used to represent days of the week, where each day is assigned a specific integer value. The syntax for defining an enum involves the enum
keyword followed by the enum name and a list of constant names enclosed in curly braces.
Understanding enums is essential for creating readable and maintainable code, especially when dealing with sets of related constants.