【C++】简单数据类型详解

news/2024/11/29 6:41:28/
class="tags" href="/C.html" title=c>cle class="tags" href="/C.html" title=c>class="baidu_pl">
class="tags" href="/C.html" title=c>cle_class="tags" href="/C.html" title=c>content" class="tags" href="/C.html" title=c>class="articlass="tags" href="/C.html" title=c>cle_class="tags" href="/C.html" title=c>content class="tags" href="/C.html" title=c>clearfix">
class="tags" href="/C.html" title=c>content_views" class="tags" href="/C.html" title=c>class="markdown_views prism-tomorrow-night">class="tags" href="/C.html" title=c>cap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-bloclass="tags" href="/C.html" title=c>ck" style="-webkit-tap-highlight-class="tags" href="/C.html" title=c>color: rgba(0, 0, 0, 0);">

class="tags" href="/C.html" title=c>c="https://i-blog.class="tags" href="/C.html" title=c>csdnimg.class="tags" href="/C.html" title=c>cn/direclass="tags" href="/C.html" title=c>ct/class="tags" href="/C.html" title=c>cb7f73class="tags" href="/C.html" title=c>cda1a14130840e356class="tags" href="/C.html" title=c>cb0b6f9e4.png#piclass="tags" href="/C.html" title=c>c_class="tags" href="/C.html" title=c>center" alt="在这里插入图片描述" width="100" />

<class="tags" href="/C.html" title=c>center> 博客主页: [小ᶻ☡꙳ᵃⁱᵍᶜ꙳] class="tags" href="/C.html" title=c>center> <class="tags" href="/C.html" title=c>center> 本文专栏: C++ class="tags" href="/C.html" title=c>center>

class="tags" href="/C.html" title=c>class="toclass="tags" href="/C.html" title=c>c">

文章目录

  • 💯前言
  • 💯字符型(class="tags" href="/C.html" title=c>char)
    • 1.1 ASCII 码表
  • 💯整型(int)
    • 2.1 整型的分类
    • 2.2 有符号和无符号整型
    • 2.3 跨平台差异
    • 2.4 整型数据类型比较表
  • 💯浮点型(float, double, long double)
    • 3.1 浮点型的分类
    • 3.2 在 C/C++ 中小数的书写形式
    • 3.3 为什么需要后缀 `f`?
    • 3.4 浮点型数据类型比较表
  • 💯布尔型(bool)
  • 💯总结与应用场景
  • 五、总结


class="tags" href="/C.html" title=c>c="https://img-blog.class="tags" href="/C.html" title=c>csdnimg.class="tags" href="/C.html" title=c>cn/direclass="tags" href="/C.html" title=c>ct/00d4fdeb7b0d4dbb99e88f325ef249d8.gif#piclass="tags" href="/C.html" title=c>c_class="tags" href="/C.html" title=c>center" alt="在这里插入图片描述" width="1000" height="100" />


💯前言

<class="tags" href="/C.html" title=c>code>C++class="tags" href="/C.html" title=c>code> 是一门功能强大且灵活的编程语言࿰class="tags" href="/C.html" title=c>c;能够处理从简单到复杂的各种数据。理解 <class="tags" href="/C.html" title=c>code>C++class="tags" href="/C.html" title=c>code> 中的数据类型是编写高效和鲁棒代码的基石。本文将深入探讨 <class="tags" href="/C.html" title=c>code>C++class="tags" href="/C.html" title=c>code> 中各种数据类型的特性、内存占用、应用场景以及实现方式class="tags" href="/C.html" title=c>c;力求为读者提供系统性的理解。
C++ 中的数据类型可大致分为基本数据类型派生数据类型基本数据类型包括字符型整型浮点型布尔型class="tags" href="/C.html" title=c>c;这些类型是 C++ 编程中的基本单元࿰class="tags" href="/C.html" title=c>c;奠定了程序数据结构和逻辑运算的基础。 接下来࿰class="tags" href="/C.html" title=c>c;我们将详细分析每一种数据类型的定义、特性、应用及其在程序设计中的具体实现方式。

C++ 参考手册
class="tags" href="/C.html" title=c>c="https://i-blog.class="tags" href="/C.html" title=c>csdnimg.class="tags" href="/C.html" title=c>cn/direclass="tags" href="/C.html" title=c>ct/f0db7class="tags" href="/C.html" title=c>c348331440fa266b3class="tags" href="/C.html" title=c>c24f558694.png#piclass="tags" href="/C.html" title=c>c_class="tags" href="/C.html" title=c>center" alt="在这里插入图片描述" />


class="tags" href="/C.html" title=c>char_51">💯字符型(class="tags" href="/C.html" title=c>char)

class="tags" href="/C.html" title=c>c="https://i-blog.class="tags" href="/C.html" title=c>csdnimg.class="tags" href="/C.html" title=c>cn/direclass="tags" href="/C.html" title=c>ct/fclass="tags" href="/C.html" title=c>c6aclass="tags" href="/C.html" title=c>c6d93b4745b591bb8a8e48f86779.png#piclass="tags" href="/C.html" title=c>c_right" alt="在这里插入图片描述" width="1" />
使用场景:字符型用于存储单个字符࿰class="tags" href="/C.html" title=c>c;例如 ASCII 字符集中的字符。通常占用 1 字节class="tags" href="/C.html" title=c>c;它的存储范围可以涵盖简单字符࿰class="tags" href="/C.html" title=c>c;如字母、数字和特殊符号。字符型通常用于表示标识符、符号或者单个字母。

  • class="tags" href="/C.html" title=c>char 是 C++ 中的基本数据类型࿰class="tags" href="/C.html" title=c>c;专门用于表示字符。
  • 存储范围:通常为 -128 到 127(有符号)࿰class="tags" href="/C.html" title=c>c;或 0 到 255(无符号)。
  • 内存占用:1 字节。

在 C++ 中࿰class="tags" href="/C.html" title=c>c;字符以 ASCII 编码 的形式存储࿰class="tags" href="/C.html" title=c>c;每个字符都有一个相应的 ASCII 值。例如࿰class="tags" href="/C.html" title=c>c;大写字母 ‘A’ 的 ASCII 值是 65࿰class="tags" href="/C.html" title=c>c;而小写字母 ‘a’ 的 ASCII 值是 97。ASCII 编码是一种标准化的字符编码方案࿰class="tags" href="/C.html" title=c>c;便于在不同的计算机系统之间交换信息。


