Computer Fundamentals for Placements – C++ MCQs with Answers
Q. 1 Which of the following is the correct way to include an iostream header file in C++?
Check Solution
Ans: A
In C++, standard library headers are included using angle brackets (< >), while user-defined headers are included using double quotes ( “).”
Q. 2 Which C++ feature allows a function to be called with different number of arguments?
Check Solution
Ans: A
Function overloading is a form of polymorphism where multiple functions can have the same name but different parameters (either in number or type), allowing the same function name to be used for different tasks.
Q. 3 What is the purpose of the friend keyword in C++?
Check Solution
Ans: A
A friend function or friend class can access the private and protected members of the class in which it is declared as a friend, breaking the normal rules of encapsulation.
Q. 4 What is the default access specifier for members of a class in C++?
Check Solution
Ans: B
By default, all members of a C++ class are private. In contrast, members of a struct are public by default.
Q. 5 Which of the following is an example of a scope resolution operator?
Check Solution
Ans: C
The scope resolution operator (::) is used to define a function outside a class or to access a class’s static members. It specifies the class or namespace to which a member belongs.
Q. 6 In C++, what is a virtual function?
Check Solution
Ans: C
A virtual function is a member function that is declared within a base class and is meant to be overridden in a derived class. It is a key mechanism for achieving runtime polymorphism.
Q. 7 What is the difference between a class and a struct in C++?
Check Solution
Ans: A
The primary difference is the default access level for members. In a struct, members are public by default, whereas in a class, they are private by default.
Q. 8 Which of these is a correct way to create a dynamic object in C++?
Check Solution
Ans: B
The new keyword is used to allocate memory on the heap and create a dynamic object. It returns a pointer to the newly created object, which should be stored in a pointer variable.
Q. 9 What is the primary function of a destructor in a C++ class?
Check Solution
Ans: C
A destructor is a special member function that is called automatically when an object is about to be destroyed. Its main purpose is to clean up resources, such as dynamically allocated memory, before the object is removed from memory.
Q. 10 Which of the following is a key feature of C++ that is not present in C?
Check Solution
Ans: C
While both C and C++ have pointers, dynamic memory allocation, and preprocessor directives, the Standard Template Library (STL) is a core part of the C++ standard library. It provides a collection of generic classes and functions like containers (vector, list), iterators, and algorithms.
Next Topic: Computer Network MCQs with Answers for Placements
Practice Aptitude Questions for Placements
Crack Placement Tests: Faster & Smarter
Adaptive Practice | Real Time Insights | Resume your Progress
