Created
March 31, 2016 02:59
-
-
Save limboinf/d6243b806612b00e28bb98cbd9f06e81 to your computer and use it in GitHub Desktop.
指向数组的指针与多维数组
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
#http://docs.linuxtone.org/ebooks/C&CPP/c/ch23s07.html | |
#include <stdio.h> | |
int main(int argc, const char * argv[]) { | |
char a[4][3][2] = { | |
{ | |
{'a', 'b'}, {'c', 'd'}, {'e', 'f'} | |
}, | |
{ | |
{'g', 'h'}, {'i', 'j'}, {'k', 'l'} | |
}, | |
{ | |
{'m', 'n'}, {'o', 'p'}, {'q', 'r'} | |
}, | |
{ | |
{'s', 't'}, {'u', 'v'}, {'w', 'x'} | |
} | |
}; | |
//要想通过pa或ppa访问数组a中的'r'元素 | |
char (*pa)[2] = &a[1][0]; | |
char (*ppa)[3][2] = &a[1]; | |
printf("%c, %c\n", (*(pa+5))[1], (*(ppa+1))[2][1]); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment