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类型


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM