[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

    What are the benefits of templates?
    Answer:

    • Templates allow implementing the concept of generic programming.
    • Template allows us to generate a family of classes or a family of functions to handle different data types.
    • Template classes and functions eliminate code duplication for different types and thus make the program development easier and more manageable.
    • We can use multiple parameters in both the class templates and function templates.
    • Like other functions, templates can be overloaded.

    Please Login First :

    22 / 187

    What is meant by exception?
    Answer:

    Some peculiar problems other than logic or syntax errors, they are known as exceptions. Exceptions are run-time anomalies or unusual conditions that a program may encounter while executing. Anomalies might include the condition such a division by zero, array outside of bound etc.

    Please Login First :

    23 / 187

    What is meant by exception handling mechanism?
    Answer:

    Exception handling mechanism is basically built upon through keywords namely try, catch, and throw. The keyword try is used to preface a block of statements which may generate an exception. This block of statements is known as try block. When an exception is detected, it is thrown using a throw statement in the try block. A catch statement is defined by the keyword catch “catches” the exception thrown by the throw statement in the try block.

    Please Login First :

    24 / 187

    What are the purpose of the exception handling?
    Answer:

    The purpose of exception handling mechanism is to provide means to detect and report an “exception circumstance”. So that appropriate action can be taken. The mechanism suggests a separate error handling code that performs the following tasks.
    1. Find the problem (hit the exception).
    2. Inform than an error has occurred (throw the exception).
    3. Receives the error information (catch the exception).
    4. Take corrective action (handle the exception).

    Please Login First :

    25 / 187

    Explain throwing mechanism briefly?
    Answer:

    When an exception that is desired to be handled is detected, it is thrown using throw statement in one of the following forms:
    Throw(exception)
    Throw exception;
    Throw; // used for re-throwing an exception.

    Please Login First :

    26 / 187

    Explain multiple catch statements?
    Answer:

    It is possible that a program segment has more than one condition to throw an exception. In such case we can associate more than one catch statement with a try. For eg:

    Try
    {
    //try block;
    }
    catch (type 1 arg)
    {
    // catch block1;
    }
    catch (type 2 arg)
    {
    // catch block 2;
    }
    ……………….
    ……………….
    Catch (type n arg)
    {
    // catch block n;
    }

    Please Login First :

    27 / 187

    Explain briefly about rethrowing an exception?
    Answer:

    A handler may decide to rethrow the exception caught without processing it. In such situation, we may simply invoke throw without any argument.
    Eg: throw;
    This cause the current exception to be thrown to the next enclosing try/catch sequence and is caught by a catch statement listed after that enclosing try block.

    Please Login First :

    28 / 187

    What is STL? What are its three components?
    Answer:

    A collection of generic classes and function is called the standard template library (STL). STL components are part of c++ standard library. STL consist of three main components. They are
    • Containers
    • Algorithms
    • Iterators

    Please Login First :

    29 / 187

    What is meant by container?
    Answer:

    A container is an object that actually stores data. It is a way data is organized in memory, the STL containers are implemented by template classes and therefore can be easily customized to hold different types of data.

    Please Login First :

    30 / 187

    What are the types of Iterators that are supported by each container class?
    Answer:

    There are three major categories of containers:
    • Sequence container
    1) Vectors
    2) Dequeue
    3) list

    • Associative container
    1. set
    2. multiset
    3. map
    4. multimap
    • Derived container
    1. stack
    2. queue
    3. priority queue

    Please Login First :