C - Enum MCQ Questions
This section focuses on the "Enum" in C programming language. These Multiple Choice Questions (mcq) should be practiced to improve the C programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.
1. Enumeration (or enum) is a ______ data type in C?
A. user defined
B. built-in
C. libary
D. None Of the above
View Answer
Ans : A
Explanation: Enumeration (or enum) is a user defined data type in C. It is mainly used to assign names to integral constants, the names make a program easy to read and maintain.
2. If we do not explicitly assign values to enum names, the compiler by default assigns values to ?
A. null
B. -1
C. 0
D. Garbage
View Answer
Ans : C
Explanation: If we do not explicitly assign values to enum names, the compiler by default assigns values to 0.
3. All enum constants are?
A. Same in their scope
B. unique in their scope
C. contain dupicate value in their scope
D. None of the above
View Answer
Ans : B
Explanation: All enum constants must be unique in their scope.
4. String handling functions such as strcmp(), strcpy() etc can be used with enumerated types.
A. TRUE
B. FALSE
C. May Be
D. Can't Say
View Answer
Ans : B
Explanation: Enumerated types are not strings. Hence it is not possible to use string handling functions with enumerated data types.
5. Pick the incorrect statement with respect to enums.
A. Two enum symbols cannot have the same value
B. Only integer constants are allowed in enums
C. It is not possible to change the value of enum symbols
D. Enum variables are automatically assigned values if no value is specified
View Answer
Ans : A
Explanation: The statement that two enum symbols cannot have the same value is incorrect. Any number of enum symbols can have the same value.
6. Arithmetic operations are not allowed on enumerated constants.
A. TRUE
B. FALSE
C. May Be
D. Can't Say
View Answer
Ans : B
Explanation: Arithmetic operations such as addition, subtraction, multiplication and division are allowed on enumerated constants.
7. What will be output for the following code?
A. error
B. success
C. failure
D. 0
View Answer
Ans : D
Explanation: The code shown above results 0, because in this there is not error in the declaration of these variables in the statement: enum test1 t1,t2;
8. What will be output for the following code?
A. error
B. success
C. failure
D. 0
View Answer
Ans : A
Explanation: The code shown above results in an error, stating : storage size of t1 and t2 unknown. There is an error in the declaration of these variables in the statement: enum test1 t1,t2;
9. What will be output for the following code?
A. Error
B. 5
C. 6
D. 2
View Answer
Ans : A
Explanation: The above code results in an error because it is not possible to modify the value of enum constants. In the above code, we have tried to increment the value of a. This results in an error.
10. What is the correct syntax of enum?
A. enum flag{constant1, constant2, constant3, ....... };
B. enum flag(constant1, constant2, constant3, ....... );
C. enum flag[constant1, constant2, constant3, ....... ];
D. enumflag{constant1, constant2, constant3, ....... };
View Answer
Ans : A
Explanation: The correct syntax of enum is enum flag{constant1, constant2, constant3, ....... };
Also check :
Discussion