We use a null pointer when we do not have the exact address to assign to a pointer. It is considered a good practice and null is assigned at the time of declaration. Therefore the pointer with a null value is called a null pointer.
Check the C++ example for the null pointer.
| #include <iostream> using namespace std; int main () { int *ptr = NULL; cout << "Value of NULL pointer: " << ptr ; return 0; } |
Output:
The value of null pointer is 0 as provided in many of the standard library.
We can also check the pointer for null before accessing it. By doing so we can perform error handling. We can do it in a following way.
| if (!ptr) { //if will be executed if pointer is not null .......... } else { ....... } |
In this tutorial, we will write various C pattern programs for String. Before that, you may go through the following topics in C. for loop …
Read MoreIn this tutorial, we will write a program to find a pair of elements from an array whose sum equals a given number in java …
Read MoreIn this tutorial, we will learn to write a C program to print Diamond patterns using alphabets/characters. However, in this tutorial, we will create a …
Read MoreIn this tutorial, we will learn and code the half diamond alphabet patterns in C programming language. However, in this tutorial, we will create a …
Read MoreIn this tutorial, we will learn and code alphabet patterns in C programming language specifically the Half pyramid of alphabets in C programming. However, in …
Read MoreIn this tutorial, we will write a C program to print half Pyramid using alphabets/characters. Before that, you may go through the following topic in …
Read More