Skip to content

Instantly share code, notes, and snippets.

@yxjxx
Last active August 29, 2015 14:16
Show Gist options
  • Save yxjxx/97580893c67b695451c3 to your computer and use it in GitHub Desktop.
Save yxjxx/97580893c67b695451c3 to your computer and use it in GitHub Desktop.
C语言二维数组
#include <iostream>
using namespace std;
int main()
{
char ch[3][5] = {"AAAA", "BBB", "CC"};//C语言中二维数组默认按行存储,ch[3]表示数组有3个元素,ch[3][5]表示ch[3]数组中的每个元素又是一个含有5个元素的数组
cout << ch[1] << endl; //ch[3]数组的第二个元素(数组下标从0开始)
for(int i=0;i<3;i++){
for(int j=0;j<5;j++){
cout << ch[i][j] << " ";
}
cout << endl;
}
return 0;
}
/*
result:
BBB
A A A A
B B B
C C
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment