Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

51.

Which option is best to eliminate the memory problem?(a) use smart pointers(b) use raw pointers(c) use virtual destructor(d) use smart pointers & virtual destructorThis question was addressed to me in an interview.This key question is from Large Objects in chapter Source Files, Classes and Operator Overloading in C++ of C++

Answer» RIGHT OPTION is (d) USE smart POINTERS & virtual destructor

Explanation: Virtual destructor means is that the object is destructed in reverse order in which it was constructed and the smart pointer will delete the object from memory when the object goes out of scope.
52.

Which rule will not affect the friend function?(a) private and protected members of a class cannot be accessed from outside(b) private and protected member can be accessed anywhere(c) protected member can be accessed anywhere(d) private member can be accessed anywhereThis question was posed to me by my school principal while I was bunking the class.Enquiry is from Friends topic in section Source Files, Classes and Operator Overloading in C++ of C++

Answer»

Right OPTION is (a) private and protected members of a CLASS cannot be ACCESSED from outside

To explain I would SAY: Friend is used to access private and protected members of a class from outside the same class.

53.

How to access the object in the class?(a) scope resolution operator(b) ternary operator(c) direct member access operator(d) resolution operatorThis question was posed to me at a job interview.This intriguing question originated from Objects topic in chapter Source Files, Classes and Operator Overloading in C++ of C++

Answer»

The CORRECT option is (C) DIRECT member access operator

The best EXPLANATION: Objects in the method can be ACCESSED using direct member access operator which is (.).

54.

Which is used to use a function from one source file to another?(a) code(b) declaration(c) prototype(d) variableI have been asked this question in my homework.Question is taken from Linkage topic in chapter Source Files, Classes and Operator Overloading in C++ of C++

Answer» RIGHT OPTION is (c) PROTOTYPE

Explanation: By defining a function’s prototype in another file means, we can inherit all the FEATURES from the SOURCE function.
55.

In Linux, how do the heaps and stacks are managed?(a) ram(b) secondary memory(c) virtual memory(d) static memoryI got this question in an internship interview.This question is from Large Objects in portion Source Files, Classes and Operator Overloading in C++ of C++

Answer»

The correct OPTION is (C) virtual memory

Explanation: In virtual memory, We can KEEP track of all the objects and access them much FASTER than any ANOTHER.

56.

Which container in c++ will take large objects?(a) string(b) class(c) vector(d) string & classI have been asked this question at a job interview.Origin of the question is Large Objects topic in chapter Source Files, Classes and Operator Overloading in C++ of C++

Answer» CORRECT ANSWER is (c) vector

To explain I would say: Because the vector is mainly used to STORE LARGE objects for the game programming and other operations etc.
57.

Which keyword is used to declare the friend function?(a) firend(b) friend(c) classfriend(d) myfriendThe question was asked in an online interview.This interesting question is from Friends in division Source Files, Classes and Operator Overloading in C++ of C++

Answer»

Right OPTION is (B) FRIEND

The explanation: friend keyword is used to DECLARE a friend function in C++.

58.

In case of non-static member functions how many maximum object arguments a binary operator overloaded function can take?(a) 1(b) 2(c) 3(d) 0I have been asked this question in final exam.My doubt is from Operator Overloading in portion Source Files, Classes and Operator Overloading in C++ of C++

Answer»

The CORRECT answer is (a) 1

Explanation: In the case of non-static member functions binary operator OVERLOADED function should TAKE MAXIMUM ONE object argument only.

59.

Which category of data type a class belongs to?(a) Fundamental data type(b) Derived data type(c) User defined derived data type(d) Atomic data typeThis question was addressed to me in homework.The query is from Classes in portion Source Files, Classes and Operator Overloading in C++ of C++

Answer»

The correct choice is (c) User defined DERIVED data type

The explanation: Fundamental/Atomic data type INCLUDES int, char, float, double and void. Derived data type includes arrays, pointers, references, FUNCTION and constants. User defined derived data type includes class, structure, UNION and ENUMERATION.

60.

Which of the following is a valid class declaration?(a) class A { int x; };(b) class B { }(c) public class A { }(d) object A { int x; };This question was posed to me in a national level competition.This key question is from Classes topic in chapter Source Files, Classes and Operator Overloading in C++ of C++

