c 函数及指针学习 8
联合体
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
#include <stdio.h>union sa { double a; int b; };int main(){union sa ssa;printf("%d \n",sizeof(union sa));} |

联合体的声明,定义,与结构体一样。
联合体的长度为最长成员的长度。
联合体的初始化
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
#include <stdio.h>union sa { int a; int b; };int main(){union sa ssa={1};;printf("%d \n",ssa.a);} |

初始化的值必须为第一个成员的类型
如果是其他类型,则会转化成该类型(如果能);
|
1
|
union sa ssa={1.9}; |
a为1;
|
1
2
3
4
5
6
7
8
9
10
11
12
|
#include <stdio.h>union sa { float a; int b; };int main(){union sa ssa={1};printf("%f \n",ssa.a);} |
a为1.000000
c 函数及指针学习 8的更多相关文章
- C函数及指针学习1
1 大段程序注释的方法 #if 0#endif 2三字母词 以两个问号 开始的都要注意 3 字面值(常量) 在整型号字面值后加 字符L (long),U(unsigned)说明字符常量 为长整型 或( ...
- c 函数及指针学习 10
标准库函数 1算数运算stdlib.h 2随机数stdlib.h 3字符串转化stdlib.h 4数学函数 math.h 5日期和时间 time.h 6信号 signal.h 7打印可变参数列表std ...
- c 函数及指针学习 9
指针的高级应用 处理命令行参数 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #include <stdio.h> int main(int ar ...
- c 函数及指针学习 7
1.结构的存储分配 1 2 printf("%d \n",sizeof(char)); printf("%d \n",sizeof(int)); int 类型为 ...
- c 函数及指针学习 5
聚合数据类型 能够同时存储超过一个的单独数据. c语言提供了数组和结构体. 1. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 #include <stdio.h> # ...
- c 函数及指针学习 4
1数组和指针声明的差别 声明数组:为数组分配内存,为数组名分配内存(指针常量 4个字节) 指针:为指针分配内存(指针变量 4个字节) 1 2 3 4 5 6 7 8 9 10 #include < ...
- c 函数及指针学习 3
strlen(x) 返回 size_t 类型,size_t是 unsigned int 类型,所以 strlen(x)-strlen(y) 返回 unsigned int 始终 >=0 1 2 ...
- C函数及指针学习2
1.break 永久终止循环,continue 结束当前循环 2.switch 每个case标签要有唯一值,(且为常量或常量表达式) 不加break 时执行流会贯穿整个case 标签 3 赋值操作符 ...
- c 函数及指针学习 6
不完整声明 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 /* 方法一 */ struct tag_a{ ...
随机推荐
- 【STL】-deque的用法
初始化: #include <deque> deque<float> fdeque; 算法: fdeque.push_front(f); fdeque.push_back(f) ...
- 0xC0000005: 读取位置 0x00000000 时发生访问冲突
遇见这种问题一般都是空指针,即:指针里没有赋值~ 如果你对null 进行操作就会产生空指针异常 Object obj = new Object(); 你要知道 obj是一个Object指针变量,指向O ...
- jsunit测试
var script = document.createElement('script'); script.src = 'http://static.pay.baidu.com/resource/ba ...
- Emacs+highlight-parentheses高亮括号
EmacsWiki上关于它的介绍HighlightParentheses,下载最新版请通过作者的GitHub:https://github.com/nschum/highlight-parenthes ...
- css3 绘制优惠券
今天偶然发现了一个css3制作动画的地方,发现css3的径向渐变好难理解,幸亏有这里的大神介绍http://www.daqianduan.com/5989.html,这是优惠券的介绍 还有这个http ...
- Python OpenCV——Image
最近看MATLAB有点看不下去...就忍不住回到python的怀抱.研究下OpenCV,就当放松啦,对视觉还是很感兴趣的. 这里和之后代码大部分是来自这里的文档. 首先是对图片的处理. ''' imp ...
- 爬虫再探实战(三)———爬取动态加载页面——selenium
自学python爬虫也快半年了,在目前看来,我面临着三个待解决的爬虫技术方面的问题:动态加载,多线程并发抓取,模拟登陆.目前正在不断学习相关知识.下面简单写一下用selenium处理动态加载页面相关的 ...
- The Blocks Problem
Description Many areas of Computer Science use simple, abstract domains for both analytical and empi ...
- Java 集合源码解析(2):ListIterator
点击查看 Java 集合框架深入理解 系列, - ( ゜- ゜)つロ 乾杯~ 今天心情和股票一样红,还是学学 ListIterator 吧! ListIterator 根据官方文档介绍, ListIt ...
- Why does my ListView scroll to the top when navigating backwards?
I’ve seen a few people asking this question. They have a page which contains a ListView and when an ...