数据类型
来源:互联网 发布:有关健身的软件 编辑:程序博客网 时间:2024/05/22 14:21
一、整形
1、整数溢出
<span style="font-size:18px;"><span style="font-size:18px;">//整数溢出#include<stdio.h>int main(void){int i = 2147483647;unsigned j = 4294967295;printf("%d %d %d\n", i, i+1, i+2);printf("%u %u %u\n", j, j+1, j+2);return 0;}</span></span>int和unsigned类型达到最大值时就会溢出,它们的主要区别是unsigned int变量的起始点是0,而int的起始点是-2147483648。注意当他们超过最大值时系统不给予提示。
2、打印short、long、long long和unsigned类型数
#include<stdio.h>int main(void){unsigned int un = 3000000000;short end = 200;long big = 65537;long long verybig = 12345678908642;printf("un = %u and not %d\n", un, un);printf("end = %hd and not %d\n", end, end);printf("big = %ld and not %hd\n", big, big);printf("verybig = %lld and not %ld\n", verybig, verybig);return 0;}
运行结果:
un = 3000000000 and not -1294967296end = 200 and not 200big = 65537 and not 1verybig = 12345678908642 and not 1942899938把65537按照二进制格式写为一个32位数字时他应该是0000 0000 0000 0001 0000 0000 0000 0001,在printf()中使用%hd使它只显示最后16位,即显示1;类似用%ld显示long long只显示了最后32位。
二、字符类型
#include<stdio.h>int main(void){char a = 'FATE';printf("a = %c\n", a);return 0;}运行结果
a = E字符常量'FATE'储存在32位单元中,把这个字符敞亮赋值给char变量,那么只有最后8位会起作用,即'E'。
注:
1、一个字符串只是一个参数。
2、使用%d显示float值不会把该float值转换成近似的int值,而是垃圾直。类似%f显示int也不会把int值转为浮点值。
0 0
- 数据类型
- 数据类型
- 数据类型
- 数据类型
- 数据类型
- 数据类型
- 数据类型
- 数据类型
- 数据类型
- 数据类型
- 数据类型
- 数据类型
- 数据类型
- 数据类型
- 数据类型
- 数据类型
- 数据类型
- 数据类型
- iOS学习总结——多态
- java 数据结构之顺序表
- hdu 1247 Hat’s Words(从给的单词中找hat's word 并按字典序输出)
- 图的遍历
- 定义名字空间
- 数据类型
- 洗牌算法
- 金额转大写及日期转大写(java)
- 问题
- Samp免流软件以及地铁跑酷的自校验分析
- JavaScript数组排序,Array.prototype.sort()
- HDU 5313
- 修改Ubuntu下tomcat内存
- 我的Android进阶之旅------>Android二级ListView列表的实现