Found 33676 Articles for Programming

Print system time in C++

Ankith Reddy
Updated on 28-Apr-2025 18:34:23

694 Views

In C++, the standard library does not provide any proper built-in date type. Instead of that we use structures and functions to inherit from the C language for the manipulation. To access this date and time related functions and structures, we need to include header file to the C++ program. There are four time-related types: clock_t, time_t, size_t, and tm. The types: clock_t, size_t and time_t are capable of representing the system time and date as some sort of integer. time_t: It is used to store calendar time (like the number of seconds since ... Read More

C++ Program to Check Whether a Given Tree is Binary Search Tree

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

353 Views

Binary Search Tree is a binary tree data structure in which we have 3 propertiesThe left subtree of a binary search tree of a node contains only nodes with keys lesser than the node’s key.The right subtree of a binary search tree node contains only nodes with keys greater than the node’s key.The left and right trees of a subtree each must also be a binary search tree.AlgorithmBegin    function BSTUtill()       If node is equals to NULL then          Returns 1.       If data of node is less than minimum or greater ... Read More

Early binding and Late binding in C++

George John
Updated on 28-Apr-2025 18:35:32

16K+ Views

In C++, binding is the process of connecting names such as variables and functions to their actual memory locations. When you intend to call a function, the program must identify the proper function definition for the execution. So, binding is the process of making this connection. This happens either at compile time (early binding) or at runtime (late binding). Early Binding This is compile time polymorphism and decides which function to call before it runs, making execution faster and direct. Example In this example, we demonstrate the early binding, where the base class function runs instead of the derived class ... Read More

fabs() in C++

Chandu yadav
Updated on 29-Apr-2025 11:32:37

603 Views

In C++, fabs is used to calculate the absolute value of a floating-point number. It is a function and defined to a header file. The fab() FunctionThis fabs() function accepts one argument, which is a floating-point number (double, float, or long double), and returns its absolute value as a floating-point number of the same type. Syntax Following is the syntax to fabs() function: double fabs(double x); The fabs() function is mostly used when we need to find the non-negative magnitude of a number. Using fabs() with positive and negative values Here, we will demonstrate how fabs() handles ... Read More

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

351 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

387 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

Advertisements