我正在练习字符串数组,但好像不理解它如何工作,有人能向我解释一下正确的编写代码方式吗?
代码目标:将两个字符串赋值给一个字符串数组,并使用函数打印它们。
错误:编译器没有发现任何错误,但是我在终端中没有得到任何输出。
#include <stdio.h>
#define MAX 100
void function(char **);
int main()
{
char *a[MAX]; /*array of max 100 strings*/
a[0] = "test0";
function(&a[MAX]);
return 0;
}
void function(char *a[MAX])
{
a[1] = "test1";
printf("%s",*a[1]);
printf("%s",*a[0]);
}
"%d"
吗?出了什么问题? - doctorlovea
中最后一个元素之后的地址,这也是错误的类型。你应该在这里得到一堆警告。 - Eugene Sh.