以下代码输出段错误:11
#include<stdio.h>
#include<string.h>
int main(){
char **total;
strcpy(*(total+1),"hello");
printf("%s",*(total+1));
}
但是下面的(当没有 **Array 初始化时)
#include<stdio.h>
#include<string.h>
int main(){
char total[3][100];
strcpy(total[1],"hello");
printf("%s",total[1]);
}
那么第一个代码到底出了什么问题呢?是由于初始化步骤还是 strcpy 函数导致的?
最佳答案
使用chartotal[3][100]
自动为数组保留一部分称为total的内存。
使用 char **total
您必须为数组分配内存。
关于c - 在 C 中构建二维字符串数组的引用运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43436691/