Found 7197 Articles for C++

Zombie and Orphan Processes in Linux

Revathi Satya Kondra
Updated on 06-May-2025 18:51:16

8K+ Views

Every program runs as a process in Linux operating system. When a process ends or gets disconnected from its parent, special types of processes can be created. These processes are known as zombie and orphan processes. Details about the zombie and orphan processes are given as follows: Zombie Processes A zombie process is a process whose execution is completed but it still has an entry in the process table. Zombie processes usually occur for child processes, as the parent process still needs to read its child's exit status. Once this is done using the wait system call, the zombie process ... Read More

Copy-and-Swap Idiom in C++

Revathi Satya Kondra
Updated on 22-Apr-2025 19:08:35

350 Views

The Copy and Swap Idiom in C++ is a technique used in assignment operations. This consists of two steps: Discarding an object's old state and building a new state for it. The destructor is used for the first step and a copy constructor does the second step. Implementing both of these is straightforward. But when overloading the assignment operator, it can become quite difficult to implement. The copy and swap idiom is a solution for the same. This idiom uses the copy-constructor to build a local copy of the data. It then swaps the old data with the new data ... Read More

Type Inference in C++

Revathi Satya Kondra
Updated on 22-Apr-2025 19:11:49

407 Views

Type inference (or, type deduction) refers to the automatic detection of the data type of an expression in a programming language. In C++, the auto keyword is used for automatic type deduction.For example, you want to create an iterator to iterate over a vector, you can simply use auto for that purpose.It is helpful, when dealing with complicated STL containers, iterators, and lambda functions where it may be hard to write the full type. This can be achieved using auto, decltype, and decltype(auto) keywords. These approaches help in letting the compiler understand the correct data types without explicitly declaring them. ... Read More

Strand sort in C++

Revathi Satya Kondra
Updated on 21-Apr-2025 18:17:18

386 Views

In C++, the strand sort is a recursive sorting algorithm. It is used to extract increasing subsequences repeatedly (called strands) from the input list and merge them into a sorted list. There are multiple libraries that can be used for different purposes. This sorting is one of them. This sorting technique is particularly good for sorting linked lists, but can be used with arrays too. The following is a list of approaches for strand sorting in C++: These approaches is to extract sorted strands (in increasing/descending order) from the unsorted list and merge them one by one into a final ... Read More

Sorting in C++

George John
Updated on 30-Jul-2019 22:30:25

2K+ Views

In this section we will see how to perform sorting algorithm in C++. A sorted array is an array in which each of the elements are sorted in some order such as numerical, alphabetical etc. There are many algorithms to sort a numerical array such as bubble sort, insertion sort, selection sort, merge sort, quick sort, heap sort etc. More details about sorting the array using selection sort are given below.The selection sort is a sorting method that yields a sorted array. It does so by repeatedly finding the smallest element in the array and interchanging it with the element ... Read More

Can namespaces be nested in C++?

Revathi Satya Kondra
Updated on 21-Apr-2025 19:24:03

281 Views

Yes, the namespace can be nested in C++. We can define one namespace inside another namespace. This makes it easier for developers to design a more structured and hierarchical format for their code. Syntax The following is the syntax as below : namespace namespace_name1 { // code declarations namespace namespace_name2 { // code declarations } } You can access members of a nested namespace by using resolution operators as follows: // to access members of namespace_name2 ... Read More

Namespace in C++

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

247 Views

Consider a situation, when we have two persons with the same name, Zara, in the same class. Whenever we need to differentiate them definitely we would have to use some additional information along with their name, like either the area, if they live in different area or their mother’s or father’s name, etc.Same situation can arise in your C++ applications. For example, you might be writing some code that has a function called xyz() and there is another library available which is also having same function xyz(). Now the compiler has no way of knowing which version of xyz() function ... Read More

C++ default constructor

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

245 Views

A class constructor is a special member function of a class that is executed whenever we create new objects of that class.A constructor will have exact same name as the class and it does not have any return type at all, not even void. Constructors can be very useful for setting initial values for certain member variables.Following example explains the concept of constructor −Example Live Demo#include using namespace std; class Line {    public:       void setLength( double len );       double getLength( void );       Line(); // This is the constructor       private:       double length; }; // Member functions definitions including constructor Line::Line(void) {    cout

C++ Program to Implement Min Heap

Nishu Kumari
Updated on 03-Mar-2025 13:16:55

12K+ Views

In this article, we will write a C++ program that implements a Min Heap. A Min Heap is a binary tree where the value of each node is less than or equal to the values of its children. We will explain how to create a Min Heap using arrays and implement operations like insertion and deletion. The article will cover the following topics: What is a Heap? Types of Heap Representing a Heap What is a Min Heap? What ... Read More

C++ Program to Implement Max Heap

Chandu yadav
Updated on 07-Mar-2025 15:35:32

14K+ Views

In this article, we will write a C++ program that implements a Max Heap. A Max Heap is a binary tree where the value of each node is greater than or equal to the values of its children. We will explain how to create a Max Heap using arrays and implement operations like insertion and deletion. The article will cover the following topics: What is a Heap? What is Max Heap? What is Heapify? Max Heap Implementation Deletion from ... Read More

Advertisements