1. What does typedef do in C++?
(A) Creates a new data type
(B) Creates an alias for an existing data type
(C) Allocates memory
(D) Declares a constant
2. Which of the following is a correct syntax for typedef?
(A) typedef int Integer;
(B) int typedef Integer;
(C) typedef Integer int;
(D) Integer typedef int;
3. After typedef int Integer;, which statement is correct?
(A) Integer x = 5;
(B) int x = Integer;
(C) typedef x = Integer;
(D) None
4. Which of the following can be used with typedef?
(A) Structs
(B) Pointers
(C) Arrays
(D) All of the above
5. What is the purpose of enum in C++?
(A) Define integer constants
(B) Define a group of named constants
(C) Allocate memory
(D) Create dynamic arrays
6. Which of the following is a correct enum declaration?
(A) enum Color { Red, Green, Blue };
(B) Color enum { Red, Green, Blue };
(C) enum { Color = Red, Green, Blue };
(D) enum Color = { Red, Green, Blue };
7. What is the default value of the first enumerator in an enum?
(A) 0
(B) 1
(C) Undefined
(D) Depends on compiler
8. Can you assign specific values to enum members?
(A) Yes, e.g., enum Color { Red=5, Green=10 };
(B) No, values are always sequential
(C) Only the first member can have a value
(D) Only the last member can have a value
9. What will be the value of Blue in enum Color { Red=2, Green, Blue };?
(A) 2
(B) 3
(C) 4
(D) 5
10. How do you declare a variable of an enum type?
(A) Color c;
(B) enum Color c;
(C) Both A and B
(D) c:Color;
11. Can typedef be used with enum?
(A) Yes, e.g., typedef enum Color ColorType;
(B) No
(C) Only with integer enums
(D) Only in C
12. What is output?
enum Color { Red, Green, Blue };
Color c = Green;
cout << c;
(A) Green
(B) 1
(C) 2
(D) Compile error
13. Can enum members have negative values?
(A) Yes
(B) No
(C) Only first member
(D) Only last member
14. Can enum values be used in switch statements?
(A) Yes
(B) No
(C) Only integers
(D) Only chars
15. Can typedef create alias for pointer types?
(A) Yes, e.g., typedef int* IntPtr;
(B) No
(C) Only arrays
(D) Only structs
16. Can you declare multiple typedefs in one line?
(A) Yes, e.g., typedef int Integer, *IntPtr;
(B) No
(C) Only one per line
(D) Only for structs
17. Can enums be forward-declared?
(A) Yes
(B) No
(C) Only in C++11 and later
(D) Only with typedef
18. What is output?
enum Numbers { One=1, Two, Three };
cout << Three;
(A) 1
(B) 2
(C) 3
(D) Compile error
19. Can enum type variables be assigned integer values directly?
(A) Yes, e.g., Color c = 2;
(B) No, only enumerators allowed
(C) Only first enumerator
(D) Only after type casting
20. Which of the following is true about typedef?
(A) Can create aliases for complex types
(B) Does not create a new type
(C) Improves code readability
(D) All of the above
21. What will be the value of Yellow in enum Color { Red=1, Green=3, Blue, Yellow=7, Pink };?
(A) 4
(B) 5
(C) 7
(D) 8
22. Can typedef be used with arrays?
(A) Yes, e.g., typedef int IntArray[10];
(B) No
(C) Only dynamic arrays
(D) Only structs
23. Can enum values overlap?
(A) Yes, e.g., enum { A=1, B=1 };
(B) No
(C) Only first member
(D) Only last member
24. Can typedef be used with function pointers?
(A) No
(B) Yes
(C) Only structs
(D) Only arrays
25. Can enum type be used as a function argument?
(A) Only typedef enum
(B) No
(C) Only const enum
(D) Yes
26. Which of the following is correct typedef for pointer to function returning int?
(A) typedef (FuncPtr) int(int);
(B) typedef int FuncPtr(int);
(C) typedef int (FuncPtr)(int);
(D) typedef FuncPtr int()(int);
27. Can enums be scoped in C++11 using enum class?
(A) Yes
(B) No
(C) Only integer enums
(D) Only typedef enums
28. Which is true about enum class in C++11?
(A) Strongly typed
(B) Scoped
(C) Does not implicitly convert to int
(D) All of the above
29. Can typedef rename a struct?
(A) No
(B) Yes, e.g., typedef struct Person P;
(C) Only enum
(D) Only pointer
30. Which of the following statements about typedef and enum is true?
(A) typedef improves code readability
(B) enum groups related constants
(C) typedef can alias pointers, arrays, structs, functions
(D) All of the above