Get Off-Campus Placement Jobs Info !!!
Programs asked in Mettl Coding Round
Click To Practce List of Programs asked in Nagarro !!!

Technical Interview Questions and Answers :: C++

    81 / 183

    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 :

    82 / 183

    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 :

    83 / 183

    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 :

    84 / 183

    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 :

    85 / 183

    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 :

    87 / 183

    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 :

    88 / 183

    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 :

    89 / 183

    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 :

    90 / 183

    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 :



You can check latest and updated C++ Job 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.