【发布时间】:2015-02-16 09:57:19
【问题描述】:
我尝试通过“简单地”计算一个圆来学习在函数中使用指针。我收到错误 expected expression before '=' token 但不明白为什么。之前说的预期表达..我不清楚,是什么样的?
#define PI = 3.1415f
void circle(float *wert) {
*wert = ( (*wert) * (*wert) * PI );
}
int main(void) {
float radius;
printf("radius input: ");
scanf("%f", &radius);
circle(&radius);
printf("the circle size will be: %f", &radius);
}
【问题讨论】:
-
&radiusinprintf应该是radius。 -
谢谢,#define PI = 3.1415f 应该是#define PI 3.1415f without =
-
如果你包含了
math.h,你会发现PI已经是pre#defined。 -
但我什至无法理解错误输出,错误出现在第 12 行,我使用数学,但 pi 定义较早,第 12 行 PI 不在 = 符号之前。
标签: c pointers c-preprocessor