/* add to pointer */ #include <stdio.h> int main() { int a; int *p; a = 10; p = &a; printf("value of a is: %d\n", a); printf("the address of a is stored in p: %p\n", p); printf("size of a is: %d\n", sizeof(a)); p++; printf("the address of p+1 moved %d bytes up: %p\n", sizeof(a), p); printf("the value of memory pointed by p+1 is garbage: %d\n", *p); return 0; }
/* Host byte order: Little Endian / Least significant bit first */ #include <stdio.h> int main() { printf("size of int : %d\n", sizeof(int)); printf("size of char: %d\n", sizeof(char)); /* 1025 : 00000000 00000000 00001000 00000001 */ int a = 2049; int *p0 = &a; printf("p0 points to address: %p\n", p0); printf("p0 points to value: %d\n", *p0); char *p1; p1 = (char *)p0; printf("p1 points to address: %p\n", p1); printf("p1 points to value: %d\n", *p1); p1++; printf("p1++ points to address: %p\n", p1); printf("p1++ points to value: %d\n", *p1); p0++; printf("p0++ points to address: %p\n", p0); printf("p0++ points to value: %d\n", *p0); return 0; }
/* void pointer */ #include <stdio.h> int main() { int a = 10; int *p = &a; printf("address is: %p\n", p); printf("value is: %d\n", *p); void *p0; p0 = p; printf("address is: %p\n", p0); /* invalid use of void expression */ // printf("value is: %d\n", *p0); return 0; }