C++ Technical Interview Question on polymorphism in oops Interviewer Intent: NOTE: As per question criteria, we will write code using interface, but, to describe the concept a basic example will be covered first. Answer: Function overriding concept is run time polymorphism in oops, in which functions get resolved on run time using VTABLE (Virtual table) […]
How to delete array of objects in C++? Proof by C++ code for proper deletion
Answer includes how to delete array of objects in C++ created dynamically with C++ code example with proof. In other words, delete array of pointers to objects in c++. Interview Question: Write C++ code to create an array of objects using new keyword and delete these objects. Also, proof that all the objects are deleted […]
How to stop class inheritance in C++ with condition that object creation should be allowed
Answer includes multiple solutions to stop or prevent class inheritance in C++ with condition that object creation of the class should be allowed with C++ program example and explanation. Interview Question: I want to stop a class to be inherited and allow to create an object of the class. Design a solution for this problem […]
What is Advantage and Use of THIS pointer in C++ – Scenarios?
Answer includes uses and advantage of the this pointer in C++ programming with multiple scenarios where the this pointer is used. Sceranio-1: Internal use of this pointer as an argument to a function. Wherever an object calls a class member function, then the compiler internally passes a “this” pointer to the member function internally. For […]
Can we use THIS Pointer in static function – Reason in C++?
We cannot use THIS pointer in static function of a class in C++ program. Reason: Whenever we call a class non-static member function using class object then THIS pointer is also passed to the function as a parameter internally and this is why a non-static member function of a class know that on which class […]
C++ Public access specifier instead of Private – What is bad?
Interview Question: A class is having private data members and that is by design and expected. Question is, if we write C++ public access specifier instead of private for that data members then what issue we can face in a C++ program? If you want to know access specifiers in C++ programming, read another interview […]
Use of Public Private and Protected access specifiers in C++?
Answer: Use of public private and protected access specifiers in C++ is to control the access/visibility of member data and functions out of a class. It all depends upon requirement when we design a class, what access level to fields and member functions, we want to provide in a class with the use of public private […]
What if memory allocation using new fails in C++ how to handle
Interview Question on memory allocation failure in C++: when you do memory allocation using new in C++ and it fails then what are issues? In another words, when you allocate memory on heap using new operator, how do you handle memory allocation using new in C++ failure? What is issue when you don’t handle it? […]
When to use RTTI – Dynamic_cast in C++
When to use RTTI (Run Time Type Information) dynamic_cast in C++ is frequently asked c++ technical interview question. Answer to this question will cover multiple scenarios where we can use dynamic_cast in C++ program. Answer: Scenarios – Use of Dynamic_cast in C++ program: Situation 1- When we need to call a specialized member function of […]
Writing Smart Pointer in C++ for a Specific Class
What is smart pointer and implementation of Smart pointer in C++. This simple smart pointer implementation in C++ is asked in technical interview to know if we know the concept of smart pointer and able to implement it. Answer: Smart pointers are a pointers that get de-allocated by itself, when it goes out of scope and […]