Category: C++ Interview Questions
When to use virtual functions in C++?
When we want a Derived Class to override a member function of Base class, then we should make that member function in Base class virtual. So that if someone uses the Derived class object using Base class’s pointer or reference to call the overridden member function, then function of derived class should be called. Suppose draw() is …
Object Oriented Approach to Display a sequence of numbers without any For-Loop or Recursion
Suppose we have to display a sequence of numbers like from 10 to 20 i.e. 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 Advertisements without using any for-loop and recursion. Solution: Frequently Asked: Object Oriented Approach to Display a sequence of numbers without any For-Loop or Recursion We will use two concepts …
Object Oriented Approach to Display a sequence of numbers without any For-Loop or RecursionRead More
How virtual functions works internally using vTable and vPointer?
In this article we will discuss that how virtual functions in C++ works internally using vTable and vPointer. If you are not clear on what is virtual function and in which scenarios we need them, then we suggest you to go through this article first, Advertisements https://ownyourlife.com.ng//when-should-i-use-virtual-functions-in-c/ virtual functions is based on run time binding. So, let’s …
How virtual functions works internally using vTable and vPointer?Read More
Using STL to verify brackets or parentheses combination in an expression
In this we will see how to check if a given string take valid combination of open and close brackets i.e. (4+{8-[22+8]*}] contains valid order of open and close brackets. ({5+8]) contains invalid combination of open and close brackets. Advertisements [showads ad=inside_post] Bracket combinations to be used, Frequently Asked: Using STL to verify brackets or parentheses combination in an …
Using STL to verify brackets or parentheses combination in an expressionRead More
Designing Code to Convert the base of a Number to any other base in Number System
In this article we will discuss how to design a Class that represents the Number in a Number System and also provides the facility to convert the Base associated with that Number i.e. conversion from any Base to any other base like, octal to hexa or hexa to decimal etc. [showads ad=inside_post] Create a class Number that …
Designing Code to Convert the base of a Number to any other base in Number SystemRead More
Designing Code for Fibonacci Sequence without Recursion
What’s a Fibonacci sequence: Fibonacci sequence is a kind of sequence in which every subsequent number is sum of the previous two numbers i.e. 0,1,1,2,3,5,8,13,21,34,55,89,144 Advertisements Designing Code for Fibonacci sequence: Frequently Asked: Unary Operator Overloading in C++ using both member & Friend function What is a Memory Leak in C++ ? When to use virtual …
Designing Code for Fibonacci Sequence without RecursionRead More
Allocating and deallocating 2D arrays dynamically in C and C++
In this article we will see how to allocate and deallocate 2D arrays dynamically using new / delete and malloc / free combinations. Suppose we want to create a 2D array using pointers on heap either using new or malloc. It should function like this, Advertisements int row = 2; int col = 3; int ** …
Allocating and deallocating 2D arrays dynamically in C and C++Read More
Differences between a pointer and reference
Differences Between Pointer and Reference in C++ are as follows, 1.) Reference is a kind of const pointer that de-reference itself automatically. Yes, its similar to const pointer therefore once you have attached a reference to a variable or object then you cannot make it to point to someone else. Advertisements Now if you try to …
Designing Callbacks in C++ – Part 1: Function Pointers
In this article we will discuss what is a callback and what types of callbacks we can have in C++ and how to Design Callbacks as function pointers. Now what is a callback? Advertisements Callback is a function that we pass to another APIs as argument while calling them. Now these APIs are expected to …
Designing Callbacks in C++ – Part 1: Function PointersRead More
Designing Callbacks in C++ – Part 2: Function Objects & Functors
In this article we will discuss, what is a Function Object, why do we need function objects and how to use function objects as Callbacks. What is a Function Objects: Advertisements A Function Object / Functor is a kind of Callback with State. In a Programmer’s terminology, Frequently Asked: Designing Callbacks in C++ – Part …
Designing Callbacks in C++ – Part 2: Function Objects & FunctorsRead More