1. By default, which access specifier is applied to members of a C++ class?
A) Public
B) Protected
C) Private
D) Internal
Show Explanation
2. In C++, which of the following is not allowed in function overloading?
A) Different parameter types
B) Different number of parameters
C) Different parameter order
D) Different return types
Show Explanation
3. What will be the output of the following code?
int x = 5; cout << ++x + 1;
A) 5
B) 6
C) 7
D) 8
Show Explanation
4. What is a key difference between a struct in C++ and C?
A) C++ structs cannot have functions
B) C++ structs can have different access specifiers
C) C structs support inheritance
D) C structs can have access modifiers
Show Explanation
5. If a member is declared protected in a base class, who can access it?
A) Derived classes
B) Any class
C) Only the base class
D) No one
Show Explanation
6. Which function in C++ is used to dynamically allocate memory?
A) malloc()
B) new
C) alloc()
D) memalloc()
Show Explanation
7. What is the result if a derived class object calls a non-virtual base class function?
A) Error
B) Base class function executes
C) Derived class function executes
D) Undefined behavior
Show Explanation
8. What will be the output of the following code?
int a = 10, b = 5; cout << (a + b);
A) 10
B) 5
C) 15
D) 0
Show Explanation
9. What will be the output of the following code?
static int x = 10; cout << x;
A) 10
B) 0
C) 1
D) Garbage
Show Explanation
10. What is the purpose of the ternary operator?
A) To iterate through loops
B) To convert types
C) To break loops
D) To conditionally select one of two values
Show Explanation
11. What is the purpose of 'endl' in C++?
A) To end the program
B) To insert a newline and flush the output buffer
C) To start a new scope
D) To end a statement
Show Explanation
12. What will happen if you run the following code?
while(1) { cout << "Hello"; }
A) It will print "Hello" once
B) It will print "Hello" twice
C) It will print "Hello" indefinitely
D) It will cause an error
Show Explanation
13. Which of the following statements about C++ references is true?
A) They are pointers
B) They can be NULL
C) They can be reassigned
D) They cannot be reassigned
Show Explanation
14. In C++, what does the 'this' pointer represent?
A) Pointer to the base class
B) Pointer to the current object
C) Pointer to the derived class
D) Pointer to the next object
Show Explanation
15. Which cast is used for safe downcasting in C++?
A) dynamic_cast
B) static_cast
C) const_cast
D) reinterpret_cast
Show Explanation
16. What is the purpose of a virtual function in C++?
A) To define a constant function
B) To define a template function
C) To initialize the base class
D) To allow polymorphic behavior
Show Explanation
17. Given void add(int &sum, int a, int b) { sum = a + b; }
, what does this function do?
A) Returns the sum
B) Does not modify sum
C) Sets sum to the sum of a and b
D) Multiplies sum by a and b
Show Explanation
18. What will happen if you declare int x = 5; int x = 10;
in the same scope in C++?
A) The output will be 10
B) Compile error due to redefinition
C) The output will be 5
D) Undefined behavior
Show Explanation
19. How does C++ handle multiple inheritance with virtual inheritance?
A) Through structs
B) With multiple parent classes
C) By inheriting from base classes
D) By using interfaces
Show Explanation
20. When is the memory allocated for an array automatically released in C++?
A) Upon exiting its scope
B) When a deallocation function is called
C) When memory is full
D) Manually by the programmer
Show Explanation