Monday, 24 May 2021

Null pointer and generic pointer in C language

Null pointer:

A pointer variable is point to some other variable of the same data type. In some cases, we may prefer to have a null pointer which is a special pointer value does not point to any valid memory address.

Example: int *ptr=NULL;

The ptr is a pointer which stores a constant value "NULL", we can also check a given pointer variable store address of some variable or containing a null by writing 

if(ptr= = NULL)

{

  statement block;

}


 

Generic pointer or Void pointer:

A generic pointer is a pointer variable that has void as its data type. The void pointer is a special type of pointer that can be used to point variables of any data type.

It is declared like a normal pointer variable but using the void keyword as the pointer type.

Example:

int a=10,b=20;

float k=20.5;

void *ptr;

ptr=&a;

ptr=&k;

In the above example, ptr is generic pointer that points to two different types of address.

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.

Find Us On Facebook

Computer Basics

More

C Programming

More

Java Tutorial

More

Data Structures

More

MS Office

More

Database Management

More
Top