Inheritance and types of Inheritance in C++

Inheritance is one of the most important features of object-oriented programming. Inheritance allows an object of one class to acquire the properties of another object of another class. It supports reusability and supports hierarchical classification.  The class that inherits the other class is called the derived class and the class that inherited is called the … Read more

Categories C++

Friend Function in C++

In a C++ programming language private member of the class can accessed by member function. Any non-member function can’t access private data member of the class. But if we want to access the private data in non member function it is still possible by using the “friend function”. A friend function can access private data … Read more

Categories C++

Functions in C++

In a C++ programming language a function is a group of statements that together perform a special task. Every C++ program has at least one function, which is main(). In a C++ library has a numerous predefined or built-in functions. For example, strcat() to concatenate two strings, main() from where program execution starts.  In a C++  programming function … Read more

Categories C++

Recursion in C++

In a C programming language, a function that calls itself is known as a recursive function. And, this technique is called as recursion.  Recursive functions are very useful to solve many problems such as  Towers of Hanoi (TOH), Inorder/Preorder/Postorder Tree Traversals, DFS of Graph, etc. How recursion works?

Example: Write a program in a … Read more

Categories C++

Virtual Function in C++

In a C++ programming language, A virtual function is a member function that is declared and defined within a base class and redefined by a derived class even if the number and type of argument are matching.   Rules for Virtual Function:  A virtual function may be declared as friend for another class.   Constructor cannot be … Read more

Categories C++

Virtual Base Class in C++

In a C++ programming language to overcome the ambiguity problem occurred due to multipath inheritance we use “virtual” keyword. By using the “virtual” keyword we can declares the specified class virtual.  When a class declared as virtual, then the compiler takes necessary precaution to avoid the duplication of member variable. We can make a class … Read more

Categories C++

Function Overloading in C++

  In C++  language, we can create more than one function with the same name but each function must have a different parameter list. Such functions are called overloaded functions and this process is known as function overloading. Function overloading is an example of polymorphism. Polymorphism means one function has many forms.    Example of … Read more

Categories C++

Single and Multidimensional Arrays in C++

Arrays is a kind of data structure that can store a elements of the same type. Arrays stores the elements in a contiguous memory locations. Array is a collection of variables of the same type.  For example: we want to declare 100 integer variable Instead of declaring 100 individual variables, such as int number0, number1,number2,number3, … Read more

Categories C++

File Handling in C++

File In a computer system files are used to store the necessary information / data stored. There are mainly two types of files: Text file Binary file Text file. It stores information/data in ASCII characters. In text files, each line of text is terminated with a special character known as EOL (End of Line) character. … Read more

Categories C++

Exception Handling in C++

In C++ programming, an exception is an abnormal condition that arises/occurs in a source code during run time.   Or  Exception is a run time error.   Example:

Output

When we try to compile this program we will receive an error message because value of 100/a (100/0) is infinite and it can’t be possible to … Read more

Categories C++