[英]why this program is not showing any error?
in the code below . 在下面的代码中。
i would like to know why i am not getting any error ? 我想知道为什么我没有任何错误?
# include <stdio.h>
float circle(); /* no parameter*/
int main()
{
float area;
int radius =2;
area=circle(radius);
printf("%f \n",area);
return 0;
}
float circle( r) /* with one parameter even no parameter type */
{
float a;
a=3.14*r*r;
return (a);
}
The 该
float circle();
is not a function with zero parameters. 不是零参数的函数。 It's a function with an unspecified number of parameters.
这是一个参数数量不确定的函数。
The 该
float circle( r) {
is a K&R-style definition in which the type of r
defaults to int
. 是K&R样式的定义,其中
r
的类型默认为int
。 See https://stackoverflow.com/a/18433812/367273 参见https://stackoverflow.com/a/18433812/367273
This is because compiler treat r
as int
by default when no parameter is defined for circle
. 这是因为,当没有为
circle
定义参数时,编译器默认将r
视为int
。 Try to run your code after declaring function prototype as 在声明函数原型为后尝试运行代码
float circle(void);
and you will get error. 你会得到错误。
That's because function 那是因为功能
float circle();
declaration doesn't declare function that takes no arguments. 声明不声明不带参数的函数。
It's implicitly declared as a function that takes undefined number of integer variables as arguments. 它隐式声明为一个函数,该函数使用未定义数量的整数变量作为参数。
Just like 就像
function();
is valid function declaration. 是有效的函数声明。 Implicitly this function will be treated as function taking
int
as arguments and returning int
. 隐式地,此函数将被视为以
int
作为参数并返回int
函数。
If you want to declare function function taking no arguments or not returning any value, you do it with void
keyword: 如果要声明不带任何参数或不返回任何值的函数,可以使用
void
关键字:
void funct(void);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.