Programming Articles - Page 2573 of 3366

C program that won’t compile in C++

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

516 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

C++ Program to Create a Random Linear Extension for a DAG

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

164 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

How to get a number of vowels in a string in JavaScript?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

2K+ Views

Calculating number of vowels in a stringVowels in English language are a, e, i, o and u. Make sure that, in any string these vowels can be both cases ( either small or capital). DebriefThe following example, using a user defined function called 'noOfVowels()', reads an input string and compares that string with another string which contains only vowels( 'aAeEiIoOuU'). It takes the help of indexOf() method to proceed the task. The indexOf() method displays index of a character whenever the character is common to both the strings, in unmatched case it displays '-1' as the output. Here it compares each and ... Read More

What are the differences between Widening Casting (Implicit) and Narrowing Casting (Explicit) in Java?

Shriansh Kumar
Updated on 20-May-2025 18:19:49

4K+ Views

A Type casting in Java is used to convert objects or variables from one data type to another. When we are converting or assigning one data type to another, automatic conversion will take place (if the types are compatible and the conversion is safe). However, if there is a risk of data loss, the conversion must be done explicitly by the programmer. Let's understand the types of Java type casting and the difference between them in this article. Types of Type Casting in Java Java Type Casting is classified into two types, which are: ... Read More

What are getters and setters methods in PHP?

Alok Prasad
Updated on 31-Dec-2019 08:57:06

15K+ Views

In this article, we learn the best way to create getter and setter strategies in PHP. Getter and setter strategies are utilized when we need to restrict the direct access to the variables by end-users. Getters and setters are methods used to define or retrieve the values of variables, normally private ones.Just as the name suggests, a getter method is a technique that gets or recovers the value of an object. Also, a setter method is a technique that sets the value of an object.ExampleLet's understand the use of getter and setter methods through an example.Output:PHP Error Cannot access private ... Read More

Advertisements