两个a
和*a
是指针,因此将其打印在格式化输出中,如printf()
使用%p
作为格式说明符。
否则你将得到警告你的编译器的消息说
warning: format ‘%x’ expects type ‘unsigned int’, but argument 2 has type ‘int (*)[2]’ warning: format ‘%x’ expects type ‘unsigned int’, but argument 2 has type ‘int *’
所以试试这个:
printf("%p\n",a);
printf("%p\n",*a);
对于第三种情况**a
是int
型的,因此最好使用%d
或%i
printf("%d\n",**a);
根据C标准,
ISO c99 standard : 7.19.6 Formatted input/output functions
9 If a conversion specification is invalid, the behavior is undefined.
If any argument is not the correct type for the corresponding conversion
specification, the behavior is undefined.
请更好地解释你的问题。我只看到代码是无效的(前两个'printf'语句)。 –
可能重复的[是数组名称中的一个指针?](http://stackoverflow.com/questions/1641957/is-array-name-a-pointer-in-c) – WhozCraig