問題:int a[10];問下面哪些不可以表示a[1]的地址?
A、a+sizeof(int)
B、&a[0] + 1
C、(int*)&a+1
D、(int*)((char*)&a+sizeof(int))
#includeint main() { int a[10] = { 1,2,3,4,5,6,7,8,9,0 }; printf("*******輸出地址*******\n"); printf("a[0] = %d\n",a); printf("a+sizeof(int) = %d\n",a+sizeof(int)); //a+1為地址加4,這裡相當於地址加了16 printf("&a[0] + 1 = %d\n",&a[0] + 1); // 這個加1也是地址加4 printf("(int*)&a+1 = %d\n",(int*)&a+1); // 加1也是地址加5 printf("(int*)((char*)&a+sizeof(int)) = %d\n",(int*)((char*)&a+sizeof(int)));//這裡先把地址變成指向char類型指針,然後+4就是按char類型長度加,最後變成指向整型 printf("\n"); printf("*******輸出值*********\n"); printf("a[0] = %d\n",*a); printf("a+sizeof(int) = %d\n",*(a+sizeof(int))); printf("&a[0] + 1 = %d\n",*(&a[0] + 1)); printf("(int*)&a+1 = %d\n",*((int*)&a+1)); printf("(int*)((char*)&a+sizeof(int)) = %d\n",*((int*)((char*)&a+sizeof(int)))); return 0; }
答案是A