Home  Interview Questions  Certifications  Aptitude Questions  Tutorials  Placement Papers  Search  Resume  Soft Skills  Video  Forum  Blog

Technical Interview Questions

C++ Interview Questions
C# Interview Questions
C Interview Questions

Aptitude Interview Questions
C ++ Aptitude Question 2
C Aptitude Questions

C Tutorial
C++ Tutorial

Programming Source Codes
C/C++ Source Codes
C# Source Codes

Online Quiz
C Online Quiz
C++ Online Quiz

Soft Skills
Communication Skills
Leadership Skills



C/C++ Aptitude Questions and Answers

What is an opaque pointer?
A pointer is said to be opaque if the definition of the type to which it points to is not included in the current translation unit. A translation unit is the result of merging an implementation file with all its headers and header files.

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.

   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
                   const smart_pointer
& operator =(const smart_pointer&);
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:
p= employee("Harris",1333);
Like other overloaded operators, p will behave like a regular pointer,

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.

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.

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).  

What are proxy objects?
Objects that points to other objects are called proxy objects or surrogates. Its an object that provides the same interface as its server object but does not have any functionality. During a method invocation, it routes data to the true server object and sends back the return value to the object.

Page Numbers :   1         2         3         4         5         6         7         8         9

Next >> C/C++ Aptitude Questions and Answers 2

Have a Question ? post your questions here. It will be answered as soon as possible.

Check Placement Papers for more IT Companies Paper