how to combine the function in the one output in Xcode

你说的曾经没有我的故事 提交于 2021-01-29 07:36:29

问题


#include <stdio.h>
#define SPACE ' '
void branching_if_judgement(int a, int b){
    if (a > b){
        printf("a(%d) is larger than b(%d)\n", a, b);
    }else {[![enter image description here][1]][1]
        printf("a(%d) is smaller or equal to b(%d)\n", a, b);
    }
}

char branching_if_judgement_char(int a, int b){
    char res;
    if (a > b){
        printf("a(%d) is larger than b(%d)\n", a, b);
        res = 'Y';
    }else {
        printf("a(%d) is smaller or equal to b(%d)\n", a, b);
        res = 'N';
    }
    return res;
}
int main() {
    branching_if_judgement_char(2,3);
}

I follow the example to run the code. And, there are missing the main function in the slide. I add it


So, my question is how to combine all function in the one output, just like the slide.

:


回答1:


The function signature tells us that

char branching_if_judgement_char(int a, int b)

it returns a thing of type char, and it takes two things of type int.

So when you call it, you're passing the two things to it, but not taking the thing it's returning.

branching_if_judgement_char(2,3);

Correct code should be

char p = branching_if_judgement_char(2,3);
printf("%c\n", p);

Please find some time to read

  • https://www.tutorialspoint.com/cprogramming/c_functions.htm
  • https://www.tutorialspoint.com/cprogramming/c_data_types.htm


来源:https://stackoverflow.com/questions/64260987/how-to-combine-the-function-in-the-one-output-in-xcode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!