菜单
×
   ❮     
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 提供支持