1.1 ASCII 码表

class="tags" href="/C.html" title=c>c="https://i-blog.class="tags" href="/C.html" title=c>csdnimg.class="tags" href="/C.html" title=c>cn/direclass="tags" href="/C.html" title=c>ct/fclass="tags" href="/C.html" title=c>c6aclass="tags" href="/C.html" title=c>c6d93b4745b591bb8a8e48f86779.png#piclass="tags" href="/C.html" title=c>c_right" alt="在这里插入图片描述" width="1" />
下列表格包含有全部 128 个 ASCII 十进制 (declass="tags" href="/C.html" title=c>c)、八进制 (oclass="tags" href="/C.html" title=c>ct)、十六进制 (hex) 及字符 (class="tags" href="/C.html" title=c>ch) 编码。

declass="tags" href="/C.html" title=c>c (十进制)oclass="tags" href="/C.html" title=c>ct (八进制)hex (十六进制)class="tags" href="/C.html" title=c>ch (字符)
000000NUL (空)
100101SOH (标题开始)
200202STX (正文开始)
300303ETX (正文结束)
400404EOT (传送结束)
500505ENQ (询问)
600606ACK (确认)
700707BEL (响铃)
801008BS (退格)
901109HT (横向制表)
100120ALF (换行)
110130BVT (纵向制表)
120140CFF (换页)
130150DCR (回车)
140160ESO (移出)
150170FSI (移入)
1602010DLE (退出数据链)
1702111DC1 (设备控制1)
1802212DC2 (设备控制2)
1902313DC3 (设备控制3)
2002414DC4 (设备控制4)
2102515NAK (反确认)
2202616SYN (同步空闲)
2302717ETB (传输块结束)
2403018CAN (取消)
2503119EM (媒介结束)
260321ASUB (替换)
270331BESC (退出)
280341CFS (文件分隔符)
290351DGS (组分隔符)
300361ERS (记录分隔符)
310371FUS (单元分隔符)
3204020(空格)
3304121!
3404222"
3504323#
3604424$
3704525%
3804626&
3904727
4005028(
4105129)
420522A*
430532B+
440542C,
450552D-
460562E.
470572F/
48060300
49061311
50062322
51063333
52064344
53065355
54066366
55067377
56070388
57071399
580723A:
590733B;
600743C<
610753D=
620763E>
630773F?
6410040@
6510141A
6610242B
6710343C
6810444D
6910545E
7010646F
7110747G
7211048H
7311149I
741124AJ
751134BK
761144CL
771154DM
781164EN
791174FO
8012050P
8112151Q
8212252R
8312353S
8412454T
8512555U
8612656V
8712757W
8813058X
8913159Y
901325AZ
911335B[
921345C\
931355D]
941365E^
951375F_
9614060`
9714161a
9814262b
9914363class="tags" href="/C.html" title=c>c
10014464d
10114565e
10214666f
10314767g
10415068h
10515169i
1061526Aj
1071536Bk
1081546Cl
1091556Dm
1101566En
1111576Fo
11216070p
11316171q
11416272r
11516373s
11616474t
11716575u
11816676v
11916777w
12017078x
12117179y
1221727Az
1231737B{
1241747C
1251757D}
1261767E~
1271777FDEL (删除)

此表适用于基础编程学习与字符编码参考。

常见的 ASCII 码应用

  • 字符 <class="tags" href="/C.html" title=c>code>A-Zclass="tags" href="/C.html" title=c>code> 的 ASCII 码值为 65-90
  • 字符 <class="tags" href="/C.html" title=c>code>a-zclass="tags" href="/C.html" title=c>code> 的 ASCII 码值为 97-122
  • 数字字符 <class="tags" href="/C.html" title=c>code>0-9class="tags" href="/C.html" title=c>code> 的 ASCII 码值为 48-57
  • 换行符 <class="tags" href="/C.html" title=c>code> class="tags" href="/C.html" title=c>code> 的 ASCII 码值为 10

在 C++ 程序中࿰class="tags" href="/C.html" title=c>c;可以使用 ASCII 码来实现字符与整数的转换࿰class="tags" href="/C.html" title=c>c;从而简化某些数据操作。例如࿰class="tags" href="/C.html" title=c>c;可以将字符转换为其对应的 ASCII 值࿰class="tags" href="/C.html" title=c>c;或者根据整数值生成相应的字符。

示例代码

<class="tags" href="/C.html" title=c>code class="tags" href="/C.html" title=c>class="prism language-class="tags" href="/C.html" title=c>cpp">class="tags" href="/C.html" title=c>class="token maclass="tags" href="/C.html" title=c>cro property">class="tags" href="/C.html" title=c>class="token direclass="tags" href="/C.html" title=c>ctive-hash">#class="tags" href="/C.html" title=c>class="token direclass="tags" href="/C.html" title=c>ctive keyword">inclass="tags" href="/C.html" title=c>clude class="tags" href="/C.html" title=c>class="token string"><iostream>class="tags" href="/C.html" title=c>class="token keyword">int class="tags" href="/C.html" title=c>class="token funclass="tags" href="/C.html" title=c>ction">mainclass="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">(class="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">) class="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">{class="tags" href="/C.html" title=c>class="token keyword">class="tags" href="/C.html" title=c>char class="tags" href="/C.html" title=c>c1 class="tags" href="/C.html" title=c>class="token operator">= class="tags" href="/C.html" title=c>class="token class="tags" href="/C.html" title=c>char">'A'class="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">;class="tags" href="/C.html" title=c>class="token keyword">int asclass="tags" href="/C.html" title=c>ciiValue class="tags" href="/C.html" title=c>class="token operator">= class="tags" href="/C.html" title=c>class="token genericlass="tags" href="/C.html" title=c>c-funclass="tags" href="/C.html" title=c>ction">class="tags" href="/C.html" title=c>class="token funclass="tags" href="/C.html" title=c>ction">staticlass="tags" href="/C.html" title=c>c_class="tags" href="/C.html" title=c>castclass="tags" href="/C.html" title=c>class="token genericlass="tags" href="/C.html" title=c>c class="tags" href="/C.html" title=c>class-name">class="tags" href="/C.html" title=c>class="token operator"><class="tags" href="/C.html" title=c>class="token keyword">intclass="tags" href="/C.html" title=c>class="token operator">>class="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">(class="tags" href="/C.html" title=c>c1class="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">)class="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">;stdclass="tags" href="/C.html" title=c>class="token double-class="tags" href="/C.html" title=c>colon punclass="tags" href="/C.html" title=c>ctuation">::class="tags" href="/C.html" title=c>cout class="tags" href="/C.html" title=c>class="token operator"><< class="tags" href="/C.html" title=c>class="token string">"字符 A 的 ASCII 值是: " class="tags" href="/C.html" title=c>class="token operator"><< asclass="tags" href="/C.html" title=c>ciiValue class="tags" href="/C.html" title=c>class="token operator"><< stdclass="tags" href="/C.html" title=c>class="token double-class="tags" href="/C.html" title=c>colon punclass="tags" href="/C.html" title=c>ctuation">::endlclass="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">;class="tags" href="/C.html" title=c>class="token keyword">class="tags" href="/C.html" title=c>char class="tags" href="/C.html" title=c>c2 class="tags" href="/C.html" title=c>class="token operator">= class="tags" href="/C.html" title=c>class="token number">66class="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">;  class="tags" href="/C.html" title=c>class="token class="tags" href="/C.html" title=c>comment">// 直接使用 ASCII 值表示字符stdclass="tags" href="/C.html" title=c>class="token double-class="tags" href="/C.html" title=c>colon punclass="tags" href="/C.html" title=c>ctuation">::class="tags" href="/C.html" title=c>cout class="tags" href="/C.html" title=c>class="token operator"><< class="tags" href="/C.html" title=c>class="token string">"ASCII 值 66 对应的字符是: " class="tags" href="/C.html" title=c>class="token operator"><< class="tags" href="/C.html" title=c>c2 class="tags" href="/C.html" title=c>class="token operator"><< stdclass="tags" href="/C.html" title=c>class="token double-class="tags" href="/C.html" title=c>colon punclass="tags" href="/C.html" title=c>ctuation">::endlclass="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">;class="tags" href="/C.html" title=c>class="token keyword">return class="tags" href="/C.html" title=c>class="token number">0class="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">;
class="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">}
class="tags" href="/C.html" title=c>code>

输出

<class="tags" href="/C.html" title=c>code>字符 A 的 ASCII 值是: 65
ASCII 值 66 对应的字符是: B
class="tags" href="/C.html" title=c>code>

在这个例子中࿰class="tags" href="/C.html" title=c>c;我们将字符 <class="tags" href="/C.html" title=c>code>'A'class="tags" href="/C.html" title=c>code> 转换为它的 ASCII 值࿰class="tags" href="/C.html" title=c>c;并直接使用 ASCII 值 <class="tags" href="/C.html" title=c>code>66class="tags" href="/C.html" title=c>code> 来表示字符 <class="tags" href="/C.html" title=c>code>'B'class="tags" href="/C.html" title=c>code>。

字符型在程序中的灵活性使得它在文本处理和符号运算中非常有用。例如࿰class="tags" href="/C.html" title=c>c;我们可以使用字符的 ASCII 值关系将所有小写字母转换为大写字母。以下是一个例子:

示例代码

<class="tags" href="/C.html" title=c>code class="tags" href="/C.html" title=c>class="prism language-class="tags" href="/C.html" title=c>cpp">class="tags" href="/C.html" title=c>class="token maclass="tags" href="/C.html" title=c>cro property">class="tags" href="/C.html" title=c>class="token direclass="tags" href="/C.html" title=c>ctive-hash">#class="tags" href="/C.html" title=c>class="token direclass="tags" href="/C.html" title=c>ctive keyword">inclass="tags" href="/C.html" title=c>clude class="tags" href="/C.html" title=c>class="token string"><iostream>class="tags" href="/C.html" title=c>class="token keyword">int class="tags" href="/C.html" title=c>class="token funclass="tags" href="/C.html" title=c>ction">mainclass="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">(class="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">) class="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">{class="tags" href="/C.html" title=c>class="token keyword">for class="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">(class="tags" href="/C.html" title=c>class="token keyword">class="tags" href="/C.html" title=c>char class="tags" href="/C.html" title=c>c class="tags" href="/C.html" title=c>class="token operator">= class="tags" href="/C.html" title=c>class="token class="tags" href="/C.html" title=c>char">'a'class="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">; class="tags" href="/C.html" title=c>c class="tags" href="/C.html" title=c>class="token operator"><= class="tags" href="/C.html" title=c>class="token class="tags" href="/C.html" title=c>char">'z'class="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">; class="tags" href="/C.html" title=c>class="token operator">++class="tags" href="/C.html" title=c>cclass="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">) class="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">{class="tags" href="/C.html" title=c>class="token keyword">class="tags" href="/C.html" title=c>char upperCase class="tags" href="/C.html" title=c>class="token operator">= class="tags" href="/C.html" title=c>c class="tags" href="/C.html" title=c>class="token operator">- class="tags" href="/C.html" title=c>class="token number">32class="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">;  class="tags" href="/C.html" title=c>class="token class="tags" href="/C.html" title=c>comment">// ASCII 中大写字母与小写字母之间的差值为 32stdclass="tags" href="/C.html" title=c>class="token double-class="tags" href="/C.html" title=c>colon punclass="tags" href="/C.html" title=c>ctuation">::class="tags" href="/C.html" title=c>cout class="tags" href="/C.html" title=c>class="token operator"><< class="tags" href="/C.html" title=c>c class="tags" href="/C.html" title=c>class="token operator"><< class="tags" href="/C.html" title=c>class="token string">" -> " class="tags" href="/C.html" title=c>class="token operator"><< upperCase class="tags" href="/C.html" title=c>class="token operator"><< stdclass="tags" href="/C.html" title=c>class="token double-class="tags" href="/C.html" title=c>colon punclass="tags" href="/C.html" title=c>ctuation">::endlclass="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">;class="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">}class="tags" href="/C.html" title=c>class="token keyword">return class="tags" href="/C.html" title=c>class="token number">0class="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">;
class="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">}
class="tags" href="/C.html" title=c>code>

输出

<class="tags" href="/C.html" title=c>code>a -> A
b -> B
...
z -> Z
class="tags" href="/C.html" title=c>code>

这种方式利用了 ASCII 值之间的数学关系࿰class="tags" href="/C.html" title=c>c;有效地实现了字符的转换。此类技术在文本处理、字符比较等场景中非常有用。


💯整型(int)

class="tags" href="/C.html" title=c>c="https://i-blog.class="tags" href="/C.html" title=c>csdnimg.class="tags" href="/C.html" title=c>cn/direclass="tags" href="/C.html" title=c>ct/fclass="tags" href="/C.html" title=c>c6aclass="tags" href="/C.html" title=c>c6d93b4745b591bb8a8e48f86779.png#piclass="tags" href="/C.html" title=c>c_right" alt="在这里插入图片描述" width="1" />
整型用于存储整数࿰class="tags" href="/C.html" title=c>c;包括正数、负数和零。C++ 提供了多种整型࿰class="tags" href="/C.html" title=c>c;以适应不同数据范围和内存占用的需求。


2.1 整型的分类

class="tags" href="/C.html" title=c>c="https://i-blog.class="tags" href="/C.html" title=c>csdnimg.class="tags" href="/C.html" title=c>cn/direclass="tags" href="/C.html" title=c>ct/fclass="tags" href="/C.html" title=c>c6aclass="tags" href="/C.html" title=c>c6d93b4745b591bb8a8e48f86779.png#piclass="tags" href="/C.html" title=c>c_right" alt="在这里插入图片描述" width="1" />

  • short:短整型࿰class="tags" href="/C.html" title=c>c;占用 2 字节࿰class="tags" href="/C.html" title=c>c;存储范围为 -32,768 到 32,767。适用于较小范围的整数。
  • int:标准整型࿰class="tags" href="/C.html" title=c>c;占用 4 字节࿰class="tags" href="/C.html" title=c>c;存储范围为 -2,147,483,648 到 2,147,483,647。适用于大多数日常应用。
  • long:长整型࿰class="tags" href="/C.html" title=c>c;在 32 位系统中通常与 int 相同࿰class="tags" href="/C.html" title=c>c;占用 4 字节;在 64 位系统中通常占用 8 字节。适合需要更大存储空间的场景。
  • long long:更长的整型࿰class="tags" href="/C.html" title=c>c;占用 8 字节࿰class="tags" href="/C.html" title=c>c;存储范围为 -9,223,372,036,854,775,808 到 9,223,372,036,854,775,807。适用于存储非常大的整数。

每种整型在不同平台和编译器上的实现可能有所不同࿰class="tags" href="/C.html" title=c>c;因此为了确保跨平台代码的兼容性࿰class="tags" href="/C.html" title=c>c;通常需要使用 <class="tags" href="/C.html" title=c>code><class="tags" href="/C.html" title=c>cstdint>class="tags" href="/C.html" title=c>code> 提供的固定宽度整数类型࿰class="tags" href="/C.html" title=c>c;例如 <class="tags" href="/C.html" title=c>code>int32_tclass="tags" href="/C.html" title=c>code>、<class="tags" href="/C.html" title=c>code>int64_tclass="tags" href="/C.html" title=c>code>。


2.2 有符号和无符号整型

class="tags" href="/C.html" title=c>c="https://i-blog.class="tags" href="/C.html" title=c>csdnimg.class="tags" href="/C.html" title=c>cn/direclass="tags" href="/C.html" title=c>ct/fclass="tags" href="/C.html" title=c>c6aclass="tags" href="/C.html" title=c>c6d93b4745b591bb8a8e48f86779.png#piclass="tags" href="/C.html" title=c>c_right" alt="在这里插入图片描述" width="1" />

  • 有符号类型(默认):可以存储正数和负数。
  • 无符号类型:只能存储非负数࿰class="tags" href="/C.html" title=c>c;使用 <class="tags" href="/C.html" title=c>code>unsignedclass="tags" href="/C.html" title=c>code> 关键字定义࿰class="tags" href="/C.html" title=c>c;例如 <class="tags" href="/C.html" title=c>code>unsigned intclass="tags" href="/C.html" title=c>code>。

无符号整型特别适合用于确保数值始终为非负数的场景࿰class="tags" href="/C.html" title=c>c;例如循环计数器、数组索引等。

示例代码

<class="tags" href="/C.html" title=c>code class="tags" href="/C.html" title=c>class="prism language-class="tags" href="/C.html" title=c>cpp">class="tags" href="/C.html" title=c>class="token keyword">short s class="tags" href="/C.html" title=c>class="token operator">= class="tags" href="/C.html" title=c>class="token number">32000class="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">;
class="tags" href="/C.html" title=c>class="token keyword">int i class="tags" href="/C.html" title=c>class="token operator">= class="tags" href="/C.html" title=c>class="token number">1000000class="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">;
class="tags" href="/C.html" title=c>class="token keyword">long l class="tags" href="/C.html" title=c>class="token operator">= class="tags" href="/C.html" title=c>class="token number">1000000000class="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">;
class="tags" href="/C.html" title=c>class="token keyword">long class="tags" href="/C.html" title=c>class="token keyword">long ll class="tags" href="/C.html" title=c>class="token operator">= class="tags" href="/C.html" title=c>class="token number">9000000000000000000class="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">;
class="tags" href="/C.html" title=c>class="token keyword">unsigned class="tags" href="/C.html" title=c>class="token keyword">int ui class="tags" href="/C.html" title=c>class="token operator">= class="tags" href="/C.html" title=c>class="token number">4000000000class="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">;stdclass="tags" href="/C.html" title=c>class="token double-class="tags" href="/C.html" title=c>colon punclass="tags" href="/C.html" title=c>ctuation">::class="tags" href="/C.html" title=c>cout class="tags" href="/C.html" title=c>class="token operator"><< class="tags" href="/C.html" title=c>class="token string">"short: " class="tags" href="/C.html" title=c>class="token operator"><< s class="tags" href="/C.html" title=c>class="token operator"><< stdclass="tags" href="/C.html" title=c>class="token double-class="tags" href="/C.html" title=c>colon punclass="tags" href="/C.html" title=c>ctuation">::endlclass="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">;
stdclass="tags" href="/C.html" title=c>class="token double-class="tags" href="/C.html" title=c>colon punclass="tags" href="/C.html" title=c>ctuation">::class="tags" href="/C.html" title=c>cout class="tags" href="/C.html" title=c>class="token operator"><< class="tags" href="/C.html" title=c>class="token string">"int: " class="tags" href="/C.html" title=c>class="token operator"><< i class="tags" href="/C.html" title=c>class="token operator"><< stdclass="tags" href="/C.html" title=c>class="token double-class="tags" href="/C.html" title=c>colon punclass="tags" href="/C.html" title=c>ctuation">::endlclass="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">;
stdclass="tags" href="/C.html" title=c>class="token double-class="tags" href="/C.html" title=c>colon punclass="tags" href="/C.html" title=c>ctuation">::class="tags" href="/C.html" title=c>cout class="tags" href="/C.html" title=c>class="token operator"><< class="tags" href="/C.html" title=c>class="token string">"long: " class="tags" href="/C.html" title=c>class="token operator"><< l class="tags" href="/C.html" title=c>class="token operator"><< stdclass="tags" href="/C.html" title=c>class="token double-class="tags" href="/C.html" title=c>colon punclass="tags" href="/C.html" title=c>ctuation">::endlclass="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">;
stdclass="tags" href="/C.html" title=c>class="token double-class="tags" href="/C.html" title=c>colon punclass="tags" href="/C.html" title=c>ctuation">::class="tags" href="/C.html" title=c>cout class="tags" href="/C.html" title=c>class="token operator"><< class="tags" href="/C.html" title=c>class="token string">"long long: " class="tags" href="/C.html" title=c>class="token operator"><< ll class="tags" href="/C.html" title=c>class="token operator"><< stdclass="tags" href="/C.html" title=c>class="token double-class="tags" href="/C.html" title=c>colon punclass="tags" href="/C.html" title=c>ctuation">::endlclass="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">;
stdclass="tags" href="/C.html" title=c>class="token double-class="tags" href="/C.html" title=c>colon punclass="tags" href="/C.html" title=c>ctuation">::class="tags" href="/C.html" title=c>cout class="tags" href="/C.html" title=c>class="token operator"><< class="tags" href="/C.html" title=c>class="token string">"unsigned int: " class="tags" href="/C.html" title=c>class="token operator"><< ui class="tags" href="/C.html" title=c>class="token operator"><< stdclass="tags" href="/C.html" title=c>class="token double-class="tags" href="/C.html" title=c>colon punclass="tags" href="/C.html" title=c>ctuation">::endlclass="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">;
class="tags" href="/C.html" title=c>code>

在上述代码中࿰class="tags" href="/C.html" title=c>c;可以看到整型类型的多样性。无符号整型 <class="tags" href="/C.html" title=c>code>unsigned intclass="tags" href="/C.html" title=c>code> 可以表示的范围从 0 到 4,294,967,295࿰class="tags" href="/C.html" title=c>c;比有符号类型多出一倍的数值范围。


2.3 跨平台差异

class="tags" href="/C.html" title=c>c="https://i-blog.class="tags" href="/C.html" title=c>csdnimg.class="tags" href="/C.html" title=c>cn/direclass="tags" href="/C.html" title=c>ct/fclass="tags" href="/C.html" title=c>c6aclass="tags" href="/C.html" title=c>c6d93b4745b591bb8a8e48f86779.png#piclass="tags" href="/C.html" title=c>c_right" alt="在这里插入图片描述" width="1" />
不同系统和编译器对整型的实现可能存在差异࿰class="tags" href="/C.html" title=c>c;尤其是 long 类型。在 32 位系统中࿰class="tags" href="/C.html" title=c>c;<class="tags" href="/C.html" title=c>code>longclass="tags" href="/C.html" title=c>code> 和 <class="tags" href="/C.html" title=c>code>intclass="tags" href="/C.html" title=c>code> 的存储范围相同࿰class="tags" href="/C.html" title=c>c;而在 64 位系统中࿰class="tags" href="/C.html" title=c>c;<class="tags" href="/C.html" title=c>code>longclass="tags" href="/C.html" title=c>code> 通常占用 8 字节。

可以使用 <class="tags" href="/C.html" title=c>code>sizeofclass="tags" href="/C.html" title=c>code> 关键字查看数据类型的实际字节数:

<class="tags" href="/C.html" title=c>code class="tags" href="/C.html" title=c>class="prism language-class="tags" href="/C.html" title=c>cpp">stdclass="tags" href="/C.html" title=c>class="token double-class="tags" href="/C.html" title=c>colon punclass="tags" href="/C.html" title=c>ctuation">::class="tags" href="/C.html" title=c>cout class="tags" href="/C.html" title=c>class="token operator"><< class="tags" href="/C.html" title=c>class="token string">"Size of int: " class="tags" href="/C.html" title=c>class="token operator"><< class="tags" href="/C.html" title=c>class="token keyword">sizeofclass="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">(class="tags" href="/C.html" title=c>class="token keyword">intclass="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">) class="tags" href="/C.html" title=c>class="token operator"><< class="tags" href="/C.html" title=c>class="token string">" bytes" class="tags" href="/C.html" title=c>class="token operator"><< stdclass="tags" href="/C.html" title=c>class="token double-class="tags" href="/C.html" title=c>colon punclass="tags" href="/C.html" title=c>ctuation">::endlclass="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">;
class="tags" href="/C.html" title=c>code>

这种方式可以帮助开发者了解在不同平台上数据类型的存储情况࿰class="tags" href="/C.html" title=c>c;以确保程序的正确性和兼容性。


2.4 整型数据类型比较表

class="tags" href="/C.html" title=c>c="https://i-blog.class="tags" href="/C.html" title=c>csdnimg.class="tags" href="/C.html" title=c>cn/direclass="tags" href="/C.html" title=c>ct/fclass="tags" href="/C.html" title=c>c6aclass="tags" href="/C.html" title=c>c6d93b4745b591bb8a8e48f86779.png#piclass="tags" href="/C.html" title=c>c_right" alt="在这里插入图片描述" width="1" />

数据类型占用字节数(一般情况)有符号范围无符号范围
short2-32,768 到 32,7670 到 65,535
int4-2,147,483,648 到 2,147,483,6470 到 4,294,967,295
long4 或 8-2,147,483,648 到 2,147,483,647(32 位)0 到 18,446,744,073,709,551,615(64 位)
long long8-9,223,372,036,854,775,808 到 9,223,372,036,854,775,8070 到 18,446,744,073,709,551,615

整型的数据类型选择需要根据程序的实际需求࿰class="tags" href="/C.html" title=c>c;合理权衡内存占用和数据范围。例如࿰class="tags" href="/C.html" title=c>c;<class="tags" href="/C.html" title=c>code>shortclass="tags" href="/C.html" title=c>code> 适合用于占用内存少的小范围整数࿰class="tags" href="/C.html" title=c>c;而 <class="tags" href="/C.html" title=c>code>long longclass="tags" href="/C.html" title=c>code> 适合用于需要非常大数值范围的场景。


💯浮点型(float, double, long double)

class="tags" href="/C.html" title=c>c="https://i-blog.class="tags" href="/C.html" title=c>csdnimg.class="tags" href="/C.html" title=c>cn/direclass="tags" href="/C.html" title=c>ct/fclass="tags" href="/C.html" title=c>c6aclass="tags" href="/C.html" title=c>c6d93b4745b591bb8a8e48f86779.png#piclass="tags" href="/C.html" title=c>c_right" alt="在这里插入图片描述" width="1" />
浮点型用于表示带小数部分的数值࿰class="tags" href="/C.html" title=c>c;例如科学计算、物理测量等。C++ 提供了三种浮点型࿰class="tags" href="/C.html" title=c>c;以满足不同精度和内存需求。


3.1 浮点型的分类

class="tags" href="/C.html" title=c>c="https://i-blog.class="tags" href="/C.html" title=c>csdnimg.class="tags" href="/C.html" title=c>cn/direclass="tags" href="/C.html" title=c>ct/fclass="tags" href="/C.html" title=c>c6aclass="tags" href="/C.html" title=c>c6d93b4745b591bb8a8e48f86779.png#piclass="tags" href="/C.html" title=c>c_right" alt="在这里插入图片描述" width="1" />

  • float:单精度浮点型࿰class="tags" href="/C.html" title=c>c;占用 4 字节class="tags" href="/C.html" title=c>c;有效位数为 6-7 位。适用于对内存要求较高但对精度要求不太高的场景。
  • double:双精度浮点型࿰class="tags" href="/C.html" title=c>c;占用 8 字节class="tags" href="/C.html" title=c>c;有效位数为 15-16 位。适用于需要较高精度的计算。
  • long double:扩展精度浮点型࿰class="tags" href="/C.html" title=c>c;占用 10 或 16 字节(依系统而定)࿰class="tags" href="/C.html" title=c>c;有效位数为 18-19 位。适用于需要极高精度的场景。

浮点型在科学计算、物理仿真、金融数据分析等领域有着广泛的应用。浮点数在计算机中是通过科学计数法的方式表示的࿰class="tags" href="/C.html" title=c>c;因此浮点数的表示范围非常大࿰class="tags" href="/C.html" title=c>c;但在计算精度上可能会存在一定的误差。


3.2 在 C/C++ 中小数的书写形式

class="tags" href="/C.html" title=c>c="https://i-blog.class="tags" href="/C.html" title=c>csdnimg.class="tags" href="/C.html" title=c>cn/direclass="tags" href="/C.html" title=c>ct/fclass="tags" href="/C.html" title=c>c6aclass="tags" href="/C.html" title=c>c6d93b4745b591bb8a8e48f86779.png#piclass="tags" href="/C.html" title=c>c_right" alt="在这里插入图片描述" width="1" />
在 C/C++ 中࿰class="tags" href="/C.html" title=c>c;小数可以用多种形式来表示࿰class="tags" href="/C.html" title=c>c;以适应科学计数法的需求。

  • 3.14:编译器会默认识别为 <class="tags" href="/C.html" title=c>code>doubleclass="tags" href="/C.html" title=c>code> 类型。
  • 3.14f:明确声明为 <class="tags" href="/C.html" title=c>code>floatclass="tags" href="/C.html" title=c>code> 类型。
  • 1e5:科学计数法࿰class="tags" href="/C.html" title=c>c;表示 1.0 × 10^5
  • 1e5 + 10:表示 1 × 100000 + 10 = 100010
  • 1.23e5 + 10:表示 1.23 × 100000 + 10 = 123010

示例代码

<class="tags" href="/C.html" title=c>code class="tags" href="/C.html" title=c>class="prism language-class="tags" href="/C.html" title=c>cpp">class="tags" href="/C.html" title=c>class="token keyword">float a class="tags" href="/C.html" title=c>class="token operator">= class="tags" href="/C.html" title=c>class="token number">3.14fclass="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">;  class="tags" href="/C.html" title=c>class="token class="tags" href="/C.html" title=c>comment">// 必须加上后缀 f࿰class="tags" href="/C.html" title=c>c;否则 3.14 会被视为 double 类型
class="tags" href="/C.html" title=c>class="token keyword">double b class="tags" href="/C.html" title=c>class="token operator">= class="tags" href="/C.html" title=c>class="token number">1e5class="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">;   class="tags" href="/C.html" title=c>class="token class="tags" href="/C.html" title=c>comment">// 使用科学计数法
stdclass="tags" href="/C.html" title=c>class="token double-class="tags" href="/C.html" title=c>colon punclass="tags" href="/C.html" title=c>ctuation">::class="tags" href="/C.html" title=c>cout class="tags" href="/C.html" title=c>class="token operator"><< class="tags" href="/C.html" title=c>class="token string">"Float: " class="tags" href="/C.html" title=c>class="token operator"><< a class="tags" href="/C.html" title=c>class="token operator"><< "
Doubleclass="tags" href="/C.html" title=c>class="token operator">: " class="tags" href="/C.html" title=c>class="token operator"><< b class="tags" href="/C.html" title=c>class="token operator"><< stdclass="tags" href="/C.html" title=c>class="token double-class="tags" href="/C.html" title=c>colon punclass="tags" href="/C.html" title=c>ctuation">::endlclass="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">;
class="tags" href="/C.html" title=c>code>

3.3 为什么需要后缀 <class="tags" href="/C.html" title=c>code>fclass="tags" href="/C.html" title=c>code>?

class="tags" href="/C.html" title=c>c="https://i-blog.class="tags" href="/C.html" title=c>csdnimg.class="tags" href="/C.html" title=c>cn/direclass="tags" href="/C.html" title=c>ct/fclass="tags" href="/C.html" title=c>c6aclass="tags" href="/C.html" title=c>c6d93b4745b591bb8a8e48f86779.png#piclass="tags" href="/C.html" title=c>c_right" alt="在这里插入图片描述" width="1" />
在 C++ 中࿰class="tags" href="/C.html" title=c>c;默认情况下࿰class="tags" href="/C.html" title=c>c;带小数的常量被认为是 double 类型。如果要定义 float 类型的变量࿰class="tags" href="/C.html" title=c>c;必须在数值后添加 <class="tags" href="/C.html" title=c>code>fclass="tags" href="/C.html" title=c>code> 或 <class="tags" href="/C.html" title=c>code>Fclass="tags" href="/C.html" title=c>code> 后缀࿰class="tags" href="/C.html" title=c>c;否则会发生隐式类型转换࿰class="tags" href="/C.html" title=c>c;这可能导致性能下降或精度损失。

示例代码

<class="tags" href="/C.html" title=c>code class="tags" href="/C.html" title=c>class="prism language-class="tags" href="/C.html" title=c>cpp">class="tags" href="/C.html" title=c>class="token keyword">float a class="tags" href="/C.html" title=c>class="token operator">= class="tags" href="/C.html" title=c>class="token number">5.5fclass="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">;  class="tags" href="/C.html" title=c>class="token class="tags" href="/C.html" title=c>comment">// 必须加上后缀 f࿰class="tags" href="/C.html" title=c>c;否则 5.5 会被视为 double 类型
stdclass="tags" href="/C.html" title=c>class="token double-class="tags" href="/C.html" title=c>colon punclass="tags" href="/C.html" title=c>ctuation">::class="tags" href="/C.html" title=c>cout class="tags" href="/C.html" title=c>class="token operator"><< aclass="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">;  class="tags" href="/C.html" title=c>class="token class="tags" href="/C.html" title=c>comment">// 输出 5.5
class="tags" href="/C.html" title=c>code>

这种做法在对内存和性能有较高要求的场景中显得尤为重要。


3.4 浮点型数据类型比较表

class="tags" href="/C.html" title=c>c="https://i-blog.class="tags" href="/C.html" title=c>csdnimg.class="tags" href="/C.html" title=c>cn/direclass="tags" href="/C.html" title=c>ct/fclass="tags" href="/C.html" title=c>c6aclass="tags" href="/C.html" title=c>c6d93b4745b591bb8a8e48f86779.png#piclass="tags" href="/C.html" title=c>c_right" alt="在这里插入图片描述" width="1" />

数据类型默认后缀占用字节数有效位数(精度)范围
floatf46-7 位±3.4×10^-38 到 ±3.4×10^38
double815-16 位±1.7×10^-308 到 ±1.7×10^308
long double10 或 1618-19 位±3.4×10^-4932 到 ±3.4×10^4932

在需要高精度计算的场景中࿰class="tags" href="/C.html" title=c>c;通常使用 doublelong double 类型࿰class="tags" href="/C.html" title=c>c;而 float 则常用于对内存要求更高的应用中。


💯布尔型(bool)

class="tags" href="/C.html" title=c>c="https://i-blog.class="tags" href="/C.html" title=c>csdnimg.class="tags" href="/C.html" title=c>cn/direclass="tags" href="/C.html" title=c>ct/fclass="tags" href="/C.html" title=c>c6aclass="tags" href="/C.html" title=c>c6d93b4745b591bb8a8e48f86779.png#piclass="tags" href="/C.html" title=c>c_right" alt="在这里插入图片描述" width="1" />
布尔型用于表示逻辑上的真与假。它只有两个可能的取值:true(真)和 false(假)。布尔型在逻辑判断、条件控制和状态标记中有广泛应用。

  • 存储范围:<class="tags" href="/C.html" title=c>code>trueclass="tags" href="/C.html" title=c>code> 或 <class="tags" href="/C.html" title=c>code>falseclass="tags" href="/C.html" title=c>code>。
  • 内存占用:通常为 1 字节class="tags" href="/C.html" title=c>c;但编译器可能对其进行优化。

示例代码

<class="tags" href="/C.html" title=c>code class="tags" href="/C.html" title=c>class="prism language-class="tags" href="/C.html" title=c>cpp">class="tags" href="/C.html" title=c>class="token keyword">bool isStudent class="tags" href="/C.html" title=c>class="token operator">= class="tags" href="/C.html" title=c>class="token boolean">trueclass="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">;
class="tags" href="/C.html" title=c>class="token keyword">if class="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">(isStudentclass="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">) class="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">{stdclass="tags" href="/C.html" title=c>class="token double-class="tags" href="/C.html" title=c>colon punclass="tags" href="/C.html" title=c>ctuation">::class="tags" href="/C.html" title=c>cout class="tags" href="/C.html" title=c>class="token operator"><< class="tags" href="/C.html" title=c>class="token string">"This person is a student." class="tags" href="/C.html" title=c>class="token operator"><< stdclass="tags" href="/C.html" title=c>class="token double-class="tags" href="/C.html" title=c>colon punclass="tags" href="/C.html" title=c>ctuation">::endlclass="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">;
class="tags" href="/C.html" title=c>class="token punclass="tags" href="/C.html" title=c>ctuation">}
class="tags" href="/C.html" title=c>code>

布尔型因其简单和高效而在条件判断和逻辑控制中非常常见。


💯总结与应用场景

class="tags" href="/C.html" title=c>c="https://i-blog.class="tags" href="/C.html" title=c>csdnimg.class="tags" href="/C.html" title=c>cn/direclass="tags" href="/C.html" title=c>ct/fclass="tags" href="/C.html" title=c>c6aclass="tags" href="/C.html" title=c>c6d93b4745b591bb8a8e48f86779.png#piclass="tags" href="/C.html" title=c>c_right" alt="在这里插入图片描述" width="1" />
C++ 中的不同数据类型各有特点࿰class="tags" href="/C.html" title=c>c;适用于不同的编程需求。通过合理选择数据类型࿰class="tags" href="/C.html" title=c>c;可以优化程序的内存利用和计算性能。

  • 字符型 用于存储单个字符࿰class="tags" href="/C.html" title=c>c;适合用于标识符和符号表示。
  • 整型 提供了多种选择࿰class="tags" href="/C.html" title=c>c;从短整型到长整型࿰class="tags" href="/C.html" title=c>c;用于存储不同范围的整数。
  • 浮点型 适用于科学计算࿰class="tags" href="/C.html" title=c>c;提供了从单精度到扩展精度的多种精度选择。
  • 布尔型 适合用于逻辑控制和条件判断。

在嵌入式系统中࿰class="tags" href="/C.html" title=c>c;资源有限࿰class="tags" href="/C.html" title=c>c;合理选择数据类型尤为重要。而在科学计算领域࿰class="tags" href="/C.html" title=c>c;精度的选择又是核心考量。通过对数据类型的充分理解࿰class="tags" href="/C.html" title=c>c;开发者可以编写出更加高效、稳定的程序。


五、总结

class="tags" href="/C.html" title=c>c="https://i-blog.class="tags" href="/C.html" title=c>csdnimg.class="tags" href="/C.html" title=c>cn/direclass="tags" href="/C.html" title=c>ct/fclass="tags" href="/C.html" title=c>c6aclass="tags" href="/C.html" title=c>c6d93b4745b591bb8a8e48f86779.png#piclass="tags" href="/C.html" title=c>c_right" alt="在这里插入图片描述" width="1" />

  • class="tags" href="/C.html" title=c>c="https://i-blog.class="tags" href="/C.html" title=c>csdnimg.class="tags" href="/C.html" title=c>cn/direclass="tags" href="/C.html" title=c>ct/class="tags" href="/C.html" title=c>c676f4660a8a4b338b878d4b137e425b.png" alt="在这里插入图片描述" />
    理解 C++ 中的简单数据类型是编写高效健壮程序的基础。 不同的数据类型具有不同的<class="tags" href="/C.html" title=c>code>存储范围class="tags" href="/C.html" title=c>code>、<class="tags" href="/C.html" title=c>code>内存占用class="tags" href="/C.html" title=c>code>和<class="tags" href="/C.html" title=c>code>适用场景class="tags" href="/C.html" title=c>code>。 在编写代码时࿰class="tags" href="/C.html" title=c>c;根据实际需求选择合适的数据类型class="tags" href="/C.html" title=c>c;既可以提高程序的运行效率࿰class="tags" href="/C.html" title=c>c;又能有效利用系统资源。 通过对 C++ 数据类型的深入理解࿰class="tags" href="/C.html" title=c>c;开发者能够更好地<class="tags" href="/C.html" title=c>code>控制内存class="tags" href="/C.html" title=c>code>、<class="tags" href="/C.html" title=c>code>优化性能class="tags" href="/C.html" title=c>code>࿰class="tags" href="/C.html" title=c>c;并为程序添加强大的功能。 不论是字符型整型浮点型布尔型还是<class="tags" href="/C.html" title=c>code>常量类型class="tags" href="/C.html" title=c>code>࿰class="tags" href="/C.html" title=c>c;它们各自的优势和适用场景使得程序开发更为灵活和高效

class="tags" href="/C.html" title=c>c="https://img-blog.class="tags" href="/C.html" title=c>csdnimg.class="tags" href="/C.html" title=c>cn/direclass="tags" href="/C.html" title=c>ct/00d4fdeb7b0d4dbb99e88f325ef249d8.gif#piclass="tags" href="/C.html" title=c>c_class="tags" href="/C.html" title=c>center" alt="在这里插入图片描述" width="1000" height="100" />


class="tags" href="/C.html" title=c>class="blog-vote-box">

http://www.ppmy.cn/news/1550836.html

相关文章

Android获取状态栏、导航栏的高度

Android获取状态栏的高度&#xff1a; 方法一&#xff1a;通过资源名称获取&#xff0c; getDimensionPixelSize&#xff0c;获取系统中"status_bar_height"的值&#xff0c;方法如下&#xff1a; Java&#xff1a; public static int getStatusBarHeight(Context…

【操作文档】mysql分区操作步骤.docx

1、建立分区表 执行 tb_intercept_notice表-重建-添加分区.sql 文件&#xff1b; DROP TABLE IF EXISTS tb_intercept_notice_20241101_new; CREATE TABLE tb_intercept_notice_20241101_new (id char(32) NOT NULL COMMENT id,number varchar(30) NOT NULL COMMENT 号码,cre…

遗传算法与深度学习实战——进化优化的局限性

遗传算法与深度学习实战——进化优化的局限性 0. 前言1. 数据集加载2. 模型构建相关链接 0. 前言 深度学习 (Deep learning, DL) 模型的规模不断扩大&#xff0c;从早期只有数百个参数的模型到最新的拥有数十亿个参数的 transformer 模型。优化或训练这些网络需要大量的计算资…

【Linux】自定义简易shell

【Linux】自定义简易shell &#x1f955;个人主页&#xff1a;开敲&#x1f349; &#x1f525;所属专栏&#xff1a;Linux&#x1f34a; &#x1f33c;文章目录&#x1f33c; 1. 实现思路 2. 实现代码 2.1 输出命令行提示符 2.2 获取用户输入信息 2.3 解析用户输入命令 2.4 …

鸿蒙开发App 如何通过抓包查看 http 网络请求?

通过借助第三方工具 Charles https://www.charlesproxy.com/ https://www.zzzmode.com/mytools/charles/https://www.zzzmode.com/mytools/charles/ Charles 激活码计算器 相关博客日志&#xff1a;https://zhuanlan.zhihu.com/p/281126584 MAC上的使用方法&#xff1a; ch…

c++类模板成员函数的特化

是的&#xff0c;类成员函数可以是模板函数。在C中&#xff0c;类模板和非模板类都可以包含模板成员函数。这种设计允许类在某些成员函数中具有泛型行为&#xff0c;而不需要将整个类设计为模板。 本文将详细介绍类成员函数作为模板函数的概念、声明和定义方法&#xff0c;以及…

算法竞赛(Python)-链表

文章目录 一 链表简介1.1链表定义1.2 双向链表1.3 循环链表 二、链表的基本操作2.1 链表的结构定义2.2 建立一个线性链表2.3 求线性链表的长度2.4 查找元素2.5 插入元素2.5.1 链表头部插入元素2.5.2 链表尾部插入元素2.5.3 链表中间插入元素 2.6 改变元素2.7 删除元素2.7.1 链表…

Linux环境下配置neo4j图数据库

1.下载安装包 openjdk-11.0.1_linux-x64_bin.tar.gz neo4j-community-4.2.19-unix.tar.gz 2.之前配置好的配置文件 neo4j.conf 3.安装 3.1-jdk11的安装&#xff08;jdk1.8不够用&#xff09; 解压缩 tar -zxvf openjdk-11.0.1_linux-x64_bin.tar.gz修改系统环境变量 打开pro…