[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.

Technical Interview Questions and Answers :: C++

    71 / 187

    What is the difference between class and structure?

    Structure: Initially (in C) a structure was used to bundle different type of data types together to perform a particular functionality. But C++ extended the structure to contain functions also. The major difference is that all declarations inside a structure are by default public.

    Class: Class is a successor of Structure. By default all the members inside the class are private.

    Please Login First :

    72 / 187

    What is public, protected, and private?

    Ø Public, protected and private are three access specifier in C++.
    Ø Public data members and member functions are accessible outside the class.
    Ø Protected data members and member functions are only available to derived classes.
    Ø Private Data members and member functions can’t be accessed outside the class. However there is an exception can be using friend classes.

    Please Login First :

    73 / 187

    What is constructor? What is the return type of it?

    A constructor is a special member function whose task is to initialize the objects of its class. It is special because its name is the same as the class name. The constructor is invoked whenever an object of its associatied class is created.
    It is called constructor because it construct the values of data members of the class.

    Please Login First :

    74 / 187

    What are the types of constructor?

    a. default constructor(or)empty constructor
    b. default argument constructor
    c. constructor polymorphism(or)multiple constructor(or)constructor overloading
    d. copy constructor
    e. parameterized constructor.

    Please Login First :

    75 / 187

    What is constructor overloading?

    When there is more than one constructor in a class with different parameters and with different data types we say that the constructor is overloaded.

    Please Login First :

    76 / 187

    What is overloading constructor?
    What is multiple constructor?

    The sharing the same name by two or more functions is referred to as function overloading. Similarly when more than one constructor function is defined in a class. We say that the constructor is overloaded. It is also called multiple constructors.

    Example :
    Complex() { } //constructor with no arg.
    Complex (float a) { x=y=a;} //constructor with one arg.
    Complex (float real, float imag) //constructor with two arg.

    Please Login First :

    77 / 187

    How to use delete operator in destructor?

    Whenever new is used to allocate memory in the constructors. We should use delete to free that memory. For example, the destructor for the matrix class discussed above may; be defined as follows

    Matrix :: ~matrix( )
    for(int i=0;i delete p[i];
    delete p;

    Please Login First :

    78 / 187

    Difference between constructor and destructor?


    1. The constructor is a ‘special’ member function whose task is to initialize the objects of its class.
    2. It constructs the values of data members of the class

    1. The destructor is a member function whose name is the same as the class name but is preceded by a tilde.
    2. It destroys the objects that have been created by a constructor.

    Please Login First :

    79 / 187

    What is dynamic constructor?

    The constructor can also be used to allocate memory while creating objects.
    This will enable the system to allocate the right amount of memory for each object when the objects are not of the same size, thus resulting in the saving of memory;. Allocation of memory to object at the time of their construction is known as a dynamic construction of objects. The memory is allocated with the help of the new operator. The use of new in constructors that are used to construct strings in objects.

    Please Login First :

    80 / 187

    What is default argument constructor?

    It is possible to define constructors with default arguments. for example, the constructor complex( ) can be declared as follows:

    Complex(float real, float imag=0)
    The default value of the argument imag is zero.then the statement
    Complex c(5.0);
    Assigns the value 5.0 to the real variable and 0.0 to imag (by default). However, the statement
    Complex c(2.0,3.0);
    Assigns 2.0 to real and 3.0 to imag. The actual parameter, when specified, overrides the default value. As pointed out earlier, the missing arguments must be the trailing ones.

    Please Login First :

You can check latest and updated Advanced C++ Interview Questions and Answers 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.