Note 1

Take Note:

Take a note while surfing.





Note With Ink

Give your Note a Colorful Tag.




Easy to Access

Stay on same information and in Sync wherever you are.

Note 2

Take Note:

Organize your information,It may take Shape.





Think With Ink

Differ your Content by Color.




Easy to Access

Easy to pull up your content from anywhere anytime.

Note 3

Take Note:

Don't Let information to miss,Because it take shape





Note With Ink

Simple an Easy Way to take a note.




Easy to Access

Get the same in next visit.

Technical Interview Questions and Answers :: C++

  • 1. What are the two ways to pass values as arguments to the constructor?
  • Answer:

    Two ways to pass values as arguments to the constructor function when an object is declared.

    1. By calling the constructor explicitly.
    2. By calling the constructor implicitly.

    Eg :
    Explicit call:
    Integer int1=integer(0,200);

    Implicit call:
    Integer int1(0,100);

    Please Login First :
    Tags:

    No Tags on this question yet!

  • 2. What is parameterized constructors, Give example?
  • Answer:

    It may be necessary to initialize the various data elements of different objects with different values when they are created.
    C++ permits us to achieve this objective by passing an argument to the constructor function when the objects are created. The constructors that can take arguments are called parameterized constructors.

    Eg:
    Class A
    {
    int m,n;
    public:
    A(int x,int y); //parameterized constructor
    ………..
    ………..
    };
    A : : A(int x,int y)
    {
    m=x;
    n=y;
    }

    Please Login First :
    Tags:

    No Tags on this question yet!

  • 3. What is default constructor. Give example?
  • Answer:

    A constructor that accepts no parameters is called the default constructor. The default constructor for class A is A::A ( ). If no such constructor is defined, then the compiler supplies a default constructor. Therefore a statement such as A a;
    Invokes the default constructor of the compiler to create the object a.

    Please Login First :
    Tags:

    No Tags on this question yet!

  • 4. What are characteristics of the constructor function?
  • Answer:

    The constructor functions have some characteristics:

    • They should be declared in the public section.
    • They got invoked automatically when the objects are created.
    • They do not have return types, not even void and therefore, they cannot return values.
    • They cannot be inherited, through a derived class can call the base class constructor.
    • Like other c++ functions, they can have default arguments.
    • Constructors cannot be virtual.
    • We cannot refer to their addresses.
    • An object with a constructor cannot be used as a member of a union.
    • They make implicit calls to the operators new and delete when memory allocation is required.

    When a constructor is declared for a class, initialization of the class objects becomes mandatory.

    Please Login First :
    Tags:

    No Tags on this question yet!

  • 5. What are properties of the constructor function?
  • Answer:

    • They should be declared in the public section.
    • They got invoked automatically when the objects are created.
    • They do not have return types, not even void and therefore, they cannot return values.
    • They cannot be inherited, through a derived class can call the base class constructor.
    • Like other c++ functions, they can have default arguments.
    • Constructors cannot be virtual.
    • We cannot refer to their addresses.
    • An object with a constructor cannot be used as a member of a union.
    • They make implicit calls to the operators new and delete when memory allocation is required.
    • When a constructor is declared for a class, initialization of the class objects becomes mandatory.

    Please Login First :
    Tags:

    No Tags on this question yet!

  • 6. How to declare and define constructor?
  • Answer:

    A constructor is declared and defined as

    Class integer
    {
    int m,n;
    public:
    integer(void); //constructor declared
    ……….
    ………..
    };
    integer : : integer(void)//constructor defined
    {
    m=0;
    n=0;
    }

    Please Login First :
    Tags:

    No Tags on this question yet!

  • 7. Explain the concept of reusability in c++?
  • Answer:

    C++ strongly supports the concept of reusability. The c++ classes can be reused in several ways .Once a class has been written and tested, it can be adapted by other programmers to suit their requirement .this done by creating new class reusing the properties of the existing ones is called reusability.

    Please Login First :
    Tags:

    No Tags on this question yet!

  • 8. What is Derived class?
  • Answer:

    A derived class can be defined by specifying its relationship with the base class in addition to its own details. the general form of defining a derived class is

    Class derived_class_name
    {
    --------------
    --------------//members of derived class
    --------------
    };

    Please Login First :
    Tags:

    No Tags on this question yet!

  • 9. What is meant by visibility mode explain briefly?
  • Answer:

    Visibility mode is optional and may be either private or public. The default visibility mode is private. Visibility mode specifies whether the features of the base class are privately derived or publicly derived.

    Ex:
    Class abc: private Xyz // private derivation
    {

    members of abc;
    };


    Ex:
    Class abc: private Xyz // public derivation
    {

    members of abc;
    };

    Please Login First :
    Tags:

    No Tags on this question yet!

  • 10. Why do we need virtual function?
  • Answer:

    When a function is made virtual, c++ determines which function to use at run-time based on the type of the object pointed to by the base pointer, rather than the type of the pointer. By making the base pointer to point to different objects, we execute different versions of the virtual function.

    Please Login First :
    Tags:

    No Tags on this question yet!

You can check latest and updated C++ Interview Questions and Answers Basic on this page. You can filter the question set by the company's name. Looking for the right answer? Don't worry! You can click on view answer section and check the answer with the explanation. You can discuss the answer in the forum with other users easily. Login with Facebook and save the answer To Reading List right now!

Our site contains top IT companies placement paper and mock test to help the freshers and experienced candidate to get hands on experience on the pattern and type of questions. We have curated all the C++ technical interview questions and answers from previous candidates.