Skip to content

Instantly share code, notes, and snippets.

@limboinf
Created March 31, 2016 02:59
Show Gist options
  • Save limboinf/d6243b806612b00e28bb98cbd9f06e81 to your computer and use it in GitHub Desktop.
Save limboinf/d6243b806612b00e28bb98cbd9f06e81 to your computer and use it in GitHub Desktop.
指向数组的指针与多维数组
#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