1
2
3
4
5
6
7
8
9
10
11
12
13
void fun1(char * str) {}
void fun2(char ** str) {}
 
//~ int main(int argc, char ** argv)
int main(int argc, char * argv[])
{
	char str1[] = "Hello, Piggy!";
	char str2[][4] = "Hello, Piggy!";
	fun1(str1);
	fun2(str2);
	fun2(&str1);
	return 0;
}

  上面的snippet有错误吗?有几个?你能找出来并说出原因吗?4、5两行有区别吗?想一下,然后看gcc给出的错误信息,

test.c: In function ‘main’:
test.c:9: error: invalid initializer
test.c:11: warning: passing argument 1 of ‘fun2’ from incompatible pointer type
test.c:4: note: expected ‘char **’ but argument is of type ‘char (*)[4]’
test.c:12: warning: passing argument 1 of ‘fun2’ from incompatible pointer type
test.c:4: note: expected ‘char **’ but argument is of type ‘char (*)[14]’
Tags: .
你好!除了代码,此处没有多少原创之物,皆为本人搜集、整理、总结之记录与心得,欢迎转载分享!转载时请尽量注明出处,将不胜感激。祝你健康、快乐!
Home

RFC: Request For Comments. Orz..

Name(required)
Mail (required),(will not be published)

RFC: Request For Comments. Orz..

Website(recommended)