Answer»

The CORRECT OPTION is (a) class A { int x; };

For explanation: A class declaration TERMINATES with SEMICOLON and starts with class keyword. only option (a) FOLLOWS these rules therefore class A { int x; }; is correct.

61.

Which of the following header file does not exist?(a) (b) (c) (d) I got this question in an online quiz.I would like to ask this question from Header Files Usage topic in chapter Source Files, Classes and Operator Overloading in C++ of C++

Answer»

The CORRECT ANSWER is (C)

EASY explanation - There is no such HEADER file in C++.

62.

What is string objects in C++?(a) Stream of alphabets(b) A stream of well-defined characters(c) Stream of characters(d) A stream of characters terminated by \0I have been asked this question in an interview.The doubt is from String topic in portion Source Files, Classes and Operator Overloading in C++ of C++

Answer» CORRECT answer is (b) A STREAM of well-defined characters

To explain: String is defined as STREAMS of characters, not necessarily terminated by \0. Also, a string can contain characters other than ALPHABETS.
63.

What does the dereference operator will return?(a) rvalue equivalent to the value at the pointer address(b) lvalue equivalent to the value at the pointer address(c) it will return nothing(d) it will return boolean valuesThe question was posed to me in exam.Asked question is from Dereferencing topic in chapter Source Files, Classes and Operator Overloading in C++ of C++

Answer»

Right choice is (B) LVALUE EQUIVALENT to the VALUE at the pointer address

Easy explanation - It operates on a pointer variable, and returns an l-value equivalent to the value at the pointer address.

64.

How are types therein user-defined conversion?(a) 1(b) 2(c) 3(d) 4I got this question at a job interview.This intriguing question originated from Conversion Operators in division Source Files, Classes and Operator Overloading in C++ of C++

Answer» CORRECT choice is (b) 2

The EXPLANATION is: There are TWO types of user-defined conversions. They are conversion by the CONSTRUCTOR, Conversion functions.
65.

Which of the following operator cannot be overloaded?(a) +(b) ?:(c) –(d) %The question was asked in semester exam.My question comes from Operator Overloading in chapter Source Files, Classes and Operator Overloading in C++ of C++

Answer» CORRECT choice is (B) ?:

To explain I would say: ?:, :: and . cannot be overloaded +, -, % can be overloaded.
66.

What is the syntax of user-defined data types?(a) typedef ExistingDataType NameByUser(b) typedef NameByUser ExistingDataType(c) def NameByUser ExistingDataType(d) def NameByUser ExistingDataThe question was asked in a national level competition.This interesting question is from User Defined Types in chapter Source Files, Classes and Operator Overloading in C++ of C++

Answer»

Correct option is (a) TYPEDEF EXISTINGDATATYPE NameByUser

The EXPLANATION is: correct syntax is typedef ExistingDataType NameByUser.

typedef int INT; (typedef existing-datatype New-name;).

67.

Pick the incorrect statement about inline functions in C++?(a) They reduce function call overheads(b) These functions are inserted/substituted at the point of call(c) Saves overhead of a return call from a function(d) They are generally very large and complicated functionI have been asked this question in a national level competition.This key question is from Classes in portion Source Files, Classes and Operator Overloading in C++ of C++

Answer»

Correct answer is (d) They are generally very large and complicated function

Easy explanation - Inline are FUNCTIONS that are expanded when it is called. The whole code of the inline function gets inserted/substituted at the point of call. In this, they help in REDUCING the function call overheads. Also they save OVERHEAD of a return call from a function. Inline functions are generally KEPT SMALL.

68.

What is Character-Array?(a) array of alphabets(b) array of well-defined characters(c) array of characters(d) array of characters terminated by \0This question was posed to me in quiz.This question is from String in division Source Files, Classes and Operator Overloading in C++ of C++

Answer» CORRECT ANSWER is (c) array of characters

The best explanation: Character-Array is DEFINED as an array of characters, not NECESSARILY terminated by \0. Also, a character-array can CONTAIN characters other than alphabets.
69.

