#include<stdio.h>
int main()
{
char a[3][5];
int i;
a[0][5]="hai";
a[1][5]="cool";
a[2][5]="many";
for(i=0;i<3;i++)
printf("%s \n",a[i]);
return 0;
}
为什么我们不能像这样分配字符串值,但是可以使用字符串函数分配它呢?
最佳答案
只读访问的另一种选择(如果您不修改字符串文字)是指针数组:
char *a[3]; /* Or better yet: const char *a[3]; */
a[0]="hai";
a[1]="cool";
a[2]="many";
关于c - 为什么我们不能将字符串值分配给2d char数组?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39408453/