Monday 7 October 2024

What is the difference between NULL and Void Pointer?

 

A null pointer is basically a null value assigned to a pointer of any data type whereas a void pointer is a data type which remains void as long as an address of a data type is not assigned to it.

In short we can say that null pointer is a value whereas void pointer is a data type.

The data type of the pointer is nothing but the type of data stored at the memory location where the pointer is pointed. When you are not sure about the type of data that is going to store at a particular memory location, you need to create the void pointer.


Null pointer doesn’t point to any valid memory         address. It's often represented by the constant "0" or the macro "NULL". Null pointers are used to initialize pointers or to indicate the end of a list.

  1. Definition:
  • -A null pointer is basically a null value assigned to a pointer of any data type
  • - a void pointer is a data type which remains void as long as an address of a data type is not assigned to it.

 

  1. Data type:
  • -Null pointer doesn’t point to any valid memory address.
  • -Void pointer has no associated data type with it.

 

  1. Use:
  • You can use null pointers in the following cases: Initialize pointers. Represent conditions such as the end of a list of unknown length.
  • Void pointers are mainly used in the implementation of data structures such as linked lists, trees, and queues i.e. dynamic data structures.

 

Void pointer is always of type void *

Mainly such pointers are used for dynamic memory allocations (using malloc(), calloc() and realloc() functions), where memory block reserved is pointer to by a void pointer and as the pointer value is returned it has to be explicitly type casted to a particular desired type.

Student of IT Field can update their Programming knowledge at TCCI. Our 18 years experienced faculty can help students to update their knowledge very efficiently.

TCCI Computer classes provide the best training in all computer courses online and offline through different learning methods/media located in Bopal Ahmedabad and ISCON Ambli Road in Ahmedabad.

For More Information:

Call us @ +91 98256 18292

Visit us @ http://tccicomputercoaching.com/

No comments:

Post a Comment