浮点型参数输入到浮点型返回值的函数中,返回正确的值,20.25
-
#include <stdio.h>
-
/* declaration */
-
float square(float);
-
-
/* main */
-
int main(void){
-
float x = 4.5;
-
printf("%.2f\n", square(x));
-
-
return 0;
-
}
-
-
/* function definition */
-
float square(float a){
-
return a*a;
-
}
浮点型参数输入到整形返回值、整形参数的函数中,返回了错误的值,16。因为4.5被截断了。
-
#include <stdio.h>
-
/* declaration */
-
int square(int);
-
-
/* main */
-
int main(void){
-
float x = 4.5;
-
printf("%d\n", square(x));
-
-
return 0;
-
}
-
-
/* function definition */
-
int square(int a){
-
return a*a;
-
}
阅读(210) | 评论(0) | 转发(0) |