Technical Interview Questions and Answers :: C++
â€¢ 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.
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.
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.
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).
When an exception that is desired to be handled is detected, it is thrown using throw statement in one of the following forms:
Throw; // used for re-throwing an exception.
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:
catch (type 1 arg)
// catch block1;
catch (type 2 arg)
// catch block 2;
Catch (type n arg)
// catch block n;
A handler may decide to rethrow the exception caught without processing it. In such situation, we may simply invoke throw without any argument.
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.
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
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.
There are three major categories of containers:
â€¢ Sequence container
â€¢ Associative container
â€¢ Derived container
3. priority queue
You can check latest and updated Important 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.