[英]compiling errors - numeric constant
I keep getting the following compilation errors in my program. 我的程序中不断出现以下编译错误。 I'm suppose to write a program which uses the array p[]
, which is passed to a function that calculates the polynomial of the nth degree (which is set to 5 below) and returns the value. 我想编写一个使用数组p[]
,该程序传递给一个函数,该函数计算第n次多项式(在下面设置为5)并返回值。
My errors are as follows: 我的错误如下:
poly.c:4:39: error: expected ';', ',' or ')' before numeric constant poly.c:4:39:错误:数值常量前应为';','或')
poly.c:16:39: error: expected ';', ',' or ')' before numeric constant poly.c:16:39:错误:数值常量前应为';','或')
My program: 我的程序:
#include <stdio.h>
#define N 5
double eval(double p[], double x, int N)
int main()
{
double p[N+1] = {0,1,2,3,4};
double x;
printf("what value of x would you like?: ");
scanf("%lf", &x);
p[N+1] = eval(p[], x, n);
printf("%lf", p[N+1]);
}
double eval(double p[], double x, int N)
{
double y;
y = x^(p[N+1]);
return y;
}
After the preprocessor is done, your code looks like: 完成预处理程序后,您的代码如下所示:
double eval(double p[], double x, int 5)
So there's still the missing ;
所以仍然有失踪者;
at the end of that line, and that 5
makes no sense there. 在该行的末尾,那5
毫无意义。
Don't define such short macro names, and don't have formal parameter names that are also #define
. 不要定义这样的短宏名,也不要使用同样也是#define
形式参数名。 Make sure you only use N
in all your code where the global constant is meant. 确保在所有代码中仅使用N
表示全局常数。
Also, to pass the p
array as a parameter, just say p
, not p[]
. 另外,要将p
数组作为参数传递,只需说p
,而不是p[]
。
#define N 5
double eval(double p[], double x, int N)
Since you #defined N to be 5, the above will look like this after preprocessing: 由于您将N定义为5,因此经过预处理后,上面的代码将如下所示:
double eval(double p[], double x, int 5)
Obviously that's wrong. 显然那是错误的。 Also function declarations need to be terminated with a semicolon. 同样,函数声明也需要以分号终止。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.