问题
#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