Joymine 2020-01-10
#include <stdio.h> int main() { int a[5] = { 0 }; int*p = NULL; printf("a = 0x%X\n",(unsigned int)(a)); printf("a+1 = 0x%X\n", (unsigned int)(a + 1)); printf("p = 0x%X\n", (unsigned int)(p)); printf("p+1 = 0x%X\n", (unsigned int)(p + 1)); return 0; } 运行结果: a = 0x55FDF8 a+1 = 0x55FDFC p = 0x0 p+1 = 0x4 请按任意键继续. . .
#include <stdio.h> #define DIM(a) (sizeof(a)/sizeof(*a)) int main() { char s[]={‘h‘,‘e‘,‘l‘,‘l‘,‘o‘}; char*pbegin = s; //如果有一个指针指向了数组最后一个元素的后一个地址,那么这个 //地址是C语言中的一个擦边球地址 char*pend = s+DIM(s); char*p = NULL; printf("pbegin=%p\n",pbegin); printf("pend=%p\n",pend); printf("数组元素个数=%ld\n",DIM(s)); for(p=pbegin;p<pend;p++) { printf("%c",*p); } printf("\n"); return 0; } 运行结果: :~$ gcc main.c :~$ ./a.out pbegin=0x7ffe6de0f620 pend=0x7ffe6de0f625 数组元素个数=5 hello