2010年6月6日星期日

void pointer

void pointer is a no type pointer can be assigned to other pointer with type.

eg:

void *vp;
int * p;

vp = p;

However, in ANSI

void pointer can not do arithmetical operation.

eg:

#include ;

int main()
{

int a = 10;
int * p = &a;
void * vp;
vp = p;

printf("p = %p,vp = %p\n",p,vp);
printf("%d\n", *p);
p++;
printf("p = %p,vp = %p\n",p,vp);
printf("%d\n", *p);
vp++;
return 0;
}

output:

p = 0012FF94,vp = 0012FF94 //output address
10 //output value
p = 0012FF98,vp = 0012FF94 //p got correct result, vp got wrong
1245120 // p move, the content value is wrong

没有评论:

发表评论