69,371
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
void function(char (*str)[10])
{
int i;
for (i = 0; i < 5; ++i)
{
printf("%s ", str + i);
}
putchar('\n');
}
int main(int argc, char ** argv)
{
char (*str)[10];//声明一个二维数组指针
char other[10] = "other";
//str = other; //cannot convert from 'char [10]' to 'char (*)[10]'
char ch[5][10] = {"this","is","a","string"};
str = ch;//(1)
int i;
for (i = 0; i < 5; ++i)
{
printf("%s ", str + i);
}
putchar('\n');
function(str);
function(ch);//效果相当于执行了(1)
return 0;
}
#include <stdio.h>
void foo(char a[])
{
// TODO ...
}
void foo1(char *a) // 数组做参数时,char a[] == char* a
{
// TODO ...
}
int main(void)
{
char a[] = "abcdef";
char* b = "ghjklmn";
foo(a);
foo(b);
foo1(a);
foo1(b);
return 0;
}