截图
test.c
#include <stdio.h>//std standard input output
#include <string.h>
//ctrl+shift+L键==删除整行
int main()
{
//int age = 10;
//if (18 <= age < 29)//运算顺序,自左向右,所以输出1
// printf("1\n");
//else printf("2\n");
//int a = 0, b = 2;
//if (a == 1)
// if (b == 2)
// printf("hehe");
//else
// printf("haha");
上面这行代码,什么也不输出(我都搞错了,认为输出haha)
int a = 0, b = 2;
if (a == 1)//这里建议写成1 == a,因为假如写成了a = 1自己没发现会引起程序bug,假如1 = a就会此处报错
if (b == 2)
printf("hehe");
else
printf("haha");
//上面这行代码是编译器自动补齐换行的,认为第二个if和else匹配
//写代码还要考虑到代码的可读性
//switch语句与while语句,比较简单,不记笔记了
char ch;
while ((ch = getchar()) != EOF)//键盘输入crtl+z键退出,实测,假如键盘没有任何输入,则这个while循环第一次不进入
{
//注意这里不是无限循环,必须按下回车键再松开一次,while判断一次
//而不是按下回车键一直循环不停,只有松开,才判断一次
if (ch < '0' || ch>'9')
continue;
putchar(ch);
printf("\n");
//printf("1");
}
return 0;
}