C++中整型变量的存储大小和范围

一、代码查看

#include <iostream>
#include <climits>
using namespace std;
int main(void)
{
	cout << "signed char is " << sizeof(char) << " bytes." << endl;
	cout << "signed int is " << sizeof(int) << " bytes." << endl;
	cout << "signed short is " << sizeof(short) << " bytes." << endl;
	cout << "signed long is " << sizeof(long) << " bytes." << endl;
	cout << "signed long long is " << sizeof(long long) << " bytes." << endl << endl;

        //下面宏都是climits头文件中所定义,可打开改头文件观察
	cout << "Maxinum values and Mininum values: " << endl;
	cout << "signed char : " << SCHAR_MIN << " -- " << SCHAR_MAX << endl;
	cout << "signed int : " << INT_MAX << " -- "<< INT_MIN <<  endl;
	cout << "signed short : " << SHRT_MIN << " -- " << SHRT_MAX << endl;
	cout << "signed long : " << LONG_MIN << " -- " << LONG_MAX << endl;
	cout << "signed long long : " << LLONG_MIN << " -- " << LLONG_MAX << endl;
	return 0;
}

二、结果显示

  1. int类型10^9,超出就要使用long long类型
posted @ 2019-11-14 11:26  睿晞  阅读(1926)  评论(0编辑  收藏  举报