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++基本类型的更多相关文章

  1. 温故而知新--day1

    温故而知新--day1 变量类型 变量是计算机存储数据的内存空间,由于计算机可以处理不同的数据,不同的数据就要定义不同的数据类型.python的数据类型很多,还可以自定义数据类型,常用的一般数据类型有 ...

  2. 【温故而知新-JQ的节点类型】

    来源:http://www.hi-docs.com/jquery/contents.html 定义和用法 查找匹配元素内部所有的子节点(包括文本节点).如果元素是一个iframe,则查找文档内容 语法 ...

  3. C语言枚举类型enum-(转)-温故而知新

    在实际编程中,有些数据的取值往往是有限的,只能是非常少量的整数,并且最好为每个值都取一个名字,以方便在后续代码中使用,比如一个星期只有七天,一年只有十二个月,一个班每周有六门课程等. 以每周七天为例, ...

  4. sql server 基础教程[温故而知新三]

    子曰:“温故而知新,可以为师矣.”孔子说:“温习旧知识从而得知新的理解与体会,凭借这一点就可以成为老师了.“ 尤其是咱们搞程序的人,不管是不是全栈工程师,都是集十八般武艺于一身.不过有时候有些知识如果 ...

  5. javascript 基础教程[温故而知新一]

    子曰:“温故而知新,可以为师矣.”孔子说:“温习旧知识从而得知新的理解与体会,凭借这一点就可以成为老师了.“ 尤其是咱们搞程序的人,不管是不是全栈工程师,都是集十八般武艺于一身.不过有时候有些知识如果 ...

  6. C# 温故而知新:Stream篇(—)

    C# 温故而知新:Stream篇(—) 目录: 什么是Stream? 什么是字节序列? Stream的构造函数 Stream的重要属性及方法 Stream的示例 Stream异步读写 Stream 和 ...

  7. 【C# in depth 第三版】温故而知新(1)

    声明 本文欢迎转载,原文地址:http://www.cnblogs.com/DjlNet/p/7192354.html 前言 关于这本书(<深入理解C# 第三版>)的详细情况以及好坏,自行 ...

  8. CLR类型设计之类型之常量和字段

             前言 孔子说:温故而知新,可以为师矣.所以对于学习过的知识要多复习,并且每一次复习都要尽可能的去扩展,而不是书本上的几句理论知识.很多人都喜欢分享自己的学习内容,记录下生活的点点滴滴 ...

  9. CSS中容易混淆的伪元素类型和用法

    :first-of-type 匹配属于其父元素的第一个特定类型的子元素. 1.例子 <head> <meta charset="UTF-8"> <ti ...

随机推荐

  1. A - 棋盘问题

    地图看起来不太大,可以试试深搜,试一下.. 还是比较简单的搜索,竟然一下就过................... #include<stdio.h> #include<)      ...

  2. Android注解利器:ButterKnife 的基本使用

    前言 ButterKnife 简介 ButterKnife是一个专注于Android系统的View注入框架,可以减少大量的findViewById以及setOnClickListener代码,可视化一 ...

  3. sqlserver授予用户查看执行计划的权限

    sqlserver查看语句的执行计划是非常重要的,可以提高开发人员代码的质量.所以有必要授予开发人员对数据库查看执行计划的权限.   查看执行计划的权限属于数据库一级别的权限,具体例子如下   use ...

  4. php如何同时连接多个数据库

    下面是一个函数能够保证连接多个数据库的下不同的表的函数,可以收藏一下,比较实用,测试过是有用的. function mysql_oper($oper,$db,$table,$where='1',$li ...

  5. HDU--杭电--1241--Oil Deposits--广搜

    Oil Deposits Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tot ...

  6. 3D游戏引擎一 win32编程

    Windows程序一般都等待用户进行一些操作,然后响应并採取行动. 一般来说.对win32的程序的操作都会转换为系统事件队列中的消息,如按键消息WM_KEYDOWN,WM_MOUSECLICK等传递键 ...

  7. Delphi 2007体验!

    Delphi 2007体验! baidu 内容摘要:CodeGear(From Borland) 公司公布了最新的Delphi 2007 For Win32版本号.作为一个 Delphi 的使用者,第 ...

  8. [ES6] Array.findIndex()

    In es5, you can use indexOf to get the index of one item in an array. In es6, you can use findIndex( ...

  9. google(转帖)

    本帖最后由 qiushui_007 于 2014-6-10 16:14 编辑 IP Addresses of Google Global Cachewww.kookle.co.nr Bulgaria  ...

  10. 深入探索C++对象模型-1

    概述 在实际生产中,遇到一个复杂的类,如果能看出这个类的内存模型结构,那么以后的操作基本就没有难度的: 所以说,学会分析一个类的内存模型,是每一个C++程序员必须要会的知识. 下面,就让我们来了解C+ ...