首页 > 解决方案 > 如果我这样声明函数,为什么它不起作用?

问题描述

我在 main fn 之前首先声明了 'GuGuDan' fn,但它显示错误消息'隐式声明函数'GuGudan' 在 C99 中无效'并且不起作用。所以我试图找到另一种解决方案,并发现如果我在“WhatToPrint”fn 中声明它就可以工作。

#include <stdio.h>

void GuGuDan(int, int);
void WhatToPrint(int, int);


...


void WhatToPrint(int x, int y){
void GuGudan(int, int); 
// why must I declare GuGuDan fn in WhatToPrint fn?
...

}

标签: function-declaration

解决方案


在声明中,您只指定输入的数据,但在定义中,您需要为其提供变量。所以如果你像下面那样做它应该可以工作。

#include <stdio.h>

void GuGuDan(int, int); //this is the declaration 
void WhatToPrint(int, int);


...


void GuGudan(int x, int y){
// This way your GuGudan function will work
...

}
void GuGudan(int x, int y){
// This way your GuGudan function will work
...

}

推荐阅读