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);
}
相关推荐
coderxiaohan1 小时前
【C++】仿函数 + 模板进阶
开发语言·c++
无敌最俊朗@1 小时前
力扣hot100-206反转链表
算法·leetcode·链表
Kuo-Teng2 小时前
LeetCode 279: Perfect Squares
java·数据结构·算法·leetcode·职场和发展
王哈哈^_^2 小时前
YOLO11实例分割训练任务——从构建数据集到训练的完整教程
人工智能·深度学习·算法·yolo·目标检测·机器学习·计算机视觉
IMPYLH2 小时前
Lua 的 collectgarbage 函数
开发语言·笔记·junit·单元测试·lua
百锦再2 小时前
第18章 高级特征
android·java·开发语言·后端·python·rust·django
檐下翻书1732 小时前
从入门到精通:流程图制作学习路径规划
论文阅读·人工智能·学习·算法·流程图·论文笔记
Tony Bai2 小时前
Go 在 Web3 的统治力:2025 年架构与生态综述
开发语言·后端·架构·golang·web3
CoderYanger2 小时前
B.双指针——3194. 最小元素和最大元素的最小平均值
java·开发语言·数据结构·算法·leetcode·职场和发展·1024程序员节