简体   繁体   English

一元'*'的无效类型参数

[英]invalid type argument of unary '*'

I'm a week into an intro programming class, and I'm having trouble with fixing what's supposed to be a relatively simple code. 我进入一个介绍编程课一周,而我在修复应该是一个相对简单的代码时遇到了麻烦。 I keep getting an invalid type argument of unary '*' error. 我一直得到一个'*'错误的无效类型参数。

#include <stdio.h>
#define PI 3.14159; 
int main()
{
   float r;
   float area;
   scanf("%f", &r);
   area = PI * r * r;
   printf("Area is %f", area);
   return 0; 
}

Could someone explain this, and how to fix it? 有人可以解释一下,以及如何解决它?

#define PI 3.14159; 
                  ^

Drop the semicolon. 丢掉分号。 Leaving it in, the code will expand to: 离开后,代码将扩展为:

area = 3.14159; * r * r;

You have to remove the extra ; 你必须删除额外的; in the definition of the macro PI . 在宏PI的定义中。 It is unnecessary for macro, and in your case results in syntax error after expansion. 它不需要宏,并且在您的情况下导致扩展后的语法错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM