【发布时间】:2010-12-19 10:28:10
【问题描述】:
给定以下代码:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a[1];
int * b = malloc(sizeof(int));
/* 1 */
scanf("%d", &a);
printf("%d\n", a[0]);
/* 2 */
scanf("%d", &b);
printf("%d\n", b[0]);
return 0;
}
编译时得到如下警告(i686-apple-darwin9-gcc-4.0.1):
array.c: In function 'main':
array.c:9: warning: format '%d' expects type 'int *', but argument 2 has type 'int (*)[0u]'
array.c:14: warning: format '%d' expects type 'int *', but argument 2 has type 'int **'
但是,为什么在第二个printf中会出现执行错误,而对第一个printf却有效?
还有,为什么把第一个scanf换成scanf("%d", a);会得到同样的输出?
提前非常感谢
【问题讨论】: