Tuesday, November 24, 2020

VOID POINTER , NULL POINTER

A void pointer is a special type of pointer. It can point to any data type, from an integer value or a float to a string of characters.

Void pointer limitation is that the pointed data cannot be referenced directly (the asterisk * operator cannot be used on them) since its length is always undetermined.

type casting or assignment must be used to turn the void pointer to a pointer of a concrete data type

 #include <stdio.h>

int main()

{

int a=5,

double b=3.1415;

void *vp;

vp=&a;

printf(“\n a= %d”, *((int *)vp));

vp=&b;

printf(“\n a= %d”, *((double *)vp));

return 0;

}


Output:

a= 5

b= 3.141500

NULL POINTER

A null pointer is a special pointer that points nowhere. That is, no other valid pointer to any other variable or array cell or anything else will ever be equal to a null pointer.

To initialize a pointer to a null pointer, code such as the following can be used.

 #include <stdio.h>

int *ip = NULL;

0 comments:

Post a Comment

Data Structures with C++



NET/SET/CS PG



Operating Systems



Computer Networks



JAVA



Design and Analysis of Algorithms



Programming in C++

Top