在许多c语言初学者中编写函数时,都喜欢将无参函数中的参数类型忽略。
int func();
但是实际上默认的参数类型不是无参void,而是接受任意数量和类型的参数。也就是说int func() 和 int func(void) 是不一样的。下面通过一个例子加深了解一下在C语言中函数的默认参数类型:
#include <stdio.h>
static int func();
int main() {
printf("func() = %d", func(3, 'a', "abc"));
system("pause");
return 0;
}
static int func() {
return 1;
}
所以说,在使用c语言编写无参函数时,一定要把void写上去,不然会有安全隐患。