Sample Questions Best site for GRE, LSAT, SAT, GMAT, TOEFL, CCNA, CCSA and interview sample questions  

Technical Sample Questions : C |  C++ |  Oracle |  Java | Unix |  Operating Systems |  Data Structure

Sample Technical Questions

C++ and OOPS Sample Question

  1. What is a smart pointer?


    A smart pointer is an object that acts, looks and feels like a normal pointer but offers more functionality. In C++, smart pointers are implemented as template classes that encapsulate a pointer and override standard pointer operators. They have a number of advantages over regular pointers. They are guaranteed to be initialized as either null pointers or pointers to a heap object. Indirection through a null pointer is checked. No delete is ever necessary. Objects are automatically freed when the last pointer to them has gone away. One significant problem with these smart pointers is that unlike regular pointers, they don't respect inheritance. Smart pointers are unattractive for polymorphic code. Given below is an example for the implementation of smart pointers.


    template ‹class X›
       class smart_pointer
                       smart_pointer();                          // makes a null pointer
                       smart_pointer(const X& x)            // makes pointer to copy of x
                       X& operator *( );
                       const X& operator*( ) const;
                       X* operator->() const;
                       smart_pointer(const smart_pointer ‹X› &);
                       const smart_pointer ‹X› & operator =(const smart_pointer‹X›&);
    This class implement a smart pointer to an object of type X. The object itself is located on the heap. Here is how to use it:
    smart_pointer ‹employee› p= employee("Harris",1333);
    Like other overloaded operators, p will behave like a regular pointer,
    p -> raise_salary(0.5);
  2. What is reflexive association?


    The 'is-a' is called a reflexive association because the reflexive association permits classes to bear the is-a association not only with their super-classes but also with themselves. It differs from a 'specializes-from' as 'specializes-from' is usually used to describe the association between a super-class and a sub-class. For example: Printer is-a printer.
  3. What is slicing?


    Slicing means that the data added by a subclass are discarded when an object of the subclass is passed or returned by value or from a function expecting a base class object.

    Consider the following class declaration:

    class base
                         base& operator =(const base&);
                         base (const base&);
                  void fun( )
                        base e=m;
    As base copy functions don't know anything about the derived only the base part of the derived is copied. This is commonly referred to as slicing. One reason to pass objects of classes in a hierarchy is to avoid slicing. Other reasons are to preserve polymorphic behavior and to gain efficiency.
  4. What is name mangling?


    Name mangling is the process through which your c++ compilers give each function in your program a unique name. In C++, all programs have at-least a few functions with the same name. Name mangling is a concession to the fact that linker always insists on all function names being unique.

    In general, member names are made unique by concatenating the name of the member with that of the class e.g. given the declaration:

    class Bar
                    int ival;
    ival becomes something like:
          // a possible member name mangling
    Consider this derivation:
         class Foo : public Bar 
                  int ival;
    The internal representation of a Foo object is the concatenation of its base and derived class members.
    // Pseudo C++ code
        // Internal representation of Foo
        class Foo
                 int ival__3Bar;
                 int ival__3Foo;
    Unambiguous access of either ival members is achieved through name mangling. Member functions, because they can be overloaded, require an extensive mangling to provide each with a unique name. Here the compiler generates the same name for the two overloaded instances(Their argument lists make their instances unique).

« Previous || Next »

C++ Sample Question number : 1-3 | 4-7 | 8-10 | 11-13 | 14-21 | 22-28 | 29-35 | 36-42 | 43-49 | 50-54 | 55-58 | 59-66 | 67-73 | 74-80
Sample Test Questions
GRE Sample Questions
CAT Sample Questions
GMAT Sample Questions
TOEFL Sample Questions
ACT Sample Questions
SAT Sample Questions
LSAT Sample Questions
PSAT Sample Questions
MCAT Sample Questions
PMP Sample Questions
GED Sample Questions
ECDL Sample Questions
DMV Sample Questions
CCNA Sample Questions
MCSE Sample Questions
Network+ Sample Questions
A+ Sample Questions
Technical Sample Questions
WASL Sample Questions
CISA Sample Questions

Other Sample Questions
Sample Interview Questions
Sample Teacher Interview Questions
Sample Citizenship Questions
Accuplacer Sample Questions
Science Bowl sample Questions
Driving Test Sample Questions
Sample Survey Questions Sample Essay Questions
Sample Behavioral Interview Questions

Copyright © 2004-2013, Best BSQ. All Rights Reserved.