Why Address Zero is Used for Null Pointer in C/C++

Revathi Satya Kondra
Updated on 17-Jun-2025 14:27:30

662 Views

In C/C++, a null pointer is a special pointer that does not point to any valid memory location. Address 0 is used for Null Pointers because address 0 is reserved by the system, and it is guaranteed not to be used for valid data. So, when a pointer is assigned the value 0 (or nullptr), it means the pointer points to nothing. Some uses of null pointers are: To initialize a pointer variable when that pointer variable isn't assigned any valid memory address yet. To pass a null pointer to a function ... Read More

Writing a Binary File in C++

Revathi Satya Kondra
Updated on 17-Jun-2025 14:05:43

7K+ Views

The binary file stores data in binary format, and data can be written using the write() or fwrite() method in C++. Writing to a Binary File To write a binary file in C++, use write method like fwrite()/write() method. It is used to write a given number of bytes on the given stream, starting at the position of the "put" pointer. The file is extended if the put pointer is current at the end of the file. If this pointer points into the middle of the file, characters in the file are overwritten with the new data. If any error ... Read More

Remove Element from ArrayList or LinkedList in Java

Maruthi Krishna
Updated on 16-Jun-2025 19:03:21

846 Views

The ArrayList and LinkedList classes implement the List interface of the java.util package. This interface provided two variants of the remove() method to remove particular elements, as shown below - Using remove(int index) Using remove(Object o) There are two additional removal approaches provided by the Collection and Iterator interfaces. They are - ... Read More

Binary Search Functions in C++ STL: Lower Bound and Upper Bound

sudhir sharma
Updated on 16-Jun-2025 18:18:23

4K+ Views

Binary search is the fastest algorithm for finding an item from a sorted list of items. C++ STL provides built-in functions to perform binary search operations on sorted ranges of elements. In this article, we will learn binary_search, lower_bound and upper_bound functions in C++ STL. First of all, let's understand what binary search is. What is Binary Search? Binary search is a fast search algorithm with run-time complexity of (log n). This search algorithm works on the principle of divide and conquer, since it divides the array into half before searching. This algorithm works only on sorted collection of ... Read More

C++ Program to Implement Vizing's Theorem

Farhan Muhamed
Updated on 16-Jun-2025 18:14:31

283 Views

In this article, we will explain the Vizing's theorem and implement it in C++ to color a graph using the Greedy Coloring Algorithm. What is Vizing's Theorem? Vizing's theorem states that for any graph, the minimum number of colors needed to color the edges (chromatic index) is either equal to the maximum degree G of the graph or one more than maximum degree G + 1. The degree of a vertex is the number of edges connected to it. The maximum degree G refer to highest degree for any vertex in the graph. It is ... Read More

Check Cycle in a Graph Using Topological Sort in C++

Farhan Muhamed
Updated on 16-Jun-2025 18:14:11

459 Views

In this problem, we are given adjacency lists of a directed graph and we need to check if there is a cycle in the graph using topological sort. If a cycle exists, it is not possible to perform a topological sort. Example: // Input Graph ( as adjacency list ) 0 -> 1 1 -> 2 1 -> 3 2 -> 0 Output: Cycle exists Explanation: The graph has a cycle (0 -> 1 -> 2 -> 0). To solve this problem, we can use Khan's Algorithm, which is a BFS based topological sorting algorithm. To ... Read More

C++ Program to Implement Threaded Binary Tree

Farhan Muhamed
Updated on 16-Jun-2025 18:10:10

4K+ Views

Threaded binary tree is a binary tree that provides the facility to traverse the tree in a particular order. In this article, we will learn all about threaded binary trees, their types, and how to implement them in C++. What is a Threaded Binary Tree? A threaded binary tree is a type of binary tree in which NULL pointers are replaced with pointers to the in-order predecessor and successor nodes. This treading will help in faster traversal of the tree without using a stack or recursion. The image below shows a threaded binary tree. There are two types ... Read More

Find All Forward Edges in a Graph using C++

Farhan Muhamed
Updated on 16-Jun-2025 18:09:57

318 Views

In this article, we will learn how to write an algorithm an C++ code to find all forward edges in a directed graph. What is a Forward Edge? A forward edge is an edge in a directed graph that points from a node to one of it's descendants in the depth-first search (DFS) tree. To understand this concept better, consider the image of a directed graph below: In the above graph, the edge from node 2 to node 5 is a forward edge because to reach node 5 in DFS traversal, we need to move through node ... Read More

Check If Three Points Lie on a Single Line in C++

Farhan Muhamed
Updated on 16-Jun-2025 18:09:45

812 Views

In this problem, you are given three coordinates in a 2D plane, and you need to check if these three points are collinear, meaning they lie on a single straight line. There are two approaches to solve this problem. In this article, we will explain both the approaches with example code in C++. // Input: Coordinates of three points points = {{2, 3}, {4, 6}, {6, 9}}; // Output The points are collinear. Check if Three Points are Collinear If three points lie on a single line, then the points are called as collinear points. ... Read More

Duality Transformation of Line and Point in C++

Farhan Muhamed
Updated on 16-Jun-2025 18:09:29

242 Views

The duality transformation is concept in computational geometry that maps coordinate points to lines and lines to coordinate points. In this article, we will learn all about the duality transformation of lines and points, and implement C++ code to show this transformation. What is Duality Transformation? The duality transformation is a process that converts 2 dimensional lines and coordinates into dual plane. In this transformation, a point in the 2D plane can be represented as a line in the dual space, and a line in the 2D plane can be represented as a point in the dual space. This ... Read More

Advertisements