Programming Articles - Page 2751 of 3366

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

392 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

C++ Program to Implement Jarvis March to Find the Convex Hull

Nitya Raut
Updated on 29-Apr-2025 19:42:07

1K+ Views

A convex hull is the smallest convex polygon with maximum area and minimum perimeter that encloses all the given points in a 2D plane. In this article, we will learn how to write C++ program to implement Jarvis March Algorithm to find a convex hull. The objective of this problem is to take a set of x and y coordinates of a 2d plane as input, and display coordinate point from the set which are part of convex hull. // Input Set of points: {0, 0}, {1, 1}, {2, 2}, {2, 0}, {1, 2}, {0, 2} // Output ... Read More

C++ Program to Implement Graham Scan Algorithm to Find the Convex Hull

Nitya Raut
Updated on 29-Apr-2025 19:43:58

4K+ Views

A convex hull is the smallest convex polygon with maximum area and minimum perimeter that encloses all the given points in a 2D plane. In this article, we will learn how to write C++ program to implement Graham Scan Algorithm to find convex hull. The objective of this problem is to take a set of x and y coordinates of a 2d plane as input, and display coordinate point from the set which are part of convex hull. // Input Set of points: {0, 0}, {1, 1}, {2, 2}, {2, 0}, {1, 2}, {0, 2} // Output Boundary ... Read More

C++ Program to Implement Adjacency Matrix

Vrundesha Joshi
Updated on 28-Apr-2025 18:17:51

15K+ Views

The adjacency matrix of a graph is a square matrix of size V x V, that represent a finite graph data structure using a 2D array, where V is number of edges of the graph. The each non zero elements in the matrix represent an edges of the graph. For example, if the graph has some edges from i to j vertices, then in the adjacency matrix at i th row and j th column it will be 1 (or some non-zero value for weighted graph), otherwise that value will be 0. In this article, we will learn how to ... Read More

C++ Program to Implement Adjacency List

Jennifer Nicholas
Updated on 28-Apr-2025 18:18:09

12K+ Views

An adjacency list of graph is a collection of unordered lists, that represents a finite graph data structure using linked lists. Each list in the collection represents one of the vertex of the graph and it will store the adjacent vertices of that vertex. In this article we will learn how to implement adjacency list for a graph using C++ program. First of all, let's see an example of adjacency list. Example of Adjacency List To understand what is an adjacency list is, first we need to take a graph data structure for reference. The image below represent a ... Read More

C++ Program to Implement Stack

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

11K+ Views

In this program we will see how to implement stack using C++. A stack is an abstract data structure that contains a collection of elements. Stack implements the LIFO mechanism i.e. the element that is pushed at the end is popped out first. Some of the principle operations in the stack are −Push - This adds a data value to the top of the stack.Pop - This removes the data value on top of the stackPeek - This returns the top data value of the stackA program that implements a stack using array is given as follows.Input: Push elements 11, ... Read More

Advertisements