Found 7197 Articles for C++

exit() vs _Exit() function in C and C++

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

459 Views

In this section we will see what are the differences between exit() and _Exit() in C and C++. In C the exit() terminates the calling process without executing the remaining code which is present after exit() function.In C++11, one new function is present called _Exit(). So what is the feature of this function? The exit() function performs some cleaning before terminating the program. It clears the connection termination, buffer flushes etc. This _Exit() function does not clean anything. If we test using atexit() method, it will not work.Let us see two examples where at first we are using exit() function, ... Read More

2D vector in C++ with user defined size

Aman Kumar
Updated on 24-Jul-2025 15:33:39

3K+ Views

In this article, we will see how we create and use 2D vectors with user-defined sizes. What is 2D Vector? In C++, a vector is a dynamic array used to store elements. The 2D vector is a vector of vectors and are used to create a dynamic two-dimensional array where the number of rows and the number of columns in each row can vary. Just like a 2D array, a 2D vector is used to store data in a tabular form such as matrices, grids, or tables. Structure of a 2D Vector A 2D vector is declared as: vector v; ... Read More

C++ Program to Find Lowest Common Ancestor in a Binary Search Tree

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

497 Views

A binary tree which has at most two children, specified as left child and right child. This is a C++ Program to find the lowest common ancestor in a Binary Tree.AlgorithmBegin Create a structure n to declare data d, a left child pointer l and a right child pointer r.    Create a function to create newnode. Call a function LCA() to Find lowest common ancestor in a binary tree:    Assume node n1 and n2 present in the tree.    If root is null, then return.       If root is not null there are two cases.   ... Read More

C++ Program to Find Deepest Left Leaf in a Binary Tree

Samual Sam
Updated on 30-Jul-2019 22:30:25

201 Views

A binary tree which has at most two children, specified as left child and right child. This is a C++ Program to Find Deepest Left Leaf in a Binary TreeAlgorithmBegin.    function deepestLLeafutil() find the deepest left leaf in a given    binary tree:         lvel is level of current node.       maxlvel is pointer to the deepest left leaf node found so far         isLeft Indicates that this node is left child of its parent         resPtr is Pointer to the result         If root is equal to Null ... Read More

C++ Program to Construct an Expression Tree for a Postfix Expression

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

2K+ Views

An expression tree is basically a binary tree which is used to represent expressions. In expression tree, nodes correspond to the operator and each leaf node corresponds to the operand. This is a C++ program to construct an expression tree for a postfix Expression in inorder, preorder and postorder traversals.AlgorithmBegin    Function r() has a character variable as parameter.       If the characters are + or - or * or / then          Return will be -1       If the characters are from A to Z then          Return will ... Read More

C++ Program to Check Whether an Input Binary Tree is the Sub Tree of the Binary Tree

Samual Sam
Updated on 30-Jul-2019 22:30:25

247 Views

A binary tree is a tree data structure in which each node has at most two children, which are defined as left child and right child.AlgorithmBegin    function identical():        Take two nodes r1 and r2 as parameter.       If r1 and r2 is NULL then          Return true.       If r1 or r2 is NULL then          Return false.       Return (r1->d is equal to r2->d and          Call function Identical(r1->l, r2->l) and          Call functions Identical(r1->r, r2->r) ); ... Read More

Print system time in C++

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

693 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

351 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

602 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

Advertisements