C and C++ Interview Questions

  1. inheritance (defn)
    The mechanism of deriving a new class (derived) from an old class (base class). It allows the extension and reuse of existing code without having to rewrite the code from scratch.Additionally, it is the process by which objects of one class acquire properties of objects of another class.
  2. What is C++?
    This language is created by Bjarne Stroustrup of AT&T Bell Labs as an extension of C, it is an object-oriented computer language used in the development of enterprise and commercial applications.
  3. The basic concepts of object oriented programming (List)
    • Objects
    • Classes
    • Data abstraction and encapsulation
    • Inheritance
    • Polymorphism
    • Dynamic Binding
    • Message passing
  4. Polymorphism (def'n)
    This concept  means one name, multiple forms. It allows us to have more than one function with the same name in a program.It allows us to have overloading of operators so that an operation can exhibit different behaviors in different instances.
  5. What are the features of C++ different from C?
    • All the features of C are similiar to C++ except some features, such as polymorphism, operator overloading which are supported in C++ but not in the C language.
    • Both C and C++ language is similar in their functionality but C++ provides with more tools and options.
  6. Encapsulation (def'n)
    The wrapping up of data and functions into a single unit (called class). Containing and hiding information about an object, such as internal data structures and code.
  7. message passing(def'n)
    • An object oriented program consists of a set of objects that communicate with each other.
    • This involves specifying the name of the object, the name of the function and the information to be sent.
  8. Tokens in C++ (def'n)
    The smallest individual units of a program.

    • Keywords
    • Identifiers
    • Constants
    • Strings
    • Operators
  9. What is the use of enumerated data type?
    • This is another user defined type which provides a way for attaching names.
    • to numbers thereby increasing comprehensibility of the code.
  10. (Default Constructor)If no user-defined constructor exists for a class A and one is needed, the compiler __?__.

  11. (Constructors)A constructor that accepts no parameters is called the __?___.

  12. (Default Constructor) This constructor is an inline __?___.

  13. (Default Constructor) The compiler will implicitly define the Default Constructor A::A() when the compiler:

  14. (Constructors)What type of constructor has no constructor initializer and a null body?

  15. Constructor (def'n)
    A member function with the same name as its class, and it is invoked whenever an object of its associated class is created.
  16. (Constructors) A constructor is called  constructor because___?____.
    It  constructs the values of data members of the class.
  17. How variable declaration in c++ differs that in c.
    C requires all the variables to be declared at the beginning of a scope, but in C++ we can declare variables anywhere in the scope. 

  18. Destructor (def'n)
    • Is called for a class object when that object passes out of scope or is explicitly deleted.
    • Is used to destroy the objects that have been created by a constructors.
    • Is a member function whose name is the same as the class name but is preceded by a tilde
  19. Class (def'n)
    A collection of objects.
  20. What is the difference between C & C++?
    • C++ is a an object oriented programing but C is a procedure oriented programing.
    • C is super set of C++
    • C can’t support inheritance, function overloading, method overloading etc. but c++ can do this.
    • In c program the main function could not return a value but in the c++ the main function should return a value.
  21. (Inline Function) Inline function advantages (?)
    • It offers an improved macro facility.
    • The user can split a large function with many nested modules of statement blocks into many small inline functions.
  22. Copy Constructor (def'n)
    A constructor function with the same name as the class and used to make deep copy of objects.
  23. Default Constructor (def'n)
    A constructor that either has no parameters, or if it has parameters, all the parameters have default values.
  24. Scope resolution operator (def'n)
    Permits a program to reference an identifier in the global scope that has been hidden by another identifier with the same name in the local scope.
  25. What is the difference between Object and Instance?
    • An instance of a user-defined type is called an object. We can instantiate many objects from one class.
    • An object is an instance of a class.
  26. What is the difference between macro and inline?
    • Inline follows strict parameter type checking, macros do not.
    • Macros are always expanded by preprocessor, whereas compiler may or may not replace the inline definitions.
  27. What is multiple inheritance?
    One thing Java or C# cannot do. A class can inherit properties from more than one class
  28. What is meant by reference variable in C++?
    Provides an alias to a previously defined variable.

    Data -type & reference-name = variable name
  29. Iterator class (def'n)
    Provides an access to the class which are inside the containers(it holds a group of objects in an organized way).
  30. Smart Pointers (def'n)
    Similar to pointers with additional features such as:

    1) Automatic destruction of a variable when it becomes out of scope.

    2)Throwing of exceptions that ensures the proper destruction of the dynamically allocated objects.
  31. (Function Overloading)Can a function be overloaded based on return types?
    Function signature does not depend on the return type. So overloading cannot be resolved by the return type alone.
  32. Virtual Function (def'n)
    • A member function that is declared within a base class and redefined by a derived class.
    • To create one the function declaration in the base class is preceded by the keyword virtual.
Card Set
C and C++ Interview Questions
questions taken from http://www.a2zinterviews.com