C++ is an object-oriented programming language that was invented in 1979 and launched for commercial use in 1983. It was invented as an extension of the C coding language to include object-oriented paradigms.
C++ is an imperative, compiled language that can also be defined as a high-level, general-purpose language for application and system programming. Object-oriented and multi-paradigm C++ supports a range of programming styles, like generic, functional, and procedural. The programming language can also support low-level system design programming, which makes it suitable for the development of system software, like operating systems and device drivers. Furthermore, C++ also has a rich set of features and libraries to support high-level programming for developing complex applications like video games and desktop apps.
1. How is C++ different from C?
C is a procedural programming language that does not support object-oriented programming concepts. On the other hand, C++ is a multi-paradigm language that supports object-oriented programming concepts as well as many new features, like namespace, reference variable, etc.
C | C++ |
---|---|
C programming language is procedure-oriented | C++ programming language is partially object-oriented |
C programming language uses a top-down approach | C++ programming language uses a bottom-up approach |
Operator overloading and function are not supported by C | Function overloading and function are both supported by C++ |
Virtual and friend function are not supported by C | Virtual and friend function are both supported by C++ |
C programming language contains 32 keywords | C++ programming language contains 52 keywords |
2. What data types are present in C++?
There are three data types in C++: Primitive (char, float, int, etc.), derived (pointer, array, etc.), and user-defined (class, structure, etc.).
3. What is namespace in C++?”
A namespace in C++ is a defined area that enables the organization of entities such as classes, objects, and functions under a single identifier.
4. What is the token in C++?
A token is the smallest individual element that can be understood by a compiler in a program. A token can comprise keywords, identifiers, constants, strings, special symbols, and operators.
5. Differentiate between Call by Value and Call by Reference.
In Call by Value, copies of the actual parameters are passed to the formal parameters of the function. Changes to the values inside the function will not affect the actual values. On the other hand, in Call by Reference, the address of the actual parameters is sent to the formal parameters of the function, so any change in value within the function will change the actual values as well.
6. How is a reference different from a pointer?
A reference is an alias for an existing variable, defined by the & symbol. It can be accessed like a regular variable, but it cannot be NULL, and it cannot be reassigned. A pointer stores a variable’s memory address, defined by the * symbol. It requires the * operator to point to addresses or variables. It can be NULL and can also be reassigned.
7. Define classes and objects.
A class refers to a user-defined data type. It includes tailor-made data members and member functions, which can be accessed using an object. An object is an instance of a class. When we create a class, no memory is assigned to it, but using an instance by declaring an object, we can allocate memory to a class to store data and perform necessary functions.
8. Define the different object-oriented programming concepts in C++.
9. What is inheritance?
Inheritance is an OOPs concept that allows you to create a new class, also known as the child class, that derives characteristics and properties from the parent class.
10. Define the three types of access specifiers.
11. What is a storage class?
A storage class defines specific features of a variable or function, like visibility and lifetime of a variable.
12. What does the keyword ‘volatile’ do in C++?
Volatile is a qualifier that can be applied to variables. The keyword informs the compiler that the value of the variable may change at any time.
1. What are the limitations of C++?
There are a few drawbacks to C++: It doesn’t provide garbage collection support. Therefore, programmers have to manage memory manually. When this is not efficiently managed, manual processes cause storage of redundant data, which increases memory usage.
2. What are the five types of inheritance in C++?
Single inheritance, multiple inheritance, multilevel inheritance, hybrid inheritance, and hierarchical inheritance are the five types of inheritance in C++.
3. What is a constructor in C++?
A constructor in C++ is a unique method called automatically when an object of a class is instantiated. Its primary purpose is to initialize the data members of the newly created object. In C++, a constructor shares the same name as the class or structure it belongs to. It helps set up the initial values for the data members of the object, which is why it is referred to as a constructor.
4. What does the ‘delete’ operator do?
The delete operator deletes or removes all the characteristics or properties of an object and deallocates its memory.
5. What is friend class and friend function?
A friend class can access private and protected variables if it has been declared as a friend in those classes. The friend function is used to access public, protected, and private member functions and data members of other classes. The friend function is not bound to the scope of a class and cannot be called by an object of the class.
6. Explain polymorphism in C++.
Polymorphism is an OOPs concept that refers to the presence of multiple forms. It means that depending on the type of object that invokes the function, a different function will be executed.
7. How is an array different from a list in C++?
An array has a fixed size, supports random access through indexes, and the elements in arrays are stored as contiguous memory. A list has a variable size, and supports sequential access, and the elements in a list can be stored in any memory location in a list.
8. Explain the overflow error.
The overflow error happens when a number is larger than the defined range of the data type.
9. Can a program without a main function be compiled?
Yes. It is possible to compile a program without a main function. It can be done by using a macro to define main, using token-pasting operator, using augmented macro, by modifying the entry point at the time of compilation, etc.
10. Is it possible to have a recursive inline function in C++?
No. An inline function cannot be recursive as the code in an inline function is placed in the position from where it is called. An inline function does not maintain pieces of information on the stack, which are required for recursion.
1. What is the ‘diamond problem’ and when does it occur?
The diamond problem happens in multiple inheritance. It occurs when a derived class inherits its properties from various base classes that have a common ancestor. This situation creates confusion within the inheritance structure, potentially leading to unforeseen behavior during method resolution and access to members.
2. What does the ‘goto’ statement do in C++, and what is the best way to use it?
The goto statement is a control flow statement that transfers the control flow from one part of the program to another while skipping the current part. It is generally recommended to use structured control flow statements, which are more readable and easier to maintain. However, there are several scenarios where goto proves to be helpful.
3. What is function overriding?
Function overriding is an example of polymorphism invoked during compilation. It is the process in which a derived class and related base class are given the same function.
4. Explain the different types of preprocessor directives.
There are several preprocessor directives that can be used for file inclusion, conditional compilation, or macros management purposes. Some of the most common preprocessor directives that are used are #define, which creates a macro; #undef, which undefines macros; and #pragma, which turns specific special purpose features on or off.
5. How is variable declaration different from the variable definition?
Variable declaration provides basic information about a variable, like its name and value type, to the compiler. Variable definition provides complete information about the variable to the compiler, including its methods, fields, storage location, etc.
6. Differentiate between a list and a vector.
In lists, elements are stored in non-contiguous memory locations. Lists also do not allow random access and are not thread safe. In vectors, elements are stored in contiguous memory locations. Vectors also provide random access and are thread safe.
7. What is the strcmp function in C++, and how is it used?
The strcmp function is used for the lexicographic comparison of two null-terminated strings. The header file must be included in the program to use the strcmp function.
8. How to verify and locate a suspected memory leak while debugging a C++ program?
The interview round gives recruiters the opportunity to assess a candidate on a deeper level. The C++ interview questions help recruiters gauge the depth of the candidate’s knowledge and proficiency in C++.
However, for an interview round to be effective, it is important to personalize the C++ interview questions to be asked based on seniority and the individual skills of different candidates. C++ interview questions for beginners or freshers should focus on basic C++ knowledge and on assessing the soft skills of the candidates.
The C++ interview questions for intermediate professionals with more experience should be more challenging and should test their technical skills and knowledge of the more complex concepts of the programming language.
The C++ interview questions for advanced professionals who are well-experienced in the field should delve into the most intricate concepts and functions of C++. The questions should also assess the abilities of the candidate beyond their technical proficiency, including their advanced C++ capabilities, senior position experience, experience in working on large-scale projects, and management experience.
Mercer | Mettl offers an expansive library of pre-employment assessments and tests to optimize the recruitment processes and identify top talent. Mercer | Mettl also offers C++ skills tests that can help evaluate candidates on their knowledge and expertise in the programming language. It helps assess the knowledge that candidates have in the basic concepts of C++, object-oriented programming, advanced C++ concepts, programming concepts, and their experience with hands-on programming.
The tests offered by Mercer | Mettl have been curated by subject matter experts and are scientifically validated for objectivity and accuracy. Choose from a range of personality tests, behavioral assessments, and other role-specific skills tests based on the hiring needs to perfect the candidate screening and hiring processes.
Regardless of the job role, recruitment has always been a complex process. When it comes to more technical job roles that require a coding language like C++, a well-planned and robust selection process is required to identify and hire the best C++ developers.
Originally published November 21 2024, Updated November 21 2024
Hiring a coder requires HRs to go beyond conventional hiring practices and assess the candidate on both knowledge and hands-on skills. A holistic suite of assessments and simulators, used in conjunction, can simplify the technical hiring process and better evaluate programmers and developers.
Thanks for submitting the comment. We’ll post the comment once its verified.
Would you like to comment?