選單
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP How To W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

C++ 教程

C++ 主頁 C++ 簡介 C++ 入門 C++ 語法 C++ 輸出 C++ 註釋 C++ 變數 C++ 使用者輸入 C++ 資料型別 C++ 運算子 C++ 字串 C++ 數學 C++ 布林值 C++ If...Else C++ Switch C++ While 迴圈 C++ For 迴圈 C++ Break/Continue C++ 陣列 C++ 結構體 C++ 列舉 C++ 引用 C++ 指標

C++ 函式

C++ 函式 C++ 函式引數 C++ 函式過載 C++ 作用域 C++ 遞迴

C++ 類

C++ OOP C++ 類/物件 C++ 類方法 C++ 建構函式 C++ 訪問修飾符 C++ 封裝 C++ 繼承 C++ 多型 C++ 檔案 C++ 異常 C++ 日期

C++ 資料結構

C++ 資料結構與 STL C++ Vectors C++ List C++ Stacks C++ Queues C++ Deque C++ Sets C++ Maps C++ 迭代器 C++ 演算法

C++ How To

C++ 兩數相加 C++ 隨機數

C++ 參考

C++ 參考 C++ 關鍵字 C++ <iostream> C++ <fstream> C++ <cmath> C++ <string> C++ <cstring> C++ <ctime> C++ <vector> C++ <algorithm>

C++ 示例

C++ 示例 C++ 現實生活中的例子 C++ 編譯器 C++ 練習 C++ 測驗 C++ 證書


C++ int 關鍵字

❮ C++ 關鍵字


示例

int myNum = 100000;
cout << myNum;

自己動手試一試 »


定義和用法

The int keyword is a data type that is usually 32 bits long which stores whole numbers. Most implementations will give the int type 32 bits, but some only give it 16 bits.

使用 16 位,它可以儲存介於 -32768 和 32767 之間的正負數,或者在無符號時儲存 0 到 65535 之間的數。

使用 32 位時,它可以儲存值介於 -2147483648 和 2147483647 之間的正數和負數,或者在無符號時儲存介於 0 和 4294967295 之間的正數。

修飾符

The size of the int can be modified with the short and long modifiers.

The short keyword ensures a maximum of 16 bits.

The long keyword ensures at least 32 bits but may extend it to 64 bits. long long ensures at least 64 bits.

64 bits can store positive and negative numbers with values between -9223372036854775808 and 9223372036854775807, or between 0 and 18446744073709551615 when unsigned.


更多示例

示例

建立有符號、無符號、短整型和長整型
int myInt = 4294967292;
unsigned int myUInt = 4294967292;
short int mySInt = 65532;
unsigned short int myUSInt = 65532;
long int myLInt = 18446744073709551612;
unsigned long int myULInt = 18446744073709551612;
cout << " size: " << 8*sizeof(myInt)   << " bits  value: " << myInt   << "\n";
cout << " size: " << 8*sizeof(myUInt)  << " bits  value: " << myUInt  << "\n";
cout << " size: " << 8*sizeof(mySInt)  << " bits  value: " << mySInt  << "\n";
cout << " size: " << 8*sizeof(myUSInt) << " bits  value: " << myUSInt << "\n";
cout << " size: " << 8*sizeof(myLInt)  << " bits  value: " << myLInt  << "\n";
cout << " size: " << 8*sizeof(myULInt) << " bits  value: " << myULInt << "\n";

自己動手試一試 »


相關頁面

The unsigned keyword can allow an int to represent larger positive numbers by not representing negative numbers.

The short keyword ensures that an int has 16 bits.

The long keyword ensures that an int has at least 32 bits.

在我們的 C++ 資料型別教程 中瞭解更多關於資料型別的資訊。


❮ C++ 關鍵字

×

聯絡銷售

如果您想將 W3Schools 服務用於教育機構、團隊或企業,請傳送電子郵件給我們
sales@w3schools.com

報告錯誤

如果您想報告錯誤,或想提出建議,請傳送電子郵件給我們
help@w3schools.com

W3Schools 經過最佳化,旨在方便學習和培訓。示例可能經過簡化,以提高閱讀和學習體驗。教程、參考資料和示例會不斷審查,以避免錯誤,但我們無法保證所有內容的完全正確性。使用 W3Schools 即表示您已閱讀並接受我們的使用條款Cookie 和隱私政策

版權所有 1999-2024 Refsnes Data。保留所有權利。W3Schools 由 W3.CSS 提供支援