Technical Interview Questions

C++ Interview Questions-C++ Advanced

|   62697

1. If you want many different iterators to be active simultaneously then which of the followings can be used?

a. Internal Iterators  

b. External Iterators  

c. Both   

d. None

Answer:b External Iterators

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 different iterators can be active simultaneously on the same object.

2. Write a function which gets the n bits from an unsigned integer x, starting from position p .(the right most digit is at position 0)

a.mask  = FFFF;

  mask   = mask << p;

  output   = mask & x;

b.mask  = FFFF;

   mask   = mask << p;

   output   = mask ^ x;

c.mask  = FFFF;

   mask   = mask >> p;

   output   = mask & x

d.mask  = FFFF;

   mask   = mask >> p;

   output   = mask ^ x;;

 Answer:d

3.
 Are method overloading and method overriding (w.r.t C++) same?

a. Both are same   

b Method overriding is available only in JAVA.

c. Method overloading is not available in C++.

d. Both are different

Answer:d. Both are different

Overloading a method (or function) in C++ is the ability for functions of the same name to be defined as long as these methods have different signatures (different set of parameters). Method overriding is the ability of the inherited class rewriting the virtual method of the base class.

 

 

feedback