如何为长春企业定制专属的港巢网站软件?

摘要:港巢网站建设,长春制作网站软件,中国网站建设中心,用织梦做的公司网站 经常被攻击一、问题 最近写函数时,遇到了一个比较奇怪的问题,相信也好多人遇到一下的问题&#xf
港巢网站建设,长春制作网站软件,中国网站建设中心,用织梦做的公司网站 经常被攻击一、问题 最近写函数时#xff0c;遇到了一个比较奇怪的问题#xff0c;相信也好多人遇到一下的问题#xff1a; error: expected declaration specifiers or ‘...’ before ‘(’ token代码如下#xff1a; #includestdio.h struct stu{char *name;int score;…一、问题 最近写函数时遇到了一个比较奇怪的问题相信也好多人遇到一下的问题 error: expected declaration specifiers or ‘...’ before ‘(’ token代码如下 #includestdio.h struct stu{char *name;int score; } stus[]{{zhangsan1,65},{zhangsan2,98} }; void averge(struct stu *,int); int main(){int lensizeof(stus)/sizeof(struct stu);printf(start...\n);//数组名可以认为是一个指针averge(stus,len);} void averge(struct stu* stus,int len){char *name;int score;int sum0;for(int i0;ilen;i){namestus[i].name;//第一种形式score(*(stusi)).score;//第二种形式sumscore;printf(%s...%d \n,name,score);} printf(平均分%d...\n,sum/len); }当然以上的代码运行和编译是正常的那么可以对代码进行修改 #includestdio.h struct stu{char *name;int score; } stus[]{{zhangsan1,65},{zhangsan2,98} }; void averge(struct stu *,int); int main(){int lensizeof(stus)/sizeof(struct stu);printf(start...\n);//数组名可以认为是一个指针averge(stus,len);} void averge(struct stu* stus,int len){ # 修改部分对函数的参数加上括号-累死强制转换char *name;int score;int sum0;for(int i0;ilen;i){namestus[i].name;//第一种形式score(*(stusi)).score;//第二种形式sumscore;printf(%s...%d \n,name,score);} printf(平均分%d...\n,sum/len); }编译结果如下 └──╼ $gcc test.c -o test test.c:25:13: error: expected declaration specifiers or ‘...’ before ‘(’ tokenvoid averge((struct stu )*stus,int len){二、原因 我们先来看一下c语言函数的定义 函数名后面圆括号括起来的部分称为形式参数列表即形参列表方括号括起来的部分是可选的。如果有多个形式参数应该分别给出各形式参数的类型并用逗号隔开该类函数称为有参函数。 return_type function_name( parameter list ) { body of the function } 这也就是说其中函数中是不能存在其他符号这就解释了为什么会出现以上的错误 其实我们所经常见到的是在调用函数时在传入的参数进行强制类型转换这与上述的方式是不相同的。 例如 struct dhb {int aa;int bb; }; struct gxy {int dd; }; struct dhb gx { 99,88 }; void test(struct gxy* p) {printf(p-aa%d\n, ((struct dhb*)p)-aa);printf(p-bb%d\n, ((struct dhb*)p)-bb);p-dd 23; } int main() {struct dhb* p1gx;test((struct gxy*)p1);printf(p1-dd%d\n, ((struct gxy*)p1)-dd); }