• +91 9971497814
  • info@interviewmaterial.com

Computer Interview Questions Answers

CPlusPlus Interview Questions Answers

Question - 61 : - What is a default constructor?

Answer - 61 : - Default constructor WITH arguments class B { public: B (int m = 0) : n (m) {} int n; }; int main(int argc, char *argv[]) { B b; return 0; }

Question - 62 : - What is RTTI?

Answer - 62 : - Runtime type identification (RTTI) lets you find the dynamic type of an object when you have only a pointer or a reference to the base type. RTTI is the official way in standard C++ to discover the type of an object and to convert the type of a pointer or reference (that is, dynamic typing). The need came from practical experience with C++. RTTI replaces many Interview Questions - Homegrown versions with a solid, consistent approach.

Question - 63 : - What is "mutable"?

Answer - 63 : - 1.   "mutable" is a C++ keyword. When we declare const, none of its data members can change. When we want one of its members to change, we declare it as mutable. 2.   A "mutable" keyword is useful when we want to force a "logical const" data member to have its value modified. A logical const can happen when we declare a data member as non-const, but we have a const member function attempting to modify that data member. For example: class Dummy { public: bool isValid() const; private: mutable int size_ = 0; mutable bool validStatus_ = FALSE; // logical const issue resolved }; bool Dummy::isValid() const // data members become bitwise const { if (size > 10) { validStatus_ = TRUE; // fine to assign size = 0; // fine to assign } }

Question - 64 : - What are the conditions that have to be met for a condition to be an invariant of the class?

Answer - 64 : - * The condition should hold at the end of every constructor. * The condition should hold at the end of every mutator (non-const) operation.

Question - 65 : - What are 2 ways of exporting a function from a DLL?

Answer - 65 : - 1.Taking a reference to the function from the DLL instance. 2. Using the DLL ’s Type Library

Question - 66 : - What is the Standard Template Library (STL)?

Answer - 66 : - A library of container templates approved by the ANSI committee for inclusion in the standard C++ specification. A programmer who then launches into a discussion of the generic programming model, iterators, allocators, algorithms, and such, has a higher than average understanding of the new technology that STL brings to C++ programming.

Question - 67 : - What are proxy objects?

Answer - 67 : - Objects that stand for other objects are called proxy objects or surrogates. template <class t=""> class Array2D { public: class Array1D { public: T& operator[] (int index); const T& operator[] (int index)const; }; Array1D operator[] (int index); const Array1D operator[] (int index) const; }; The following then becomes legal: Array2D<float>data(10,20); cout<<data[3][6]; // fine Here data[3] yields an Array1D object and the operator [] invocation on that object yields the float in position(3,6) of the original two dimensional array. Clients of the Array2D class need not be aware of the presence of the Array1D class. Objects of this latter class stand for one-dimensional array objects that, conceptually, do not exist for clients of Array2D. Such clients program as if they were using real, live, two-dimensional arrays. Each Array1D object stands for a one-dimensional array that is absent from a conceptual model used by the clients of Array2D. In the above example, Array1D is a proxy class. Its instances stand for one-dimensional arrays that, conceptually, do not exist. Name some pure object oriented languages. Smalltalk, Java, Eiffel, Sather.

Question - 68 : - What is a Null object?

Answer - 68 : - It is an object of some class whose purpose is to indicate that a real object of that class does not exist. One common use for a null object is a return value from a member function that is supposed to return an object with some specified properties but cannot find such an object.

Question - 69 : - Write the psuedo code for the Depth first Search.

Answer - 69 : - dfs(G, v) //OUTLINE Mark v as "discovered" For each vertex w such that edge vw is in G: If w is undiscovered: dfs(G, w); that is, explore vw, visit w, explore from there as much as possible, and backtrack from w to v. Otherwise: "Check" vw without visiting w. Mark v as "finished".

Question - 70 : - What is an Iterator class ?

Answer - 70 : - A class that is used to traverse through the objects maintained by a container class. There are five categories of iterators: input iterators, output iterators, forward iterators, bidirectional iterators, random access. An iterator is an entity that gives access to the contents of a container object without violating encapsulation constraints. Access to the contents is granted on a one-at-a-time basis in order. The order can be storage order (as in lists and queues) or some arbitrary order (as in array indices) or according to some ordering relation (as in an ordered binary tree). The iterator is a construct, which provides an interface that, when called, yields either the next element in the container, or some value denoting the fact that there are no more elements to examine. Iterators hide the details of access to and update of the elements of a container class. The simplest and safest iterators are those that permit read-only access to the contents of a container class.

Computer Contributors

krishan
Rajeev Katiyar
Yes Baroda

Share your email for latest updates

Name:
Email:

Our partners