- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7346 Articles for C++
6K+ Views
Following table shows the difference between Virtual and Pure Virtual Function:Virtual FunctionPure Virtual FunctionVirtual function has their definition in the class.Pure virtual function has no definition.Declaration: virtual funct_name(parameter_list) {. . . . .};Declaration: virtual funct_name(parameter_list)=0;It has no concept of derived class.If a class contains at least one pure virtual function, then it is declared abstract.If required, the base class can override a virtual function.In case of pure virtual function derived class has to definitely override the pure virtual function.virtual functionExample Code Live Demo#include using namespace std; class B { public: virtual void s() //virtual function { ... Read More
476 Views
The pure virtual destructor is possible in C++. If a class contains pure virtual destructor it is must to provide a function body for the pure virtual destructor.Example Code Live Demo#include using namespace std; class B { public: virtual ~B()=0; // Pure virtual destructor }; B::~B() { std::cout
2K+ Views
Virtual functions in C++ use to create a list of base class pointers and call methods of any of the derived classes without even knowing kind of derived class object. Virtual functions are resolved late, at the runtime.The main use of the virtual function is to achieve Runtime Polymorphism. The inline functions are used to increase the efficiency of the code. The code of inline function gets substituted at the point of an inline function call at compile time, whenever the inline function is called.Whenever a virtual function is called using base class reference or pointer it cannot be inlined, ... Read More
323 Views
Here we will see what is assertions in C/C++. The C library macro void assert(int expression) allows diagnostic information to be written to the standard error file. In other words, it can be used to add diagnostics in your C program.Following is the declaration for assert() Macro.void assert(int expression);The parameter of this assert() is expression − This can be a variable or any C expression. If expression evaluates to TRUE, assert() does nothing. If expression evaluates to FALSE, assert() displays an error message on stderr (standard error stream to display error messages and diagnostics) and aborts program execution.Example Code#include ... Read More
140 Views
In this section we will see how to execute the if and else section simultaneously in a C or C++ code. This solution is little bit tricky.When the if and else are executed one after another then it is like executing statements where if-else are not present. But here we will see if they are present how to execute them one after another.Example Code#include using namespace std; int main() { int x = 10; if(x > 5) { lebel_1: cout
20K+ Views
AVL tree is a self-balancing Binary Search Tree where the difference between heights of left and right subtrees cannot be more than one for all nodes.Tree rotation is an operation that changes the structure without interfering with the order of the elements on an AVL tree. It moves one node up in the tree and one node down. It is used to change the shape of the tree, and to decrease its height by moving smaller subtrees down and larger subtrees up, resulting in improved performance of many tree operations. The direction of a rotation depends on the side which ... Read More
1K+ Views
In this section we will see what are the differences between *ptr++, *++ptr and ++*ptr in C++.Here we will see the precedence of postfix++ and prefix++ in C or C++. The precedence of prefix ++ or -- has higher priority than dereference operator ‘*’ and postfix ++ or -- has priority higher than both prefix ++ and dereference operator ‘*’.When ptr is a pointer, then *ptr++ indicates *(ptr++) and ++*prt refers ++(*ptr)Example Code Live Demo#include using namespace std; int main() { char arr[] = "Hello World"; char *ptr = arr; ++*ptr; cout
875 Views
A hash table is a data structure which is used to store key-value pairs. Hash function is used by hash table to compute an index into an array in which an element will be inserted or searched.Linear probing is a collision resolving technique in Open Addressed Hash tables. In this method, each cell of a hash table stores a single key–value pair. If a collision is occurred by mapping a new key to a cell of the hash table that is already occupied by another key. This method searches the table for the following closest free location and inserts the ... Read More
1K+ Views
This is a simple example of throwing exceptions from C++ constructorsAlgorithmClass descriptions and pseudocodes:Begin Declare a class sample1. Declare a constructor of sample1. Print “Construct an Object of sample1” Declare a destructor of sample1. Print “Destruct an Object of sample1” Declare a class sample. Declare a constructor of sample2. Declare variable i of the integer datatype. Initialize i = 7. Print “Construct an Object of sample1”. ... Read More
2K+ Views
A hash table is a data structure which is used to store key-value pairs. Hash function is used by hash table to compute an index into an array in which an element will be inserted or searched. Quadratic probing is a collision resolving technique in Open Addressed Hash tables. It operates by taking the original hash index and adding successive values of an arbitrary quadratic polynomial until an open slot is found.This is a C++ program to Implement Hash Tables with Quadratic Probing.AlgorithmFor search a key value:Begin Declare function SearchKey(int k, HashTable *ht) int pos = ... Read More