![](/img/trans.png)
[英]How to fix this code written in Xcode? In the main function, Xcode is displaying the error:Function definition is not allowed here
[英]how to fix "Function definition is not allowed here" in Xcode
這是我講課的例子。 而且,我遵循它。 如何修復錯誤?
#include <stdio.h>
#define SPACE ' '
int main(){
void branching_if_judgement(int a, int b)
{
if (a > b)
{
printf("a(%d) is larger than b(%d)\n", a, b);
}else
{
printf("a(%d) is smaller or equal to b(%d)\n", a, b);
}
}
}
另一個函數中不允許有函數定義/聲明。
main
是一個函數, branching_if_judgement
是另一個函數。
正確(讀取可編譯)代碼:
#include <stdio.h>
#define SPACE ' '
static void branching_if_judgement(const int a, const int b){
if (a > b)
{
printf("a(%d) is larger than b(%d)\n", a, b);
} else
{
printf("a(%d) is smaller or equal to b(%d)\n", a, b);
}
}
int main(){
branching_if_judgement(2, 3);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.