How many types are there in increment/decrement operator?(a) 1(b) 2(c) 3(d) 4I got this question in an internship interview.My doubt stems from Increment and Decrement in chapter Source Files, Classes and Operator Overloading in C++ of C++

Answer»

Right answer is (b) 2

To EXPLAIN: There are two TYPES of increment/decrement. They are postfix and PREFIX.

70.

Why we use the “dynamic_cast” type conversion?(a) result of the type conversion is a valid(b) to be used in low memory(c) result of the type conversion is an invalid(d) it is used for storageI got this question by my college director while I was bunking the class.The question is from Conversion Operators in division Source Files, Classes and Operator Overloading in C++ of C++

Answer»

Right answer is (a) RESULT of the type conversion is a valid

For explanation: It is USED to CHECK that OPERATORS and operands are compatible after conversion.

71.

What is the return type of the conversion operator?(a) void(b) int(c) float(d) no return typeThe question was posed to me in an interview for job.Enquiry is from Conversion Operators in division Source Files, Classes and Operator Overloading in C++ of C++

Answer»

The CORRECT option is (d) no RETURN TYPE

The best explanation: CONVERSION operator doesn’t have any return type not even void.

72.

Where does the object is created?(a) class(b) constructor(c) destructor(d) attributesI got this question during an interview.Question is taken from Objects in section Source Files, Classes and Operator Overloading in C++ of C++

Answer»

Correct CHOICE is (a) CLASS

To EXPLAIN: In class, only all the listed ITEMS except class will be DECLARED.

73.

What does a mutable member of a class mean?(a) A member that can never be changed(b) A member that can be updated only if it not a member of constant object(c) A member that can be updated even if it a member of constant object(d) A member that is global throughout the classI have been asked this question during an interview.This key question is from Classes in division Source Files, Classes and Operator Overloading in C++ of C++

Answer» CORRECT answer is (C) A MEMBER that can be updated even if it a member of CONSTANT OBJECT

For explanation: Mutable members are those which can be updated even if it a member of a constant object. You can change their value even from a constant member function of that class.
74.

Which operator a pointer object of a class uses to access its data members and member functions?(a) .(b) ->(c) :(d) ::I have been asked this question during an interview.My query is from Classes topic in division Source Files, Classes and Operator Overloading in C++ of C++

Answer»

Correct option is (B) ->

For explanation: ->(ARROW operator) is USED by a pointer object to ACCESS members of its class.

75.

What is the default type of linkage that is available for identifiers?(a) internal(b) external(c) no linkage(d) single linkageThe question was asked during an online interview.The query is from Linkage topic in portion Source Files, Classes and Operator Overloading in C++ of C++

Answer»

The correct OPTION is (b) EXTERNAL

Explanation: external is the default type of LINKAGE that is available for identifiers.

76.

Which header file is used to include the string object functions in C++?(a) #include (b) #include (c) #include (d) #include I got this question in an international level competition.My question is taken from String topic in section Source Files, Classes and Operator Overloading in C++ of C++

Answer»

The CORRECT option is (C) #include

The explanation: #include header file is used as it CONTAINS all the string OBJECT functions.

77.

What do we need to do to pointer for overloading the subscript operator?(a) reference pointer(b) dereference pointer(c) store it in heap(d) memory locatorThe question was asked in an interview for internship.Question is from Subscripting topic in division Source Files, Classes and Operator Overloading in C++ of C++

Answer» RIGHT OPTION is (b) dereference pointer

Best explanation: If you have a pointer to an object of some class type that OVERLOADS the subscript operator, you have to dereference that pointer in ORDER to FREE the memory.
78.

Which of the following is correct about friend functions?(a) Friend functions use the dot operator to access members of a class using class objects(b) Friend functions can be private or public(c) Friend cannot access the members of the class directly(d) All of the mentionedThis question was posed to me during a job interview.The above asked question is from Friend Function topic in section Source Files, Classes and Operator Overloading in C++ of C++

Answer»

Correct option is (d) All of the mentioned

To EXPLAIN I would SAY: Friend function can be declared either in private or public PART of the class. A friend function cannot ACCESS the members of the class directly. They use the dot membership operator with a member name.

