以下是引用zisefengye在2010-7-31 22:48:13的发言:
其实这个问题是这样的。sizeof(int*)是4,sizeof(char*)也是4。因为传递一个数组参数,接受参数的函数,会把传过来的参数当指针处理。
其实这个问题是这样的。sizeof(int*)是4,sizeof(char*)也是4。因为传递一个数组参数,接受参数的函数,会把传过来的参数当指针处理。
你终于明白了。
哥说了半天,你才明白,传进来的是指针。

程序代码:#include <stdarg.h>
#include <stdio.h>
// printf's action is like this
void test(char *fmt, ...)
{
int i;
float j;
va_list ap, app;
va_start(ap, fmt);
app = ap;
i = va_arg(ap, int); // when you call like printf("%d\n", i);this line while be called
j = va_arg(app, double); // when you call like printf("%f\n", i);
// this line while be called
// and you can't call it like j = va_arg(app,float), because gcc compiler will complain
va_end(ap);
printf("if the args interpret as int, you get %d\n", i);
printf("it should interpret as double, the right answer is %f\n",j);
}
int main(void)
{
float a = 12.5;
test("%d", a);
return 0;
}