Found 7197 Articles for C++

C++ Program to Perform Graph Coloring on Bipartite Graphs

Farhan Muhamed
Updated on 02-May-2025 18:27:53

544 Views

Graph coloring is a technique in which, we assign colors to the vertices of a graph such that no two adjacent vertices have same color. Bipartite graph a special kind of graph which is possible to color by just two colors. In this article, we will discuss how to perform graph coloring on a bipartite graph using BFS algorithm. What is Bipartite Graph? Bipartite graph is special graph where you can divide the vertices into two sets, such that no two vertices of the same set are connected. This is why, it's possible to color a bipartite graph by ... Read More

Is there a performance difference between i++ and ++i in C++?

Nitya Raut
Updated on 30-Jul-2019 22:30:25

908 Views

There is a big distinction between the suffix and prefix versions of ++.In the prefix version (i.e., ++i), the value of i is incremented, and the value of the expression is the new value of i. So basically it first increments then assigns a value to the expression.In the postfix version (i.e., i++), the value of i is incremented, but the value of the expression is the original value of i. So basically it first assigns a value to expression and then increments the variable.Let's look at some code to get a better understanding.Example Code#include using namespace std; int main() ... Read More

Difference between private, public, and protected inheritance in C++

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

3K+ Views

Data hiding is one of the important features of Object Oriented Programming which allows preventing the functions of a program to access directly the internal representation of a class type. The access restriction to the class members is specified by the labeled access modifiers: public, private, and protected sections within the class body.The default access for members and classes is private.Example Codeclass Base { public:     // public members go here protected: // protected members go here private:     ... Read More

Difference between \'struct\' and \'typedef struct\' in C++ program?

Farhan Muhamed
Updated on 26-May-2025 18:20:27

5K+ Views

In C++ program, struct is a keyword used to define a structure, while typedef is a keyword that is used to create an alias for a data type. In this article, we will discuss the difference between struct and typedef struct in C++. Struct in C++ Struct is a keyword used to define a structure in C++. A structure is a user-defined data type that groups related variables of different data types into a single unit. Struct is same as a class, but the members of a struct are public by default. The syntax for defining a struct is ... Read More

Regular cast vs. static_cast vs. dynamic_cast in C++ program

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

683 Views

static_cast − This is used for the normal/ordinary type conversion. This is also the cast responsible for implicit type coersion and can also be called explicitly. You should use it in cases like converting float to int, char to int, etc.dynamic_cast − This cast is used for handling polymorphism. You only need to use it when you're casting to a derived class. This is exclusively to be used in inheritance when you cast from base class to derived class.Regular Cast − This is the most powerful cast available in C++ as it combines const_cast, static_cast and reinterpret_cast. but it's also ... Read More

What does int argc, char *argv[] mean in C++?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

1K+ Views

The argc stands for argument count and argv stands for argument values. These are variables passed to main function when it starts executing. When we run a program we can give arguments to that program like:$ ./a.out helloHere hello is an argument to the executable. This can be accessed in your program.Example Code#include using namespace std; int main(int argc, char** argv) {    cout

What is a segmentation fault in C/C++ program?

Farhan Muhamed
Updated on 02-May-2025 18:27:39

1K+ Views

In C++, segmentation fault is a runtime error that occur when your program attempts to access an area of memory that it is not allowed to access. In other words, segmentation fault occur when your program tries to access memory that is beyond the limits that the operating system allocated for your program. These errors are type of access violation that can lead to crashing of program. Segmentation fault occur often with beginner programmers due to the lack of understanding of system level concepts like pointer. In this article, we will explain all the concepts related to segmentation fault, including ... Read More

How to pass objects to functions in C++ Program?

Farhan Muhamed
Updated on 02-May-2025 18:26:45

9K+ Views

The C++ functions can receive objects in multiple ways, depending upon how you want the function to interact with the object. You can either define functions that can modify the original objects or define functions that will make a copy of original object and modify the copy without affecting the original object. In this article, we will explain all the ways to pass an object a C++ function. Pass Objects to Function in C++ Here is the list of all the ways to pass an object to a function in c++ program, which we will be discussing ... Read More

How to detect integer overflow in C/C++?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

383 Views

The only safe way is to check for overflow before it occurs. There are some hacky ways of checking for integer overflow though. So if you're aiming for detecting overflow in unsigned int addition, you can check if the result is actually lesser than either values added. So for example, Example Codeunsigned int x, y; unsigned int value = x + y; bool overflow = value < x; // Alternatively "value < y" should also workThis is because if x and y are both unsigned ints, if added and they overflow, their values can't be greater than either of them ... Read More

C++ Program to Find the Longest Increasing Subsequence of a Given Sequence

Farhan Muhamed
Updated on 30-Apr-2025 20:33:38

1K+ Views

A subsequence is a sequence that can be derived from another sequence by deleting some elements and without changing the order of elements in sequence. For example, the sequences [3, 10], [3, 2, 20] and [3, 10, 20] are some of the subsequences of [3, 10, 2, 1, 20]. Longest Increasing Subsequence(LIS) is the longest of all the subsequences that are having elements in increasing order. In this article, we will learn how to write a C++ program to find the length of longest increasing subsequence for a given sequence. In other words, we are provided with a sequence ... Read More

Advertisements