79.

How many parameters does a conversion operator may take?(a) 0(b) 1(c) 2(d) as many as possibleThe question was asked in a national level competition.The question is from Conversion Operators in chapter Source Files, Classes and Operator Overloading in C++ of C++

Answer»

The CORRECT CHOICE is (a) 0

Explanation: 0 parameters does a CONVERSION operator will TAKE.

80.

Pick out the correct statement.(a) Increment operator ++ adds 1 to its operand(b) Increment operator ++ adds 2 to its operand(c) Decrement operator ++ subtracts 1 to its operand(d) Decrement operator ++ subtracts 3 to its operandI got this question by my college director while I was bunking the class.Asked question is from Increment and Decrement topic in section Source Files, Classes and Operator Overloading in C++ of C++

Answer»

Right option is (a) INCREMENT OPERATOR ++ ADDS 1 to its operand

For EXPLANATION: Increment operator are used to increase the values of any integer variable by 1.

81.

How many real types are there in complex numbers?(a) 1(b) 2(c) 3(d) 4I had been asked this question by my school principal while I was bunking the class.Asked question is from Complex Number Type in division Source Files, Classes and Operator Overloading in C++ of C++

Answer»

The correct answer is (c) 3

To EXPLAIN I would say: There are THREE real types in complex numbers. They are FLOAT complex, DOUBLE complex, long double complex.

82.

Pick out the compound assignment statement.(a) a = a – 5(b) a = a / b(c) a -= 5(d) a = a + 5This question was posed to me in final exam.This question is from Essential Operators in section Source Files, Classes and Operator Overloading in C++ of C++

Answer»

The correct answer is (c) a -= 5

To explain: When we want to modify the value of a variable by performing an operation on the value CURRENTLY stored,We will USE compound assignment statement. In this option, a -=5 is EQUAL to a = a-5.

83.

Which is used to define the member of a class externally?(a) :(b) ::(c) #(d) !!$This question was addressed to me in final exam.My doubt stems from Classes in chapter Source Files, Classes and Operator Overloading in C++ of C++

Answer»

The correct OPTION is (b) ::

To EXPLAIN: :: OPERATOR is used to DEFINE the body of any class FUNCTION outside the class.

84.

How to stop your program from eating so much ram?(a) Find a way to work with the data one at a time(b) Declare it in program memory, instead of on the stack(c) Use the hard drive, instead of RAM(d) All of the mentionedI had been asked this question in my homework.The question is from Large Objects topic in section Source Files, Classes and Operator Overloading in C++ of C++

Answer» RIGHT answer is (d) All of the mentioned

Explanation: Some of the ways to STOP the program by consuming more ram. They are

i) Find a way to work with the DATA one at a time

ii) Declare it in program MEMORY, instead of on the stack

iii) Use the hard DRIVE, instead of RAM
85.

To use internal linkage we have to use which keyword?(a) static(b) extern(c) static or extern(d) publicI got this question during a job interview.Asked question is from Linkage in division Source Files, Classes and Operator Overloading in C++ of C++

Answer»

The correct choice is (a) STATIC

The best I can EXPLAIN: static keyword is used for internal LINKAGE.

86.

What is a friend function in C++?(a) A function which can access all the private, protected and public members of a class(b) A function which is not allowed to access any member of any class(c) A function which is allowed to access public and protected members of a class(d) A function which is allowed to access only public members of a classThis question was posed to me during an interview for a job.This interesting question is from Friend Function in section Source Files, Classes and Operator Overloading in C++ of C++

Answer»

The CORRECT answer is (a) A function which can access all the private, protected and public MEMBERS of a CLASS

To explain I WOULD say: FRIEND function in C++ is a function which can access all the private, protected and public members of a class.

87.

What does a class in C++ holds?(a) data(b) functions(c) both data & functions(d) arraysThis question was posed to me in quiz.My question comes from Classes topic in section Source Files, Classes and Operator Overloading in C++ of C++

Answer»

Right answer is (C) both data & functions

The EXPLANATION: The classes in C++ encapsulates(i.e. PUT together) all the data and functions related to them for manipulation.