Found 7197 Articles for C++

isnormal() in C++

Smita Kapse
Updated on 30-Jul-2019 22:30:26

123 Views

In this section we will see the isnormal() function in C++. This function is present in the cmath library. This function is used to check whether a number is normal or not. The numbers that are considered as non-normal are zeros, infinity or NAN.This function takes float, double or long double values as argument. Returns 1 if the number is normal, otherwise returns 0.Example Live Demo#include #include using namespace std; int main() {    cout

Foreach in C++ and Java

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

167 Views

In C++ and Java, there are another type of loop called foreach loop. This is not present in C. This loop has introduced in C++11 and Java JDK 1.5.0. The advantage of this loop is that, it can access the elements very quickly without performing initialization, testing and increment/decrement. This loop is used to access every element in one array or some containers. This loop is known as foreach but to denote this loop we have to use ‘for’ keyword. The syntax is different than normal for and foreach.for(datatype item : Array) { }Let us see some examples of foreach ... Read More

Comparison of Exception Handling in C++ and Java

Smita Kapse
Updated on 30-Jul-2019 22:30:26

292 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

Write a program that produces different results in C and C++

Anvi Jain
Updated on 30-Jul-2019 22:30:26

125 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

C program that won’t compile in C++

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

506 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

What is the difference between iostream and iostream.h in C++?

Tapas Kumar Ghosh
Updated on 16-Jun-2025 17:07:37

1K+ 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

When to use inline function and when not to use it in C/C++?

Tapas Kumar Ghosh
Updated on 11-Jul-2025 17:48:27

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

What are the rules for calling the superclass constructor C++?

Tapas Kumar Ghosh
Updated on 01-Jul-2025 15:09:39

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

How to stop C++ console application from exiting immediately?

Anvi Jain
Updated on 30-Jul-2019 22:30:26

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

C++ Program to Implement Johnson’s Algorithm

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

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

Advertisements