1. Which of the following is used to include header files in a C++ program?
A) #include
B) #define
C) #header
D) #import
Show Explanation
2. Which of the following is true about a static variable in C++?
A) It is a global variable
B) It is reinitialized with each function call
C) It cannot hold a constant value
D) It retains its value between function calls
Show Explanation
3. Which keyword is used to deallocate memory allocated by 'new' in C++?
A) free
B) delete
C) remove
D) clear
Show Explanation
4. What will be the output of the following code?
for(int i=1; i<4; i++) { cout << i*2; }
A) 246
B) 135
C) 123
D) Error
Show Explanation
5. What does the 'break' statement do in a C++ loop?
A) Skips the current iteration
B) Exits the loop
C) Run for infinite
D) Restarts the loop
Show Explanation
6. What is true about a constructor in C++?
A) It can return an int value
B) It cannot return any value
C) It can return a pointer
D) It can return a boolean
Show Explanation
7. What is the purpose of a virtual function in C++?
A) To allow polymorphic behavior
B) To avoid function overloading
C) To create abstract classes
D) To override operators
Show Explanation
8. Which of the following is the ternary operator in C++?
A) &&
B) ||
C) ??
D) ?:
Show Explanation
9. What is the size of a char in C++?
A) 1 byte
B) 2 bytes
C) 4 bytes
D) System dependent
Show Explanation
10. When is a destructor called in C++?
B) When an object goes out of scope or is deleted
A) At the beginning of a program
C) When a class is defined
D) Manually only
Show Explanation
11. What is true about references in C++?
A) They cannot be null
B) They can be reassigned
C) They are pointers
D) They require dynamic allocation
Show Explanation
12. What does the 'const' keyword do in C++?
A) Allows variable to change
B) Makes variable a pointer
C) Changes variable type
D) Prevents variable from changing
Show Explanation
13. What happens when a derived class object is created in C++?
A) Base class constructor is called first
B) Derived class constructor is called first
C) Only the derived class constructor runs
D) No constructor is called
Show Explanation
14. What will be the output of the following code?
cout << 'Hello' << 'World';
A) HelloWorld
B) Hello World
C) Error
D) WorldHello
Show Explanation
15. Which keyword is used for dynamic memory allocation in C++?
A) malloc
B) new
C) allocate
D) create
Show Explanation
16. What will be the output of the following code?
int i=0; cout << i++ << i;
A) 0 0
B) 0 1
C) 1 1
D) 0 1
Show Explanation
17. Which operator is used to cast away constness in C++?
A) dynamic_cast
B) const_cast
C) reinterpret_cast
D) static_cast
Show Explanation
18. What happens when you call a virtual function from a base class pointer pointing to a derived class object?
A) The derived class version is called
B) The base class version is called
C) No function is called
D) Error occurs
Show Explanation
19. What is true about a pure virtual function in C++?
A) It has a definition
B) It can be called directly
C) It must be overridden in derived classes
D) It is not needed in derived classes
Show Explanation
20. When is the destructor of a class called in C++?
A) When the program starts
B) When the program ends
C) When an object goes out of scope
D) When the object is created
Show Explanation