gcc -o arrary arrary.c
./arrary
default_environment=8049760, &default_environment=8049760, &default_environment[0]=8049760
&ptr=804976c, *(&ptr)=8584008, ptr=8584008,*ptr=a
nm -e ./arrary | grep ptr
0804976c B ptr
Symbol table中的指標symbol value 代表"該指標變數的位置"。
//arrary.c
#include stdio.h
#include string.h
#include stdlib.h
unsigned char default_environment[4] ={'a','b','c','\0'};
unsigned char *ptr=NULL;
int main(){
ptr=(unsigned char *)malloc(sizeof(unsigned char)*4);
memset(ptr,'0',4);
memcpy(ptr,default_environment,4);
printf(" default_environment=%x, &default_environment=%x, &default_environment[0]=%x\n", default_environment,& default_environment, &default_environment[0]);
printf("&ptr=%x, *(&ptr)=%x, ptr=%x,*ptr=%c\n",&ptr,*(&ptr),ptr,*ptr);
return 0;
}
沒有留言:
張貼留言