MCQ Practice
MCQ Practice
8>Choose one of the best options. An element Referring outside array bounds is a ___?
A. Logical error
B. Syntax error
C. Execution time error
D. Both A and C
Ans:d
10>Consecutive group of memory locations contains all same name and same type, is
called as
A. Structures
B. Arrays
C. Classes
D. Functions
Ans: a
11> Which of the header file is used for array type manipulation?
a) <array>
b) <type_traits>
c) <iostream>
d) std namespace
Ans: d
int x = 10;
int* ptr1 = &x;
int** ptr2 = &ptr1;
std::cout << **ptr2;
a) 10 b) &x c) 0 d) Error
Ans: a
24>Which of the following is NOT a valid condition for function overloading in C++?
A. Different number of parameters
B. Different order of parameters
C. Different return type
D. Different parameter types
Ans: c
25>If you define two functions with the same name but different parameter types, which
function will be called when you pass an argument to the function?
A. The first function defined in the program.
B. The second function defined in the program.
C. The function that matches the argument type most closely.
D. The function with the largest number of parameters.
Ans: c
26>In C++, can you overload functions by changing the order of the parameters?
A. Yes, as long as the types of the parameters are the same.
B. Yes, the order of parameters doesn't matter in function overloading.
C. No, changing the order of parameters is not allowed for function overloading.
D. Yes, but only for non-member functions.
Ans: a
30> In C++, what does the new operator return when it fails to allocate memory?
A. nullptr B. 0 C. An exception is thrown D. A system error code
Ans: a
31> How is memory deallocated when using dynamic memory allocation in C++?
A. Automatically by the C++ runtime system
B. By the operating system
C. Using the delete operator or delete[] operator
D. Automatically when the program exits
Ans: c
35>Which of the following is a common issue related to null pointer assignment in C++?
a. It leads to dangling pointers.
b. It leads to dangling pointers.
c. It causes undefined behavior when dereferenced.
d. It increases the program's speed.
Ans: c
39> What is the term for a recursive function that calls itself with modified arguments?
A. Direct recursion
B. Tail recursion
C. Indirect recursion
D. Recursive function call
Ans: a
44>Which type of recursion is typically less memory-efficient due to the need to save
function call state?
A. Direct recursion
B. Tail recursion
C. Indirect recursion
D. All types of recursion use the same amount of memory.
Ans: a
50>In C++, which keyword is used to declare a member of a class that can be accessed
without creating an instance of the class?
A. new
B. static
C. this
D. public
Ans: b
52>In C++, what is the purpose of the "private" access modifier in a class?
A. To make class members accessible from outside the class
B. To restrict access to class members only within the class
C. To make class members accessible from derived classes
D. To create global variables
Ans: b
58>What is the access level of a friend function in relation to the class it is a friend of?
A. Private
B. Protected
C. Public
D. It has no access level
Ans: d
62>In C++, what is the arrow operator (->) primarily used for when working with class
objects?
a.Incrementing object values
b.Accessing class methods
c.Performing logical operations
d.Accessing members of an object through a pointer
Ans: d
63>What is a static member in a C++ class?
A. A member that can only be accessed within the class
B. A member that belongs to a specific instance of the class
C. A member that is shared among all instances of the class
D. A member that is created dynamically at runtime
Ans:c
64>When you declare a data member as "static" in a class, how many copies of that
member are created for all instances of the class?
A. One copy for each instance
B. A separate copy for each instance
C. One shared copy for all instances
D. No copy is created; it remains in the class definition only.
Ans: c