[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++

    21 / 187

    Explain overloading the delete operator.
    Answer:

    Syntax:

    void operator delete(void *p)
    {
    /*free memory pointed to by p. the destructor is called automatically.*/
    }

    The delete function receives a pointer to the region of memory to be freed. It then releases the previously allocated memory back to the system. When an object is deleted, its destructor is automatically called.

    Please Login First :

    22 / 187

    Explain overloading the new operator.
    Answer:

    Syntax:
    void *operator new (size_t size)
    {
    /*performs the allocation operation.
    The constructor is called automatically.
    returns the pointer to memory*/
    }
    size_t - It is a defined type capable of containing the largest single piece of memory that can be allocated.
    Size - It contains the number of bytes needed to hold the object being allocated.
    When we allocate an object using new, the object’s constructor is automatically called.

    Please Login First :

    23 / 187

    Mention the advantages of having default arguments in constructors.
    Answer:

    • It prevents us from having to provide an overloaded constructor that takes no parameters.
    • It is convenient by providing the default common initial values than specifying them each time an object is declared.

    Please Login First :

    24 / 187

    Mention the advantages of providing the default arguments.
    Answer:

    • We can use default arguments to add new parameters to the existing functions.
    • Default arguments can be used to combine similar functions into one.

    Please Login First :

    25 / 187

    When the functions are said to be overloaded?
    Answer:

    Functions are said to be overloaded when they have the same name with the different number and the type of the arguments. Two functions differing only in their return types cannot be overloaded.

    Please Login First :
    Answer:

    Two or more functions can share the same name that perform a variety of different tasks as long as their parameter declarations are different. The functions that share the same name are said to be overloaded, and the process is referred to as function overloading.

    Please Login First :

    27 / 187

    How to initialize object dynamically?
    Answer:

    Class objects can be initialized dynamically too. That is, the initial value of an object may; be provided during run time.

    Advantages:
    We can provide various initialization formats, using overloaded constructor. This provides the flexibility of using different format of data at run time depending upon the situation.

    Please Login First :

    28 / 187

    Distinguish between default constructor and default argument constructor?
    Answer:

    Default constructor:

    1. The constructor that accepts no parameter is called is a default constructor.
    2.it is used in class by
    A :: A( )

    Default argument constructor:

    1. The default argument constructor can be called with either one argument or no arguments.
    2. It is used in class by
    A:: A(int =0)

    Please Login First :

    29 / 187

    Which method is called as shorthand method?
    Answer:

    To pass values as arguments to the constructor function when an object is declared.
    By calling the constructor implicitly

    Ex:
    Implicit call:
    Integer int1 (0,100);
    This method is called as shorthand method, is used very often as it is shorter, looks better and is easy to implement.

    Please Login First :

    30 / 187

    How to pass values as arguments to the constructor when an object is declared?
    Answer:

    To pass values as arguments to the constructor function when an object is declared. This done in two ways.
    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 :