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

3 Comments so far

Leave a comment

Name(required)
Mail (required),(will not be published)
  4 + 10 = ?
Please leave these two fields as-is:
Website(recommended)

Fields in bold are required. Email addresses are never published or distributed.

Some HTML code is allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
URLs must be fully qualified (eg: http://www.dutor.net),and all tags must be properly closed.

Line breaks and paragraphs are automatically converted.

Please keep comments relevant. Off-topic, offensive or inappropriate comments may be edited or removed.