Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ Articles - Page 599 of 717
330 Views
The exception handling feature is present almost any object oriented languages nowadays. In C++ and Java also we can get this kind of feature. There are some similarities between exception handling in C++ and exception handling in Java, like in both languages we have to use the try-catch block. Though there are some difficulties also. These are like below −In C++, we can throw any type of data as exception. Any type of data means primitive datatypes and pointers also. In Java we can only throw the throwable objects. Subclasses of any throwable class will also be throwable.Example Live Demo#include ... Read More
156 Views
Here we will see some program that will return different results if they are compiled in C or C++ compilers. We can find many such programs, but here we are discussing about some of them.In C and C++, the character literals are treated as different manner. In C, they are treated as int but in C++, they are treated as characters. So if we check the size using sizeof() operator, it will return 4 in C, and 1 in C++.Live Demo For C.Example Live Demo#include int main() { printf("The character: %c, size(%d)", 'a', sizeof('a')); }Output(C)The character: a, size(4)Live Demo For ... Read More
532 Views
The C++ language is designed by adding some additional features like Object Oriented concepts with C. Most of the C programs can be compiled using C++ compiler also. Though there are some programs that cannot be compiled using C++ compiler.Let us see some code, that will compile in C compiler, but not in C++ compilers.In this program there will be one compilation error for C++ code. Because it is trying to call a function that is not declared before. But in C it may compileLive Demo For C.Example Live Demo#include int main() { myFunction(); // myFunction() is called before its ... Read More
2K+ Views
Both and are the header files of C++ language. The .h extension was common in older, non-standard implementations like Turbo C++. The has been deprecated in modern C++ compilers and the became part of the C++ standard starting from the 1998 ANSI/ISO standard. The Header File The iostream.h header file was part of the early 1990s I/O streams library, developed at AT&T for use with early C++. At that time, C++ was not yet standardized. The purpose of this header file is used to perform the input-output operations. Example Following is an example of iostream.h as per ... Read More
2K+ Views
In C/C++, an inline function is a function where the compiler replaces the function call with the actual code of the function during compilation. So, this makes the program run faster than a normal function call. Why to Use Inline Function in C/C++? We should use an inline function in C/C++ when the function is very simple and small size. Also, avoid the regular function call and replace macros with type safety. Let us understand how an inline function is used for small functions. Suppose we write square(5), the compiler converts it directly to 5*5. This makes the program run ... Read More
12K+ Views
In C++, a superclass serves as a base/parent class. When we create a derived class (or child class) from a superclass, sometimes we have to call the constructor of the base class along with the constructor of the derived class. Unlike Java, there is no reference variable for the superclass. If the constructor is non-parameterized, then it will be called automatically with the derived class, otherwise, we have to put the superclass constructor in the initializer list of the derived class. Constructor Without Arguments It is a default constructor where no argument is passed to it. Here, we create a ... Read More
1K+ Views
Sometimes we have noticed that the console is being closed immediately after displaying the result. So we cannot see the result properly. Here we will see how we can stop the console from closing.The idea is very simple. We can use the getchar() function at the end. This will wait for one character. If one character is pressed, the console will exit.Example Live Demo#include using namespace std; int main() { cout
1K+ Views
Here we will see the Johnson’s Algorithm to find shortest path between two vertices. The graph is given here. The shortest path between the edges is like below. This program will take the number of vertices, number of edges, and the edges with their costs.Input − Vertices: 3Edges: 5Edge with costs −1 2 82 1 121 3 223 1 62 3 4Output − The distance matrix of the graph.081210046140AlgorithmjohnsonAlgorithm(cost)Input − The cost matrix of given Graph.Output − Matrix to for shortest path between any vertex to any vertex.Begin Create another matrix ‘A’ same as cost matrix, if there is no ... Read More
181 Views
Here we will see how to create Random Linear Extension of a Directed Acyclic Graph (DAG). The Linear extension is basically the topological sorting of DAG. Let us consider the graph is like below −The topological sorting for a directed acyclic graph is the linear ordering of vertices. For every edge u-v of a directed graph, the vertex u will come before vertex v in the ordering.As we know that the source vertex will come after the destination vertex, so we need to use a stack to store previous elements. After completing all nodes, we can simply display them from ... Read More
490 Views
Here we will see the concept of Bidirectional iterators in C++.The bidirectional iterators support all of the features of forward iterators, and also prefix and postfix decrement operators.This type of iterator can access elements in both directions, like towards the end and towards the beginning.The random access iterator is also a type of bidirectional iterator.Bidirectional iterators have features of forward iterator, but only difference is this iterator can also be decremented.The Bidirectional iterators has some properties. These are like below.PropertyExpressionThe bidirectional iterator is default-constructible, copy-assignable, and also destructibleA pA q(p) q = pWe can compare them using equality and inequality operatorsp ... Read More