
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
NULL pointer in C
A null pointer is a pointer which points nothing.
Some uses of the null pointer are:
a) To initialize a pointer variable when that pointer variable isn’t assigned any valid memory address yet.
b) To pass a null pointer to a function argument when we don’t want to pass any valid memory address.
c) To check for null pointer before accessing any pointer variable. So that, we can perform error handling in pointer related code e.g. dereference pointer variable only if it’s not NULL.
Algorithm
Begin. Declare a pointer p of the integer datatype. Initialize *p= NULL. Print “The value of pointer is”. Print the value of the pointer p. End.
Example
#include <stdio.h> int main() { int *p= NULL;//initialize the pointer as null. printf("The value of pointer is %u",p); return 0; }
Output
The value of pointer is 0.
- Related Articles
- Null Pointer Exception in C#
- Differentiate the NULL pointer with Void pointer in C language
- Calling class method through NULL class pointer in C++
- Null Pointer Exception in Java Programming
- Why is address zero used for the null pointer in C/C++?
- Calling a member function on a NULL object pointer in C++
- Why do we check for a NULL pointer before deleting in C/C++?
- Double Pointer (Pointer to Pointer) in C
- What should we assign to a C++ pointer: A Null or 0?
- What is null pointer exception in Java and how to fix it?
- Pointer Arithmetic in C/C++
- Explain the concept of pointer to pointer and void pointer in C language?
- How to define pointer to pointer in C language?
- void pointer in C
- Function Pointer in C

Advertisements