1.环境:
[root@localhost Desktop]# cat /proc/version
Linux version 2.6.32-220.el6.i686 (mockbuild@x86-003.build.bos.redhat.com) (gcc version 4.4.5 20110214 (Red Hat 4.4.5-6) (GCC) ) #1 SMP Wed Nov 9 08:02:18 EST 2011
2.代码:
/*
*wuxiuwen*switch 中的注意点
*/
#include<stdio.h>
int fun1(int a,int b){
printf("%d,%d\n",a,b);
return 0;
}
#define N 3
int fun2(){
// float f; //此处用于switch中的case,不能用float,float的保存方式不一样;
int f =3;
switch(f)
{
case N:printf("OK\n");
}
return 0;
}
int main()
{
int i=3;
printf("j=%d\n",++i+(++i)+(++i));
fun1(i=4,i);
fun2();
return 0;
}
3.说明:
1)switch中的case不能用float,一般用char或者int 、enum等;
2)++等的方式是右结合,所以以后写程序的时候直接加上小括号,这样子一般不会出错;
3)执行结果:
[root@localhost 20120721_1]# gcc test1.c
[root@localhost 20120721_1]# ./a.out
j=16
4,4
OK
[root@localhost 20120721_1]#
//************************************end*******************************************//