2010年7月1日 星期四

C - pointer

Description : Pointer
When I announce a variable " int *ptr."
Ptr mean this is a address.
This is a integer address.
If I want assign a value, it must be a address to assign to ptr.


#include

int j, k;
int *ptr;

int main(void)
{
j = 1;
k = 2;
ptr = &k;
printf("\n");
printf("j has the value %d and is stored at %p\n", j, &j);
printf("k has the value %d and is stored at %p\n", k, (void *)&k);
printf("ptr has the value %p and is stored at %p\n", ptr, (void *)&ptr);
printf("The value of the integer pointed to by ptr is %d\n", *ptr);

return 0;
}


Reference :
http://pw1.netcom.com/~tjensen/ptr/ch1x.htm

Related Posts:

0 意見:

張貼留言