示例1:
#include "stdio.h"
void main()
{
int i = 1;
if(0 != i);
{
printf("i的取值不为0");
/* if条件满足时处理流程*/
}
}
示例2:
#include "stdio.h"
typedef struct trqcUeInst
{
int ueidx;
int mcs;
int transmode;
}TrqcUeInst;
void main()
{
TrqcUeInst * ptrqcUeInst = NULL;
TrqcUeInst tUeInst;
//ptrqcUeInst = &tUeInst;
printf("%d",ptrqcUeInst->ueidx);
}
示例3:
#include "stdio.h"
void main()
{
unsigned int x = 0xffffffff;
unsigned int result1 = 0;
unsigned int result2 = 0;
unsigned int result3 = 0;
printf("%u\n",x);
x = 0xefffffff;
printf("%u\n",x);
result1 = (x * 100) >> 9;
result2 = (unsigned int)(((unsigned long long)(x * 100)) >> 9)//这种方式强转是错误的,因为是先乘100后已经溢出,再转为64位已失效。
result3 = (unsigned int)(((unsigned long long)x * 100) >> 9);
printf("%u\n",result1);
printf("%u\n",result2);
printf("%u\n",result3);
}
示例4:
# include <stdio.h>
int main(void)
{
int i = 1;
switch(i)
{
case 1:
printf("%d",i);
case 2:
printf("%d",i+1);
case 3:
printf("%d",i+2);
break;
default:
printf("%d",i+10);
break;
}
}
上面程序i=1,第一个case条件满足,执行结果会输出:123
但如果每个case都加上break:
# include <stdio.h>
int main(void)
{
int i = 1;
switch(i)
{
case 1:
printf("%d",i);
break;
case 2:
printf("%d",i+1);
break;
case 3:
printf("%d",i+2);
break;
default:
printf("%d",i+10);
break;
}
}
执行结果只会输出:1