• +91 9723535972
  • info@interviewmaterial.com

CPlusPlus Interview Questions and Answers

CPlusPlus Interview Questions and Answers

Question - 41 : - What is friend function?

Answer - 41 : - As the name suggests, the function acts as a friend to a class. As a friend of a class, it can access its private and protected members. A friend function is not a member of the class. But it must be listed in the class definition.

Question - 42 : - Which recursive sorting technique always makes recursive calls to sort subarrays that are about half size of the original array?

Answer - 42 : - Mergesort always makes recursive calls to sort subarrays that are about half size of the original array, resulting in O(n log n) time.

Question - 43 : - What is abstraction?

Answer - 43 : - Abstraction is of the process of hiding unwanted details from the user.

Question - 44 : - What are virtual functions?

Answer - 44 : - A virtual function allows derived classes to replace the implementation provided by the base class. The compiler makes sure the replacement is always called whenever the object in question is actually of the derived class, even if the object is accessed by a base pointer rather than a derived pointer. This allows algorithms in the base class to be replaced in the derived class, even if users don't know about the derived class.

Question - 45 : - What is the difference between an external iterator and an internal iterator? Describe an advantage of an external iterator.

Answer - 45 : - An internal iterator is implemented with member functions of the class that has items to step through. .An external iterator is implemented as a separate class that can be "attach" to the object that has items to step through. .An external iterator has the advantage that many difference iterators can be active simultaneously on the same object.

Question - 46 : - What is a scope resolution operator?

Answer - 46 : - A scope resolution operator (::), can be used to define the member functions of a class outside the class.

Question - 47 : - What do you mean by pure virtual functions?

Answer - 47 : - A pure virtual member function is a member function that the base class forces derived classes to provide. Normally these member functions have no implementation. Pure virtual functions are equated to zero. class Shape { public: virtual void draw() = 0; };

Question - 48 : - What is polymorphism? Explain with an example?

Answer - 48 : - "Poly" means "many" and "morph" means "form". Polymorphism is the ability of an object (or reference) to assume (be replaced by) or become many different forms of object. Example: function overloading, function overriding, virtual functions. Another example can be a plus ‘+’ sign, used for adding two integers or for using it to concatenate two strings.

Question - 49 : - What’s the output of the following program? Why?

Answer - 49 : - #include main() { typedef union { int a; char b[10]; float c; } Union; Union x,y = {100}; x.a = 50; strcpy(x.b,\"hello\"); x.c = 21.50; printf(\"Union x : %d %s %f \n\",x.a,x.b,x.c ); printf(\"Union y :%d %s%f \n\",y.a,y.b,y.c); } Given inputs X, Y, Z and operations | and & (meaning bitwise OR and AND, respectively) What is output equal to in output = (X & Y) | (X & Z) | (Y & Z)

Question - 50 : - Why are arrays usually processed with for loop?

Answer - 50 : - The real power of arrays comes from their facility of using an index variable to traverse the array, accessing each element with the same expression a[i]. All the is needed to make this work is a iterated statement in which the variable i serves as a counter, incrementing from 0 to a.length -1. That is exactly what a loop does.


NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners