
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Why is address zero used for the null pointer in C/C++?
Null pointer is a pointer which points nothing.
Some uses of null pointer are:
b) 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.
In C++ if we assign 0 in any pointer that means the pointer pointing to the NULL.
Syntax
Float *p = 0 //initializing the pointer as 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 Questions & Answers
- Why do we check for a NULL pointer before deleting in C/C++?
- NULL pointer in C
- Null Pointer Exception in C#
- Differentiate the NULL pointer with Void pointer in C language
- Why C/C++ array index starts from zero?
- Why is the size of an empty class not zero in C++?
- Why array index starts from zero in C/C++ ?
- Calling class method through NULL class pointer in C++
- Why zero (0) is the first number?
- Why does the indexing start with zero in C# arrays?
- Double Pointer (Pointer to Pointer) in C
- What is the size of void pointer in C/C++?
- What is the size of a pointer in C/C++?
- What is Pointer operator * in C++?
- Why are NULL pointers defined differently in C and C++?
Advertisements