- Which operator is used to define a reference variable in C++?
a) *
b) &
c) ->
d) %
Answer: b) &
- Which function is used to allocate an array dynamically in C++?
a) malloc()
b) new[]
c) calloc()
d) allocate()
Answer: b) new[]
- What happens if a pointer is deleted twice in C++?
a) Compilation error
b) Runtime error (undefined behavior)
c) Pointer is reset to NULL
d) No effect
Answer: b) Runtime error (undefined behavior)
- Which keyword is used to define an abstract class in C++?
a) abstract
b) virtual
c) pure
d) None of the above
Answer: b) virtual
- Which C++ function is used to copy a string?
a) strcpy()
b) strcat()
c) copy()
d) strcopy()
Answer: a) strcpy()
- Which of the following is an example of an implicit type conversion in C++?
a) Type casting using (int)
b) Conversion done by the compiler
c) Usingstatic_cast<>
d) Usingdynamic_cast<>
Answer: b) Conversion done by the compiler
- Which of the following is used to handle exceptions in C++?
a) try, catch, throw
b) error(), catch()
c) try(), throw(), finally()
d) exception(), handle()
Answer: a) try, catch, throw
- Which keyword is used to return control to the calling function in C++?
a) break
b) continue
c) return
d) goto
Answer: c) return
- Which STL container follows Last-In-First-Out (LIFO) order?
a) queue
b) deque
c) stack
d) vector
Answer: c) stack
- What does
std::endl
do in C++?
a) Moves to the next line
b) Ends the program
c) Clears the screen
d) Terminates the execution
Answer: a) Moves to the next line
- Which of the following is NOT a fundamental C++ data type?
a) int
b) double
c) boolean
d) float
Answer: c) boolean
- Which feature of C++ allows a class to have multiple functions with the same name but different parameters?
a) Function overriding
b) Function overloading
c) Operator overloading
d) Encapsulation
Answer: b) Function overloading
- Which operator is used to define scope in C++?
a) ::
b) .
c) ->
d) :
Answer: a) ::
- Which header file is required to use the
vector
container in C++?
a) vector.h
b) vectors
c) stdio.h
d) vector
Answer: d) vector
- Which of the following is NOT a valid C++ control structure?
a) for
b) while
c) loop
d) do-while
Answer: c) loop
- Which function is automatically called when an object is destroyed in C++?
a) Constructor
b) Destructor
c) Finalizer
d) Cleanup
Answer: b) Destructor
- Which of the following is an invalid variable name in C++?
a) my_variable
b) _myVariable
c) 2ndVariable
d) myVariable2
Answer: c) 2ndVariable
- Which of the following statements about
inline
functions in C++ is true?
a) They improve performance by reducing function call overhead
b) They are always compiled as inline
c) They can only be used for constructors
d) They must be declared outside a class
Answer: a) They improve performance by reducing function call overhead
- Which C++ function is used to get the length of a string object?
a) size()
b) length()
c) strlen()
d) Both a and b
Answer: d) Both a and b
- Which of the following statements is true about multiple inheritance in C++?
a) A class can inherit from only one class
b) A class can inherit from multiple classes
c) Multiple inheritance is not supported in C++
d) Multiple inheritance is allowed but cannot have member functions
Answer: b) A class can inherit from multiple classes
- Which operator is used to check if two values are equal in C++?
a) =
b) ==
c) :=
d) !=
Answer: b) ==
- Which of the following is NOT a property of an object-oriented programming language?
a) Encapsulation
b) Abstraction
c) Compilation
d) Polymorphism
Answer: c) Compilation
- Which of the following correctly initializes a reference in C++?
a) int x = 10; int &y = x;
b) int x = 10; int *y = x;
c) int x = 10; int y = &x;
d) int x = 10; int y = *x;
Answer: a) int x = 10; int &y = x;
- Which function is used to open a file in C++?
a) fopen()
b) open()
c) file()
d) openfile()
Answer: b) open()
- What is the purpose of the
this
pointer in C++?
a) It refers to the calling object
b) It creates a new object
c) It destroys the current object
d) It is used for inheritance
Answer: a) It refers to the calling object