语法-分支

新建项branch.c
1.if
将branch.c最后一个main方法的名改为main12
添加stdbool.h里的true

#include <stdio.h>
#include <stdbool.h>

int main(void) {
	int a = 1;
	if (true) {
		printf("true");
	}
	return 0;
}

2.if...else
将上一个main方法的名改为main21

int main(void){
	if (false) {}
	else
	{
		printf("false");
	}
	return 0;

3.if...else if...else
将上一个main方法的名改为main22

int main(void) {
	char true_or_false = fgetchar();
	if (true_or_false == 'y') {
		printf("first_true");
	}
	else if (true_or_false == 'n') {
		printf("second_true");
	}
	else {
		printf("false");
	}
	return 0;
}

PixPin_2025-07-10_16-18-59

posted @ 2025-07-31 20:36  基础狗  阅读(6)  评论(0)    收藏  举报