获取变量字节以及存储的最大值和最小值

前言:

各种变量类型在内存中存储都需要占用内存(即字节数),并且该类型都有各自能存储的最大值以及最小值,因电脑而异。

示例代码:

// type_value.cpp: 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <limits>
using namespace std;

//by zhaocl
int main()
{
    cout << "---------------type begin---------------------" << endl;

    //bool
    cout << "bool size:" << sizeof( bool );
    cout << "\t MaxValue:" << ( numeric_limits<bool>::max )();
    cout << "\t MinValue:" << ( numeric_limits<bool>::min )() << endl;

    //int
    cout << "int size:" << sizeof( int );
    cout << "\t MaxValue:" << ( numeric_limits<int>::max )();
    cout << "\t MinValue:" << ( numeric_limits<int>::min )() << endl;

    //unsigned int
    cout << "unsigned int size:" << sizeof( unsigned int );
    cout << "\t MaxValue:" << ( numeric_limits<unsigned int>::max )();
    cout << "\t MinValue:" << ( numeric_limits<unsigned int>::min )() << endl;

    //the same as other ...

    cout << "---------------type end---------------------" << endl;
    system( "pause" );
    return 0;
}


知识点:

(numeric_limits<type>::max)()的使用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值