C++ is a very common language which is used by the developer. But still there are many c++ question about which developer usually get confused and need answers for these. Below are few common c++ question whose answer, every developer like to search.
As previously shown, the community around certain programming languages share job search experiences and some common questions that recruiters ask when trying to fill a certain vacancy, so this time we will address what C ++ developers indicate.
Interviewers ask questions that are intended to investigate whether the candidate has knowledge of the subject, according to specialized pages, including:
1. Explain what is OOP?
This is the most popular question in a C ++ interview. Object-oriented programming (OOP) is a type of programming in which a programmer indicates the type of data for operations, functions, and data structures used in code, and also creates relationships between objects.
Object-oriented programming is mainly aimed at the implementation of real entities. These include: abstraction, encapsulation, inheritance, polymorphism, etc.
2. Differentiate #import and #include?
A common question in a C ++ interview. The #include operator is used in C ++ to include the source file or import file headers containing declarations of functions and other constructs that will be shared in the program. The #import operator is a Microsoft-specific operator used in binary libraries such as DLLs or Libs . It is very similar to #include, because it loads all function and header definitions from a DLL file , and the developer can use headers in the same way as with #include.
3. What is a static element?
Static is a keyword used to give an element unique characteristics. To store static elements, memory is allocated only once during the entire program life cycle. Such elements are similar to global variables, except for scope (public, private). With their help, you can limit its use.
Declared methods with the same name and parameters cannot be overloaded if any of them is static, plus a static function cannot be declared as const, volatile or const volatile.
4. How structure is different from class?
In C ++, a class is an extension of the structure used in PL. A class is a user-defined data type that binds data and dependent functions in a single block. The structure and class in C ++ are very different because the structure has limited functionality and capabilities compared to the class. A structure is also a user-defined data type with a specific template and can contain both methods and classes.
5. What new() is different from malloc()?
New () is the preprocessor, while malloc () is the method. The user does not need to allocate memory when using “new “, and in malloc (), the sizeof () function must be used to allocate memory. “ New” initializes the new memory to 0, while malloc () stores a random value in a new allocated memory location.
6. What is this?
One of the most popular questions in a C ++ interview. The “this” keyword is passed to all non-static methods as a hidden argument and is available as a local variable inside all non-static methods. The “this” statement is a constant pointer that stores a reference to the current object in memory. It is not available in static functions, because they can be called without any object (using the class name).
7. Differentiate an array from a list?
An array is a collection of homogeneous elements, and a list is heterogeneous.
The memory allocation of the array is always static and continuous, and in the list it is all dynamic and random.
In the case of arrays, the user does not need to control the allocation of memory, but when using lists, it will have to, because of its dynamism.
8. What is dynamic and static typing?
Statically typed languages are languages in which type checking is performed at compile time, and in dynamically typed languages in runtime.
9. What is meant by a delegate?
A delegate is an object acting on behalf of, or paired with another object that detects an event during program execution. This is often just a pointer to a function that uses callbacks.
Delegates can be saved by the user. As a rule, they are saved automatically, so you can avoid unnecessary save cycles and not record again.
10. The Mutator Method. What is it?
The access function creates an element of type protected or private for external use, but it does not give permission to edit or modify it. Changing a protected data element always requires a mutator function call. The mutator provides direct access to protected data, so you must be very careful when creating the mutator and accessor functions.
11. Explain what is single and multiple inheritance?
Inheritance allows you to define a class that has a specific set of characteristics (for example, methods and instance variables), and then create other classes derived from this class. A derived class inherits all the functions of the parent class and usually adds some native functions.
Constructors of inherited classes are called in the same order in which the base classes are inherited.
12. Can a built-in function be recursive?
Although the user can call the built-in function from himself, the compiler will not be able to generate the built-in code, because it will not be able to determine the depth of the recursion during compilation. A compiler with a good optimizer can embed recursive calls to some fixed depth during compilation, and also insert non-recursive calls for cases when the actual depth is exceeded in runtime.
13. What is abstraction? How is it different from encapsulation?
Abstraction is a mechanism for providing only interfaces, hiding information about the implementation, and “showing” the necessary details of the functionality. Encapsulation can be understood as hiding properties and methods from the outside world. A class is the best example of encapsulation in C ++.