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

    101 / 187

    What are the rules of virtual function?
    Answer:

    1. Virtual functions must be members of some class.
    2. They cannot be static members.
    3. They are accessed by using object pointers.
    4. A virtual function can be a friend of another class.
    5. We cannot have virtual constructors but we can have virtual destructors.
    6. If a virtual function is defined in the base class. It need not be necessarily redefined in the derived class.

    Please Login First :

    102 / 187

    What does generic programming means?
    Answer:

    Templates execute us to define generic class and functions and thus provides support for generic programming. It is an approach where generic types are used as parameters in algorithms so that they work for a variety of suitable data types and data structures.

    Please Login First :

    103 / 187

    Why do we call templates as a parameterized class?
    Answer:

    Templates are defined with a parameter that would be replaced by a specified data type at the time of actual use of the class or function, the template is sometimes called as parameterized classes or functions.

    Please Login First :

    104 / 187

    What do you mean by template class?
    Answer:

    A class created from a class template is called a template class. The syntax for defining an object of a template class is :

    Class_nameobject_name(arglist);

    The process of creating a specific class from a class is called instantiation. The compiler will perform the error analysis only when an instantiation takes place.

    Please Login First :

    105 / 187

    Define class templates with multiple parameters?
    Answer:

    We can use more than one generic data types in a class template. They are declared as a comma separated list within the template specification as shown below:
    Syntax:

    Template
    Class classname
    {
    ----------
    ---------- ( body of the class)
    };

    Please Login First :

    106 / 187

    What is function templates?
    Answer:

    Like class template, we can also define function templates that would be used to create a family of function with different argument types.
    Syntax:
    Template
    return type function name(argument of type T)
    {
    ………..
    //body of function
    //with type T
    //wherever appropriate
    }

    We must use the template parameter T as and when necessary in the function body and in its arguments list.

    Please Login First :

    107 / 187

    Explain function templates with multiple parameters?
    Answer:

    Like template class we can use more than one generic data type in the template statement, using comma separator
    Syntax:
    Template
    return type function name(argument of type T1,T2,…)
    {
    ………..
    //body of function

    }

    Please Login First :

    108 / 187

    How can we overload a template functions?
    Answer:

    A template function may be overloaded either by template function or by the ordinary function of its name. in such cases, the overloading resolution is accomplished by
    • Call an ordinary function that has an exact match.
    • Call a template function that would be created with an exact match.
    • Try normal overloading resolution to ordinary function and call the one that match.

    Please Login First :

    109 / 187

    What is meant by member function template?
    Answer:

    The member functions of the template classes themselves are parameterized by the type argument and therefore the function must be defined by the function template.

    Syntax:
    Template
    return type classname : : function name(arglist)
    {
    ……………(function body)
    …………….
    }

    Please Login First :

    110 / 187

    Explain non-type template arguments?
    Answer:

    It is also possible to use nontype arguments that are in additional argument T, we can also use other arguments such as strings, function names, constant expressions and built-in types.

    Ex:
    Template
    Class array
    {
    T a[size];
    ……..
    ……..
    };
    this templates supplies the size of the array as an argument.

    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.