查看“︁01-基础语法/03-变量与基础类型”︁的源代码
←
01-基础语法/03-变量与基础类型
跳转到导航
跳转到搜索
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
以下所有描述的都指当前比赛环境。 === 常见数据类型/变量类型 === {| class="wikitable" ! !! 有符号整数 !! 无符号整数 |- | <math>32</math> 位 | <code>int</code>、<code>signed</code> | <code>unsigned</code>、<code>unsigned int</code> |- | <math>64</math> 位 | <code>long long</code> | <code>unsigned long long</code> |} - 小数(浮点数): - 单精度:<code>float</code> - 双精度:<code>double</code> - 扩展精度:<code>long double</code> - 字符:<code>char</code> - 布尔:<code>bool</code> - 字符串:<code>string</code> === 变量定义规则 === 变量定义方法: <syntaxhighlight lang="cpp"> int a; //变量类型 变量名; int b = 0; //变量类型 变量名 = 初始值; int c, d, e; //变量类型 变量名1, 变量名2, 变量名3; </syntaxhighlight> 变量命名规则: - 字母或下划线开头 - 只能包含字母、数字、下划线 - 不能是 C++ 关键字 === 数据类型对应的范围 === - bit:位(<math>1</math> 个二进制位),计算机储存的最小单位 - Byte:字节(<math>8</math> 个连续的二进制位),计算机储存的基本单位 - 换算方法: - <math>1</math> B(Byte) = <math>8</math> bits - <math>1</math> KB(KiB) = <math>1024</math> B(<math>2^{10}</math> B) - <math>1</math> MB(MiB) = <math>1024</math> KB - <math>1</math> GB(GiB) = <math>1024</math> MB - <math>1</math> TB(TiB) = <math>1024</math> GB - <math>1</math> PB(PiB) = <math>1024</math> TB {| class="wikitable" ! 数据类型名 !! 内容(一般情况) !! 占用内存大小 !! 能储存的范围 !! <code>scanf</code>/<code>printf</code> 标识符(g++) |- | <code>int</code>/<code>signed</code> | <math>32</math> 位整数 | <math>4</math> Bytes | <math>-2^{31}\sim 2^{31}-1</math>,约 <math>-2\times 10^9\sim 2\times 10^9</math> | <code>%d</code>/<code>%d</code> |- | <code>long long</code> | <math>64</math> 位整数 | <math>8</math> Bytes | <math>-2^{63}\sim 2^{63}-1</math>,约 <math>-9\times 10^{18}\sim 9\times 10^{18}</math> | <code>%lld</code>/<code>%lld</code> |- | <code>char</code> | 字符 | <math>1</math> Byte | 至少能储存 <math>0\sim 127</math>,常见范围为 <math>-128\sim 127</math> | <code>%c</code>/<code>%c</code> |- | <code>float</code> | 单精度浮点数 | <math>4</math> Bytes | <math>-3.4\times 10^{38}\sim 3.4\times 10^{38}</math>,有效数字 <math>6\sim 7</math> 位 | <code>%f</code>/<code>%f</code> |- | <code>double</code> | 双精度浮点数 | <math>8</math> Bytes | <math>-1.7\times 10^{308}\sim 1.7\times 10^{308}</math>,有效数字 <math>15\sim 16</math> 位 | <code>%lf</code>/<code>%f</code> |- | <code>unsigned int</code> | 无符号 <math>32</math> 位整数 | <math>4</math> Bytes | <math>0 \sim 2^{32}-1</math>,约 <math>0 \sim 4\times 10^9</math> | <code>%u</code>/<code>%u</code> |- | <code>unsigned long long</code> | 无符号 <math>64</math> 位整数 | <math>8</math> Bytes | <math>0 \sim 2^{64}-1</math>,约 <math>0 \sim 1.8\times 10^{19}</math> | <code>%llu</code>/<code>%llu</code> |} === 类型转换 === - 用一个目标类型的数参与运算(必须是更优先的类型): - <code>1.0 * a</code> - <code>1LL * a</code>(默认情况下 <code>1</code> 为 <code>int</code> 类型,在后面加上 <code>ll</code> 或 <code>LL</code> 可以得到一个 <code>long long</code> 类型的 <code>1</code>) - 存入一个目标类型的变量: - <code>char c = 'a' - 32;</code> - 用 <code>(type)</code> 前缀,这个前缀会把紧跟着的数变为 <code>type</code> 类型: - <code>(double)p / q</code> - <code>(char)('a' - 32)</code> [[Category:基础语法]] [[Category:三三文档]]
返回
01-基础语法/03-变量与基础类型
。
导航菜单
个人工具
登录
命名空间
页面
讨论
大陆简体
查看
阅读
查看源代码
查看历史
更多
搜索
导航
首页
最近更改
随机页面
MediaWiki帮助
特殊页面
工具
链入页面
相关更改
页面信息