当前位置:网站首页>C language register skills (struct and union)
C language register skills (struct and union)
2022-07-16 09:00:00 【aningxiaoxixi】
Reference resources :
C Language | Detailed explanation of the use of bit fields
Test code
#include <stdio.h>
struct pack
{
unsigned int a:2; // The value range is :0~3
unsigned int b:4; // The value range is :0~15
unsigned int c:6; // The value range is :0~63
};
union u1 //u1 Indicates the consortium type name
{
//unsigned int b;
struct pack f;
unsigned int b;
};
int main(void)
{
struct pack pk1;
struct pack pk2;
// to pk1 Assign values to members and print out
pk1.a = 1;
pk1.b = 10;
pk1.c = 50;
printf("%d, %d, %d\n", pk1.a, pk1.b, pk1.c);
// to pk2 Assign values to members and print out
pk2.a = 5;
pk2.b = 20;
pk2.c = 66;
printf("%d, %d, %d\n", pk2.a, pk2.b, pk2.c);
printf("\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
union u1 mytest;
mytest.f.a=3;
mytest.f.b=15;
mytest.f.c=63;
mytest.b = 3456;
int sum = 3 + 15*4 + 63 * 64;
printf("@@@@@@@ U2 mytest is %d\n",sum);
printf("U2 mytest is %d\n",mytest);
return 0;
}
边栏推荐
- Hj3 explicit random number hj03
- js中树形结构的深度遍历与广度遍历
- 创原会丨携手50+云原生企业,共探跨越数字化鸿沟新模式
- Is it safe to open an account for stock speculation through the online account manager?
- Various methods of obtaining form handle in VC
- Programmer transformation project management? Get a PMP?
- Interprocess communication (very practical)
- Shutter renderflex overflowed by pixels on the bottom keyboard pop-up warning exception
- Qstring regular expression of QT
- 字符串库函数和内存操作库函数详解及模拟实现
猜你喜欢

LeetCode 2155. 分组得分最高的所有下标

【IDEA】check out master invalid path 问题

Emqx cloud update: add redis and JWT external authentication authorization

人工智能与 RPA 技术应用(一)-RPA弘玑产品介绍、设计器界面功能讲解

LeetCode 1584. Minimum cost of connecting all points

Interprocess communication (very practical)

先序和中序遍历序列确定一颗二叉树(还原二叉树)

JMeter 21天打卡 day01

Web安全-ReDos正则表达式的拒绝服务攻击

GPU资源池的虚拟化路径
随机推荐
字符串库函数和内存操作库函数详解及模拟实现
进程间通信(非常实用)
Response.Write具体介绍
判断两棵二叉树是否同构,三种实现方式(递归、队列、堆栈)
Central bank: the central bank rating of most small and medium-sized banks in China is within the safe boundary
What happens when you unplug the power? Gaussdb (for redis) dual life keeps you prepared
人工智能与 RPA 技术应用(一)-RPA弘玑产品介绍、设计器界面功能讲解
Shell script learning record
ADB环境配置
[canvas] canvas and SVG are basically used
模块
Lesson 3: take coins
用 AnimatedBuilder 分离组件和动画,实现动效复用
Hongliulin, data gold mine has been dug up in the coal mine!
HCIP第一天笔记
PG运维篇--服务启停
YOLOv5使用时遇到的问题
密码密钥硬编码检查
面试诈骗:竟然还有靠面试挣钱的公司
Shutter renderflex overflowed by pixels on the bottom keyboard pop-up warning exception