2007年9月25日 星期二

Pointer 與 Structure 運用.

/*
* 說明: (*pz).a = pz->a

first member before the function call 11, Address = 4598856
first member inside the function 11
first member before the function call 12, Address = 4598976
first member after the function call 12 Address = 4606680
first member before the function call 12, Address = 4606704
Address of y.d = 4606728
Address of y->d = 4606752
*/
struct y{
int d;
int e;
};
struct x{
int a;
int b;
int c;
struct y ys;
};

void function(struct x *);

main(){
struct x z, *pz;

pz = &z;
z.a = 10;
z.a++;

printf("first member before the function call %d, Address = %u\n", pz->a, malloc(sizeof(pz->a)));

function(pz);
printf("first member before the function call %d, Address = %u\n", pz->a, malloc(sizeof(pz->a)));
printf("first member after the function call %d Address = %u\n", (*pz).a, malloc(sizeof((*pz).a)));
printf("first member before the function call %d, Address = %u\n", z.a, malloc(sizeof(z.a)));
printf("Address of y.d = %u \n", malloc(sizeof(z.ys.d)));
printf("Address of y->d = %u \n", malloc(sizeof(pz->ys.d)));

}

void function(struct x *pz){
printf("first member inside the function %d \n", pz->a);

pz->a++;

}

沒有留言: