温故而知新 C++基本类型
C++基本类型大小:

在32位计算机中测试得到:
sizeof(bool) == 1
sizeof(char) == 1
sizeof(short) == 2
sizeof(int) == 4
sizeof(long) = 4
sizeof(float) == 4
sizeof(double) == 8
类型枚举:
enum
//例子: 定义一个服务器的当前状态,分别表示启动,关闭,暂停状态
enum ServerState{START, STOP, PAUSE};
类型void*
void指针可以指向任意类型的数据,亦即可用任意数据类型的指针对void指针赋值,可以用void指针来作为函数形参,这样函数就可以接受任意数据类型的指针作为参数。
int * pint;
void *pvoid;
pvoid = pint; /* 不过不能 pint= pvoid; */
void * memcpy( void *dest, const void *src, size_t len );
void * memset( void * buffer, int c, size_t num);
文字量
012132 (0开头的表示8进制)
0x1232(0x开头的表示16进制)
3U (unsigned int)
3L (long int)
按默认规定浮点数的文字量为double
2.0f
1.2e10
2.9e-3f
limits的用法:
The template class describes arithmetic properties of built-in numerical types. The header defines explicit specializations for the types wchar_t, bool, char, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, float, double, and long double. For these explicit specializations, the member numeric_limits::is_specialized is true, and all relevant members have meaningful values. The program can supply additional explicit specializations. Most member functions of the class describe or test possible implementations of float. For an arbitrary specialization, no members have meaningful values. A member object that does not have a meaningful value stores zero (or false) and a member function that does not return a meaningful value returns Type(0). 这个模板类描述了内建类型的数值属性。 C++标准库显式地为wchar_t, bool, char, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, float, double, and long double这些类型提供了特化。对于这些类型来说,is_specialized为true,并且所有的相关的成员(成员变量或成员函数)是有意义的。这个模板也提供其他的特化。大部分的成员函数可以用float型别来描述或测试。 对于一个任意的特化,相关的成员是没有意义的。一个没有意义的对象一般用0(或者false)来表示,一个没有意义的成员函数会返回0.
numeric_limits的基本用法例子
#include <limits>
#include <iostream>
using namespace std; int main() {
cout << boolalpha; cout << "max(short): " << numeric_limits<short>::max() << endl;
cout << "min(short): " << numeric_limits<short>::min() << endl; cout << "max(int): " << numeric_limits<int>::max() << endl;
cout << "min(int): " << numeric_limits<int>::min() << endl; cout << "max(long): " << numeric_limits<long>::max() << endl;
cout << "min(long): " << numeric_limits<long>::min() << endl; cout << endl; cout << "max(float): " << numeric_limits<float>::max() << endl;
cout << "min(float): " << numeric_limits<float>::min() << endl; cout << "max(double): " << numeric_limits<double>::max() << endl;
cout << "min(double): " << numeric_limits<double>::min() << endl; cout << "max(long double): " << numeric_limits<long double>::max() << endl;
cout << "min(long double): " << numeric_limits<long double>::min() << endl; cout << endl; cout << "is_signed(char): "
<< numeric_limits<char>::is_signed << endl;
cout << "is_specialized(string): "
<< numeric_limits<string>::is_specialized << endl;
}
我的电脑运行结果

温故而知新 C++基本类型的更多相关文章
- 温故而知新--day1
温故而知新--day1 变量类型 变量是计算机存储数据的内存空间,由于计算机可以处理不同的数据,不同的数据就要定义不同的数据类型.python的数据类型很多,还可以自定义数据类型,常用的一般数据类型有 ...
- 【温故而知新-JQ的节点类型】
来源:http://www.hi-docs.com/jquery/contents.html 定义和用法 查找匹配元素内部所有的子节点(包括文本节点).如果元素是一个iframe,则查找文档内容 语法 ...
- C语言枚举类型enum-(转)-温故而知新
在实际编程中,有些数据的取值往往是有限的,只能是非常少量的整数,并且最好为每个值都取一个名字,以方便在后续代码中使用,比如一个星期只有七天,一年只有十二个月,一个班每周有六门课程等. 以每周七天为例, ...
- sql server 基础教程[温故而知新三]
子曰:“温故而知新,可以为师矣.”孔子说:“温习旧知识从而得知新的理解与体会,凭借这一点就可以成为老师了.“ 尤其是咱们搞程序的人,不管是不是全栈工程师,都是集十八般武艺于一身.不过有时候有些知识如果 ...
- javascript 基础教程[温故而知新一]
子曰:“温故而知新,可以为师矣.”孔子说:“温习旧知识从而得知新的理解与体会,凭借这一点就可以成为老师了.“ 尤其是咱们搞程序的人,不管是不是全栈工程师,都是集十八般武艺于一身.不过有时候有些知识如果 ...
- C# 温故而知新:Stream篇(—)
C# 温故而知新:Stream篇(—) 目录: 什么是Stream? 什么是字节序列? Stream的构造函数 Stream的重要属性及方法 Stream的示例 Stream异步读写 Stream 和 ...
- 【C# in depth 第三版】温故而知新(1)
声明 本文欢迎转载,原文地址:http://www.cnblogs.com/DjlNet/p/7192354.html 前言 关于这本书(<深入理解C# 第三版>)的详细情况以及好坏,自行 ...
- CLR类型设计之类型之常量和字段
前言 孔子说:温故而知新,可以为师矣.所以对于学习过的知识要多复习,并且每一次复习都要尽可能的去扩展,而不是书本上的几句理论知识.很多人都喜欢分享自己的学习内容,记录下生活的点点滴滴 ...
- CSS中容易混淆的伪元素类型和用法
:first-of-type 匹配属于其父元素的第一个特定类型的子元素. 1.例子 <head> <meta charset="UTF-8"> <ti ...
随机推荐
- hdoj 1711 Number Sequence【求字串在母串中第一次出现的位置】
Number Sequence Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- RabbitMQ-死信(Dead Letter)
对于有异常的消息我们可以有如下做法: 记录下来再ack. nack或者reject,同时将requeue设为false. 在第2条的基础上增加死信(Dead Letter). 上边的第3个做法可以 ...
- oracle 32位和64位的问题
- Atom 编辑器 前端基本插件
Atom 编辑器插件 这个编辑器是github出品,现在处于免费试用期:如果是初学者,可以使用这个编辑器,插件安装很方便,只需要点菜单栏的File-Settings-Install,在搜索框中输入想要 ...
- JavaScript使用需要注意的细节
1.JavaScript区分大小写 在JavaScript中对象,变量.函数都是区分大小写的,例如: Object表示对象,Arrary表示数组,而写成object,arrary的时候JavaScri ...
- 谋哥:App自推广这个概念就由我来创立了!
[谋哥每天一干货,第六十四篇] 昨天谋天团新增加了一名90后会员崔崔(微信号cuinianyyyy9),之前请教过我关于怎样从.Net到移动IOS开发然后创业的问题.我说你转到IOS,你须要自己学新语 ...
- C - Surprising Strings
C - Surprising Strings 题意:输入一段字符串,假设在同一距离下有两个字符串同样输出Not surprising ,否 ...
- HDU--2040
亲和数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...
- ubuntu 连接 mssql <转>
转自 http://www.sendong.net/thread-90941-1-1.html 在linux下连接MSSQL,因为微软同志没有提供任何接口给开发人员,大约他们认为要用MSSQL的,只 ...
- Lucene全文检索
Lucene写入和更新操作: if (id.equals("")) { this.goodsService.save(goods); String goods_lucene_pat ...