Friday, 10 December 2010

void pointer


Void pointer:
Void * p;
Int a=25;
Float b=10.8;
P=&a;
Pf(“%d”,*(int *)p);//type casting
P=&b;
Pf(“%d”,*(float *)p); type casting

An integer can not point to float, the advantage of void pointer is it can point to int,float, char.

  • we can not use void pointer without type casting

#include<stdio.h>
#include<conio.h>
void main()
{
 int a=5;
 float f=5.2f;
 char ch='k';
 void *p;
 p=&a;
 printf("indirect accessing of a is %d\n",*(int *)p);
 p=&f;
 printf("indirect accessing of a f %f\n",*(float *)p);
 p=&ch
printf("indirect accessing of a is %ch\n",*(char *)p);

getch();
}
Pointers

No comments:

Post a Comment