Home >Backend Development >C++ >In C language, what is a null pointer?
It is a pointer that can save the address of any data type variable (or) can point to any data type variable.
The declaration of void pointer is as follows −
void *pointername;
For example − void *vp;
Access − Through pointer Type conversion operators are used when accessing the value of a variable.
The syntax of void pointer is as follows −
* ( (type cast) void pointer)
int i=10; void *vp; vp = &i; printf ("%d", * ((int*) vp)); // int * type cast
The following is the C program void pointer:
Real-time demonstration
#include<stdio.h> main ( ){ int i =10; float f = 5.34; void *vp; vp = &i; printf ("i = %d", * ((int*)vp)); vp = &f; printf ( "f = %f", * ((float*) vp)); }
When the above program is executed, it produces the following results−
i = 10 f = 5.34
Given below is a C program for pointer arithmetic in null pointers −
Online Demonstration
#include<stdio.h> #define MAX 20 int main(){ int array[5] = {12, 19, 25, 34, 46}, i; void *vp = array; for(i = 0; i < 5; i++){ printf("array[%d] = %d</p><p>", i, *( (int *)vp + i ) ); } return 0; }
When the above program is executed, it produces the following Result−
array[0] = 12 array[1] = 19 array[2] = 25 array[3] = 34 array[4] = 46
The above is the detailed content of In C language, what is a null pointer?. For more information, please follow other related articles on the PHP Chinese website!