簡體   English   中英

如何修復Xcode中的“此處不允許定義函數”

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM