c语言flag的使用

flag在c语言中标识某种状态或记录某种信息,可以通过修改flag中来控制程序流程,判断某种状态是否存在或记录某种信息

操作:(1)初始化 (2)赋值 (3)判断 (4)修改 (5)去初始化

c 复制代码
#include <stdlib.h>

int power_state_check;
 
int main()
{
    int i = 0;
     
    power_state_check = 0x10;
    
    if(power_state_check&0x10)
    {
        power_state_check |= (1<<0);
    }
    
    if(power_state_check&0x10)
    {
        power_state_check |= (1<<1);
    }
    
    if(power_state_check&0x10)
    {
        power_state_check |= (1<<2);
    }
    
    if(power_state_check&0x10)
    {
        power_state_check |= (1<<3);
    }
    
    if(power_state_check&0x10)
	{
	    printf("Hello, World power_state_check is %x\n",power_state_check);
		for(i=0;i<4;i++)
		{
			if((power_state_check&(1<<i)) == 0x0)
			{
			   printf("i =%d cmd loss func %s line %d\r\n",i,__func__,__LINE__);
				if(i==2)
				{
					printf(" i=%d cmd loss func  msg_match enter operation %s line %d\r\n",i,__func__,__LINE__);
				}
			}
		}

	}
	power_state_check = 0x0;
    
    printf("Hello, World power_state_check is %d\n",power_state_check);
    return(0);
}
相关推荐
To_OC3 小时前
LC 994 腐烂的橘子:人人都说是 BFS 入门题,我却写了三遍才过
javascript·算法·leetcode
金銀銅鐵6 小时前
[Python] 扩展欧几里得算法
python·数学·算法
To_OC9 小时前
LC 200 岛屿数量:经典 DFS 入门题,我第一次写居然连方向都搞错了
javascript·算法·leetcode
To_OC1 天前
LC 128 最长连续序列:别上来就排序,O (n) 解法才是这题的灵魂
javascript·算法·leetcode
05Kevin2 天前
lk每日冒险题--数据结构6.27
算法
To_OC2 天前
从一次栈溢出报错说起,我把递归彻底扒明白了
javascript·算法·程序员
千纸鹤安安2 天前
千问Qwen-AgentWorld来了:一个语言模型搞定七大Agent场景,GPT-5.4都输了
算法
七牛开发者2 天前
MCP 到底是什么?为什么 Agent 都想接上它
算法·aigc·agent