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

    Answer:

    Class is a user-defined data type in C++. It can be created to solve a particular kind of problem. After creation the user need not know the specifics of the working of a class.

    Please Login First :
    Answer:

    Object is a software bundle of variables and related methods. Objects have state and behavior.

    Please Login First :

    53 / 183

    What is virtual constructors/destructors?
    Answer:

    Virtual destructors: If an object (with a non-virtual destructor ) is destroyed explicitly by applying the delete operator to a base-class pointer to the object, the base-class destructor function (matching the pointer type) is called on the object.
    There is a simple solution to this problem – declare a virtual base-class destructor. This makes all derived-class destructors virtual even though they don’t have the same name as the base-class destructor. Now, if the object in the hierarchy is destroyed explicitly by applying the delete operator to a base-class pointer to a derived-class object, the destructor for the appropriate class is called.

    Virtual constructor: Constructors cannot be virtual. Declaring a constructor as a virtual function is a syntax error. Does c++ support multilevel and multiple inheritance?
    Yes.
    What are the advantages of inheritance?
    • It permits code reusability.
    • Reusability saves time in program development.
    • It encourages the reuse of proven and debugged high-quality software, thus reducing problem after a system becomes functional.
    What is the difference between declaration and definition?
    The declaration tells the compiler that at some later point we plan to present the definition of this declaration.
    E.g.: void stars () //function declaration
    The definition contains the actual implementation. E.g.: void stars () // declaration
    {
    for(int j=10; j>=0; j--) //function body cout<<”*”;
    cout< }

    Please Login First :

    54 / 183

    What do you mean by pure virtual functions?
    Answer:

    A pure virtual member function is a member function that the base class forces derived classes to provide. Normally these member functions have no implementation. Pure virtual functions are equated to zero.
    class Shape { public: virtual void draw() = 0; };

    Please Login First :

    55 / 183

    What is Namespace?
    Answer:

    Namespaces allow us to group a set of global classes, objects and/or functions under a name. To say it somehow, they serve to split the global scope in sub-scopes known
    as namespaces.The form to use namespaces is:

    namespace identifier { namespace-body }

    Where identifier is any valid identifier and namespace-body is the set of classes, objects and functions that are included within the namespace. For example:
    namespace general { int a, b; } In this case, a and b are normal variables integrated within the general namespace. In order to access to these variables from outside the namespace we have to use the scope operator ::. For example, to access the previous variables we would have to put:

    general::a general::b

    The functionality of namespaces is specially useful in case that there is a possibility that a global object or function can have the same name than another one, causing a
    redefinition error.

    Please Login First :

    56 / 183

    What is RTTI?
    Answer:

    Run time type identification (RTTI) lets you find the dynamic type of an object when you have only a pointer or a reference to the base type. RTTI is the official way in standard C++ to discover the type of an object and to convert the type of a pointer or reference (that is, dynamic typing). The need came from practical experience with C++. RTTI replaces many homegrown versions with a solid, consistent approach.

    Please Login First :

    57 / 183

    What is a template?
    Answer:

    Templates allow to create generic functions that admit any data type as parameters and return value without having to overload the function with all the possible data types. Until certain point they fulfill the functionality of a macro. Its prototype is any of the two following ones:

    template function_declaration; template function_declaration;

    The only difference between both prototypes is the use of keyword class or type name, its use is indistinct since both expressions have exactly the same meaning and behave exactly the same way.

    Please Login First :

    58 / 183

    What do you mean by inline function?
    Answer:

    The idea behind inline functions is to insert the code of a called function at the point where the function is called. If done carefully, this can improve the application's performance in exchange for increased compile time and possibly (but not always) an increase in the size of the generated binary executables.

    Please Login First :

    59 / 183

    What is virtual class and friend class?
    Answer:

    Friend classes are used when two or more classes are designed to work together and need access to each others implementation in ways that the rest of the world shouldn’t be allowed to have. In other words, they help keep private things private. For instance, it may be desirable for class Database Cursor to have more privilege to the internals of class Database than main () has.

    Please Login First :

    60 / 183

    What is function overloading and operator overloading?
    Answer:

    Function overloading: C++ enables several functions of the same name to be defined, as long as these functions have different sets of parameters (at least as far as their types are concerned). This capability is called function overloading. When an overloaded function is called, the C++ compiler elects the proper function by examining the number, types and order of the arguments in the call. Function overloading is commonly used to create several functions of the same name that perform similar tasks but on different data types.

    Operator overloading allows existing C++ operators to be redefined so that they work on objects of user-defined classes. Overloaded operators are syntactic sugar for equivalent function calls. They form a pleasant facade that doesn't add anything fundamental to the language (but they can improve understand ability and reduce maintenance costs).

    Please Login First :



You can check latest and updated C++ Programming Questions and Answers C++ Programs Questions 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.