Friday, January 3, 2014

C++ important interview questions and exam notes

  1. Important benefits OOPS programming in C++
    Encapsulation- Securing data in single unit in form of class.
    Data Abstraction- Creating new user defined data types modeling real world entities complete with built in data type properties and allowed operators.
    Inheritance- Allows a sub class to inherit the properties of the base class. Help avoid the problem of rewriting the code again and again in a program.
    Multiple Inheritance- Type of inheritance where there are multiple base classes each with its own instance variable
    Polymorphism- Single name/operator associated with multiple operations depending on the type of data. It is done by operator overloading, function overloading and dynamic binding (virtual functions).
    Message Passing- It invokes an operation on an object by passing a message
    Genericity- It is declaration of data items without specifying data type. It is done when the data type is not fixed and varies according to the data passed to it. Example is sort() function. It is realized through function templates and class templates.
    Delegation- Based on the object view that an object can be a collection of multiple objects and relationships. That is it has a has a relationship or containership relationship. It is quite similar to inheritance in that it passes (delegates) a receiving operating to its delegate.
    Persistence- Object outlives the existence of its program execution period and exists during the program execution too. Supported in C++ by use of file streams.
    Extensibility- This is what is done by inheritance and abstract classes. They allow the extension of a software or function.
  2. Types of programming paradigm and to which does C++ belong?
    Monolithic, Structural,  Procedural and Object Oriented
    C++ belongs to Object Oriented programming type
  3. Types of Object based programming and differences
    Object based languages- Encapsulation + Object identity
    Object oriented languages- Object based + Inheritance + Polymorphism
  4. Dynamic binding or late binding refers to the binding of the procedure call to the address code which executes when the procedure is called. This means that the code to be executed is unknown till it is called at run time.
  5. C++ was developed by Bjarne Stroustrup in AT&T Bell laboratories in 1980.
  6. Memory allocation for objects: Static (preallocated by compiler in fixed global memory), automated (allocated on stack) and dynamic (allocated on heap).
  7. It C++ it is possible to access a global variable with the same name as the local variable with the help of scope resolution operator (::)
  8. Reference variables are used a value variable but have the power of pointer variable. Reference variables are called as an alias for the actual variable. Constant values do not have an alias; i.e. int &b=a[100] will give compilation error.
  9. Inline function is used where the function is small to avoid the overhead of jumping to another function. Member functions defined inside a class are considered inline and those outside the class are not treated inline.
  10. In C++, basic data types can easily be converted with implicit type conversion or explicit type conversion routines for which are provided by the compiler itself.
  11. Function templates are programs which possess the functionality of many functions which themselves are different only due to their parameters and local variable data types.
  12. new in C++ is similar to malloc() and calloc() of C and similarly delete operator in C++ is similar to free of C. Important to call delete after new to ensure that the allocated heap space is returned back to the system.
  13. Constructor is a member function having same name as of the class and is executed automatically when the class is instantiated. It is possible to overload a constructor.
    Destructor is used (~classname) to reclaim the memory allocated to an object. A class has only 1 destructor.
  14. Access specifiers like private and public are used to set access permissions to a class.

No comments:

Post a Comment