C语言完美演绎9-13

/* 范例:9-13 */

#include <stdio.h>

union

{

char a;

char b;

int c;

int d;

}myUnion;

struct

{

char a;

char b;

int c;

int d;

}myStruct;

void main(void)

{

printf("size of myUnion=%d\n",sizeof(myUnion));

printf("size of myStruct=%d\n",sizeof(myStruct));

printf("address of myUnion ={%x\t%x\t%x\t%x}\n", \

&myUnion.a,&myUnion.b,&myUnion.c,&myUnion.d);

printf("address of myStruct={%x\t%x\t%x\t%x}\n", \

&myStruct.a,&myStruct.b,&myStruct.c,&myStruct.d);

getchar();

}

程序执行结果:

size of myUnion=4

size of myStruct=12

address of myUnion ={40d658 40d658 40d658 40d658}

address of myStruct ={40d65c 40d65d 40d660 40d664}

相关推荐
Zwawa7 小时前
屏幕不止一种:OLED、LCD1602字符屏、TFT/IPS图形屏和串口屏怎么用,这与TTY和PTY又有什么关系
c语言·单片机·嵌入式
Fruiticecake7 小时前
C 程序员速通现代 C++(一):lambda、std::function、移动语义与智能指针
c语言·c++
田甲8 小时前
做一款 Type-C 母座读卡器:GL3224 双卡方案实测
c语言·开发语言
·present·12 小时前
CSAPP(lecture 13_02 Linking)
c语言·c++
wuyk5551 天前
Keil工具链-第05讲-启动文件与__main到底做了什么
c语言·stm32·单片机·嵌入式硬件·物联网
Navigator_Z1 天前
LeetCode //C - 1317. Convert Integer to the Sum of Two No-Zero Integers
c语言·算法·leetcode
冻柠檬飞冰走茶1 天前
字母移动游戏题解:贪心求最长可保留连续子串(附 C 实现)
c语言·开发语言·数据结构·算法·动态规划
Hhy_11072 天前
《C++深度解构06》手撕 string —— 从底层内存管理到深浅拷贝彻底吃透
c语言·开发语言·c++·学习·visual studio
曦樂~2 天前
Cpp面筋
c语言·c++
HUANGZHENXUAN1233 天前
最大子矩阵和:从 O(n⁴) 到 O(n³) 的列压缩 + Kadane
c语言·前端