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