a11 if省略{}
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a = 0;
printf("%d",a);
if (a == 0)a=1;
printf("%d",a);
system("pause");
return 0;
}
a12 if(判断){...}else if(判断){...}else{...}
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a = 0;
printf("%d\n", a);
if (a == 0){
a = 1;
}
else if (a == 1){
a = 2;
}
else{
a = 3;
}
printf("%d\n", a);
system("pause");
return 0;
}
a13 三目运算 (赋值)
#include <stdio.h>
#include <stdlib.h>
int main()
{
//三目运算
int a = 0;
a=a==1?1:2;
printf("%d\n", a);
system("pause");
return 0;
}
a14 三目运算2 (赋值)
#include <stdio.h>
#include <stdlib.h>
int main()
{
//三目运算2
int a = 0;
printf("%d\n", a==1?1:2);
system("pause");
return 0;
}
a15 三目运算3 (复合)
#include <stdio.h>
#include <stdlib.h>
int main()
{
//三目运算3
int a = 0;
printf("%d\n", a);
a=a==0?1:a==1?2:3;
// if (a == 0) a = 1;
// else if (a == 1)a = 2;
// else a = 3;
printf("%d\n", a);
system("pause");
return 0;
}
a16 三目运算4 (输出)
#include <stdio.h>
#include <stdlib.h>
int main()
{
//三目运算4
int a = 0;
printf(a==0?"A\n":"B\n");
system("pause");
return 0;
}
a17 三目运算5 (语句)
#include <stdio.h>
#include <stdlib.h>
int main()
{
//三目运算5
int a = 0;
a==0?printf("A\n"):printf("B\n");
system("pause");
return 0;
}
a18 switch关键字
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a = 0;
switch (a)
{
case 0:
printf("A\n");
break;
case 1:
printf("B\n");
break;
default:
printf("C\n");
break;
}
system("pause");
return 0;
}
a19 常量
#include <stdio.h>
#include <stdlib.h>
#define SIZE 10 //常量
int main()
{
int a = 0;//变量
const int b = 1;//常量,本质常量
system("pause");
return 0;
}
a20 枚举
#include <stdio.h>
#include <stdlib.h>
int main()
{
enum Sex//枚举常量
{
MALE,
FEMALE,
SECRET
};
enum Sex s = FEMALE; //利用枚举常量给变量赋值
printf("%d\n", MALE);//0
printf("%d\n", FEMALE);//1
printf("%d\n",SECRET);//2
system("pause");
return 0;
}