Last active
March 25, 2018 01:46
-
-
Save LuckyKoala/a0ab068825363546abede949beb2ebb3 to your computer and use it in GitHub Desktop.
int array[8]; &array 的类型是 int (*)[8]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(void) | |
{ | |
int array[8] = {10,11,12,13,14,15,16,17}; | |
int *p = array; | |
int *q = &array; //提示不兼容的类型,这里其实是转换了指针类型 | |
int (*z)[8] = &array; | |
printf("the size of array: %ld, the size of &array: %ld\n", sizeof(array), sizeof(&array)); | |
printf("the value of array[1]: %d, the value of (&array)[0][1]: %d\n", array[1], (&array)[0][1]); | |
printf("the address of pointer array: %p, the address of pointer array+1: %p\n", (void*)array, (void*)(array+1)); | |
printf("the address of pointer &array: %p, the address of pointer &array+1: %p\n", (void*)&array, (void*)(&array+1)); | |
printf("the size of p: %ld, the size of q: %ld\n", sizeof(p), sizeof(q)); | |
//printf("the value of p[1]: %d, the value of q[0][1]: %d\n", p[1], q[0][1]); | |
printf("the address of pointer p: %p, the address of pointer p+1: %p\n", (void*)p, (void*)(p+1)); | |
printf("the address of pointer q: %p, the address of pointer q: %p\n", (void*)q, (void*)(q+1)); | |
return 0; | |
} | |
/* | |
示例输出: | |
the size of array: 32, the size of &array: 8 | |
the value of array[1]: 11, the value of (&array)[0][1]: 11 | |
the address of pointer array: 0x7ffdaff18c90, the address of pointer array+1: 0x7ffdaff18c94 | |
the address of pointer &array: 0x7ffdaff18c90, the address of pointer &array+1: 0x7ffdaff18cb0 | |
the size of p: 8, the size of q: 8 | |
the address of pointer p: 0x7ffdaff18c90, the address of pointer p+1: 0x7ffdaff18c94 | |
the address of pointer q: 0x7ffdaff18c90, the address of pointer q: 0x7ffdaff18c94 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment