This commit is contained in:
Aurorxa 2024-08-27 03:12:01 +00:00
parent d53a102c28
commit 0d6d498527
31 changed files with 1585 additions and 1478 deletions

View File

@ -8,7 +8,7 @@
<meta name="generator" content="VitePress v1.3.3">
<link rel="preload stylesheet" href="/c/assets/style.zDJ0OJGU.css" as="style">
<script type="module" src="/c/assets/app.Ca2FOFw4.js"></script>
<script type="module" src="/c/assets/app.1a4d5P-6.js"></script>
<link rel="preload" href="/c/assets/inter-roman-latin.Di8DUHzh.woff2" as="font" type="font/woff2" crossorigin="">
<link rel="shortcut icon" href="/c//logo.svg">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="">
@ -20,7 +20,7 @@
</head>
<body>
<div id="app"></div>
<script>window.__VP_HASH_MAP__=JSON.parse("{\"index.md\":\"Dga0tMF5\",\"notes_01_c-basic_00_xdx_index.md\":\"BRC7slaL\",\"notes_01_c-basic_01_xdx_index.md\":\"DvCUr2L0\",\"notes_01_c-basic_02_xdx_index.md\":\"CC2Mg9VD\",\"notes_01_c-basic_03_xdx_index.md\":\"CcATnhKW\",\"notes_01_c-basic_04_xdx_index.md\":\"DABEMZSO\",\"notes_01_c-basic_05_xdx_index.md\":\"CGbN5wss\",\"notes_01_c-basic_06_xdx_index.md\":\"CIGNaKYV\",\"notes_04_linux_01_xdx_index.md\":\"C9IatKsj\",\"notes_about_index.md\":\"DLuQgC_8\",\"notes_index.md\":\"CeV-uJ5V\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"zh-CN\",\"dir\":\"ltr\",\"title\":\"许大仙\",\"titleTemplate\":\"Hi终于等到你\",\"description\":\"许大仙前端、Java、大数据、云原生\",\"base\":\"/c/\",\"head\":[],\"router\":{\"prefetchLinks\":true},\"appearance\":true,\"themeConfig\":{\"lastUpdatedText\":\"上次更新\",\"returnToTopLabel\":\"返回顶部\",\"search\":{\"provider\":\"local\"},\"logo\":\"/logo.svg\",\"nav\":[{\"text\":\"首页\",\"link\":\"https://aexiar.github.io/\"},{\"text\":\"计组6件套\",\"link\":\"https://aexiar.github.io/coa6/notes/\"},{\"text\":\"编程语言\",\"items\":[{\"text\":\"c/c++\",\"link\":\"/notes/\"},{\"text\":\"前端\",\"link\":\"https://aexiar.github.io/web-design/notes/\"},{\"text\":\"Java\",\"link\":\"https://aexiar.github.io/java/notes/\"},{\"text\":\"大数据\",\"link\":\"https://aexiar.github.io/big-data/notes/\"},{\"text\":\"云原生\",\"link\":\"https://aexiar.github.io/linux/notes/\"},{\"text\":\"Go\",\"link\":\"https://aexiar.github.io/go/notes/\"},{\"text\":\"Python\",\"link\":\"https://aexiar.github.io/python/notes/\"}]},{\"text\":\"数据库\",\"link\":\"https://aexiar.github.io/db/notes/\"},{\"text\":\"开源软件\",\"link\":\"https://aexiar.github.io/open-software/notes/\"},{\"text\":\"关于我\",\"link\":\"/notes/about/\"}],\"sidebar\":{\"/notes/\":[{\"text\":\"C 语言基础\",\"collapsed\":true,\"items\":[{\"text\":\"编程基础\",\"link\":\"/notes/01_c-basic/00_xdx/\"},{\"text\":\"C 语言入门\",\"link\":\"/notes/01_c-basic/01_xdx/\"},{\"text\":\"变量和进制\",\"link\":\"/notes/01_c-basic/02_xdx/\"},{\"text\":\"数据类型和运算符\",\"link\":\"/notes/01_c-basic/03_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/01_c-basic/04_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/01_c-basic/05_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/01_c-basic/06_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/01_c-basic/07_xdx/\"},{\"text\":\"预处理器\",\"link\":\"/notes/01_c-basic/08_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/01_c-basic/09_xdx/\"},{\"text\":\"内存管理\",\"link\":\"/notes/01_c-basic/10_xdx/\"},{\"text\":\"文件操作\",\"link\":\"/notes/01_c-basic/11_xdx/\"},{\"text\":\"调试工具和调试技巧gdb和make\",\"link\":\"/notes/02_c-basic/13_xdx/\"},{\"text\":\"常用库函数\",\"link\":\"/notes/01_c-basic/13_xdx/\"}]},{\"text\":\"C 语言高级\",\"collapsed\":true,\"items\":[{\"text\":\"变量和内存分布\",\"link\":\"/notes/02_c-advance/01_xdx/\"},{\"text\":\"指针强化\",\"link\":\"/notes/02_c-advance/02_xdx/\"},{\"text\":\"结构体和文件的高级用法\",\"link\":\"/notes/02_c-advance/03_xdx/\"},{\"text\":\"链表和回调函数\",\"link\":\"/notes/02_c-advance/04_xdx/\"},{\"text\":\"编译过程和面向接口\",\"link\":\"/notes/02_c-advance/05_xdx/\"}]},{\"text\":\"项目构建工具\",\"collapsed\":true,\"items\":[{\"text\":\"meson\",\"collapsed\":true,\"items\":[{\"text\":\"meson 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Cmake\",\"collapsed\":true,\"items\":[{\"text\":\"Cmake 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Conan \",\"link\":\"/notes/03_build/01_${commonDirectoryName}/\"},{\"text\":\"Gradle\",\"collapsed\":true,\"items\":[{\"text\":\"Gradle 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]}]},{\"text\":\"Linux\",\"collapsed\":true,\"items\":[{\"text\":\"Linux 初识和安装\",\"link\":\"/notes/04_linux/01_xdx/\"}]},{\"text\":\"C++ 基础\",\"collapsed\":true,\"items\":[{\"text\":\"C++ 入门\",\"link\":\"/notes/05_cpp/01_xdx/\"},{\"text\":\"变量、数据类型、运算符\",\"link\":\"/notes/05_cpp/02_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/05_cpp/03_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/05_cpp/04_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/05_cpp/05_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/05_cpp/06_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/05_cpp/07_xdx/\"},{\"text\":\"类和对象\",\"link\":\"/notes/05_cpp/08_xdx/\"},{\"text\":\"C++ 引用\",\"link\":\"/notes/05_cpp/09_xdx/\"},{\"text\":\"继承和派生\",\"link\":\"/notes/05_cpp/10_xdx/\"},{\"text\":\"C++ 多态和虚函数\",\"link\":\"/notes/05_cpp/11_xdx/\"},{\"text\":\"运算符重载\",\"link\":\"/notes/05_cpp/12_xdx/\"},{\"text\":\"模板\",\"link\":\"/notes/05_cpp/13_xdx/\"},{\"text\":\"C++ 异常\",\"link\":\"/notes/05_cpp/14_xdx/\"},{\"text\":\"面向对象进阶\",\"link\":\"/notes/05_cpp/15_xdx/\"},{\"text\":\"文件操作和 IO 流\",\"link\":\"/notes/05_cpp/16_xdx/\"},{\"text\":\"STL标准模板库\",\"link\":\"/notes/05_cpp/17_xdx/\"}]},{\"text\":\"C++ 高级\",\"collapsed\":true,\"items\":[]},{\"text\":\"QT 桌面开发\",\"collapsed\":true,\"items\":[]},{\"text\":\"Linux 高并发服务器开发\",\"collapsed\":true,\"items\":[]}]},\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/Aurorxa\"}],\"docFooter\":{\"prev\":\"上一篇\",\"next\":\"下一篇\"},\"darkModeSwitchLabel\":\"深浅模式\",\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2024 许大仙\"},\"outline\":{\"level\":[1,6],\"label\":\"目录\"},\"outlineTitle\":\"当前页大纲\"},\"locales\":{},\"scrollOffset\":134,\"cleanUrls\":false}");</script>
<script>window.__VP_HASH_MAP__=JSON.parse("{\"index.md\":\"Dga0tMF5\",\"notes_01_c-basic_00_xdx_index.md\":\"BRC7slaL\",\"notes_01_c-basic_01_xdx_index.md\":\"Fg4OXydV\",\"notes_01_c-basic_02_xdx_index.md\":\"CC2Mg9VD\",\"notes_01_c-basic_03_xdx_index.md\":\"Cw3Z19MO\",\"notes_01_c-basic_04_xdx_index.md\":\"ySxH8sG-\",\"notes_01_c-basic_05_xdx_index.md\":\"DUbOwEts\",\"notes_01_c-basic_06_xdx_index.md\":\"CV_r2WNu\",\"notes_01_c-basic_07_xdx_index.md\":\"CE9q5cmu\",\"notes_04_linux_01_xdx_index.md\":\"C9IatKsj\",\"notes_about_index.md\":\"DLuQgC_8\",\"notes_index.md\":\"CeV-uJ5V\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"zh-CN\",\"dir\":\"ltr\",\"title\":\"许大仙\",\"titleTemplate\":\"Hi终于等到你\",\"description\":\"许大仙前端、Java、大数据、云原生\",\"base\":\"/c/\",\"head\":[],\"router\":{\"prefetchLinks\":true},\"appearance\":true,\"themeConfig\":{\"lastUpdatedText\":\"上次更新\",\"returnToTopLabel\":\"返回顶部\",\"search\":{\"provider\":\"local\"},\"logo\":\"/logo.svg\",\"nav\":[{\"text\":\"首页\",\"link\":\"https://aexiar.github.io/\"},{\"text\":\"计组6件套\",\"link\":\"https://aexiar.github.io/coa6/notes/\"},{\"text\":\"编程语言\",\"items\":[{\"text\":\"c/c++\",\"link\":\"/notes/\"},{\"text\":\"前端\",\"link\":\"https://aexiar.github.io/web-design/notes/\"},{\"text\":\"Java\",\"link\":\"https://aexiar.github.io/java/notes/\"},{\"text\":\"大数据\",\"link\":\"https://aexiar.github.io/big-data/notes/\"},{\"text\":\"云原生\",\"link\":\"https://aexiar.github.io/linux/notes/\"},{\"text\":\"Go\",\"link\":\"https://aexiar.github.io/go/notes/\"},{\"text\":\"Python\",\"link\":\"https://aexiar.github.io/python/notes/\"}]},{\"text\":\"数据库\",\"link\":\"https://aexiar.github.io/db/notes/\"},{\"text\":\"开源软件\",\"link\":\"https://aexiar.github.io/open-software/notes/\"},{\"text\":\"关于我\",\"link\":\"/notes/about/\"}],\"sidebar\":{\"/notes/\":[{\"text\":\"C 语言基础\",\"collapsed\":true,\"items\":[{\"text\":\"编程基础\",\"link\":\"/notes/01_c-basic/00_xdx/\"},{\"text\":\"C 语言入门\",\"link\":\"/notes/01_c-basic/01_xdx/\"},{\"text\":\"变量和进制\",\"link\":\"/notes/01_c-basic/02_xdx/\"},{\"text\":\"数据类型和运算符\",\"link\":\"/notes/01_c-basic/03_xdx/\"},{\"text\":\"大话小数\",\"link\":\"/notes/01_c-basic/04_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/01_c-basic/05_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/01_c-basic/06_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/01_c-basic/07_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/01_c-basic/08_xdx/\"},{\"text\":\"预处理器\",\"link\":\"/notes/01_c-basic/09_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/01_c-basic/10_xdx/\"},{\"text\":\"内存管理\",\"link\":\"/notes/01_c-basic/11_xdx/\"},{\"text\":\"文件操作\",\"link\":\"/notes/01_c-basic/12_xdx/\"},{\"text\":\"调试工具和调试技巧gdb和make\",\"link\":\"/notes/02_c-basic/13_xdx/\"},{\"text\":\"常用库函数\",\"link\":\"/notes/01_c-basic/14_xdx/\"}]},{\"text\":\"C 语言高级\",\"collapsed\":true,\"items\":[{\"text\":\"变量和内存分布\",\"link\":\"/notes/02_c-advance/01_xdx/\"},{\"text\":\"指针强化\",\"link\":\"/notes/02_c-advance/02_xdx/\"},{\"text\":\"结构体和文件的高级用法\",\"link\":\"/notes/02_c-advance/03_xdx/\"},{\"text\":\"链表和回调函数\",\"link\":\"/notes/02_c-advance/04_xdx/\"},{\"text\":\"编译过程和面向接口\",\"link\":\"/notes/02_c-advance/05_xdx/\"}]},{\"text\":\"项目构建工具\",\"collapsed\":true,\"items\":[{\"text\":\"meson\",\"collapsed\":true,\"items\":[{\"text\":\"meson 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Cmake\",\"collapsed\":true,\"items\":[{\"text\":\"Cmake 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Conan \",\"link\":\"/notes/03_build/01_${commonDirectoryName}/\"},{\"text\":\"Gradle\",\"collapsed\":true,\"items\":[{\"text\":\"Gradle 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]}]},{\"text\":\"Linux\",\"collapsed\":true,\"items\":[{\"text\":\"Linux 初识和安装\",\"link\":\"/notes/04_linux/01_xdx/\"}]},{\"text\":\"C++ 基础\",\"collapsed\":true,\"items\":[{\"text\":\"C++ 入门\",\"link\":\"/notes/05_cpp/01_xdx/\"},{\"text\":\"变量、数据类型、运算符\",\"link\":\"/notes/05_cpp/02_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/05_cpp/03_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/05_cpp/04_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/05_cpp/05_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/05_cpp/06_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/05_cpp/07_xdx/\"},{\"text\":\"类和对象\",\"link\":\"/notes/05_cpp/08_xdx/\"},{\"text\":\"C++ 引用\",\"link\":\"/notes/05_cpp/09_xdx/\"},{\"text\":\"继承和派生\",\"link\":\"/notes/05_cpp/10_xdx/\"},{\"text\":\"C++ 多态和虚函数\",\"link\":\"/notes/05_cpp/11_xdx/\"},{\"text\":\"运算符重载\",\"link\":\"/notes/05_cpp/12_xdx/\"},{\"text\":\"模板\",\"link\":\"/notes/05_cpp/13_xdx/\"},{\"text\":\"C++ 异常\",\"link\":\"/notes/05_cpp/14_xdx/\"},{\"text\":\"面向对象进阶\",\"link\":\"/notes/05_cpp/15_xdx/\"},{\"text\":\"文件操作和 IO 流\",\"link\":\"/notes/05_cpp/16_xdx/\"},{\"text\":\"STL标准模板库\",\"link\":\"/notes/05_cpp/17_xdx/\"}]},{\"text\":\"C++ 高级\",\"collapsed\":true,\"items\":[]},{\"text\":\"QT 桌面开发\",\"collapsed\":true,\"items\":[]},{\"text\":\"Linux 高并发服务器开发\",\"collapsed\":true,\"items\":[]}]},\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/Aurorxa\"}],\"docFooter\":{\"prev\":\"上一篇\",\"next\":\"下一篇\"},\"darkModeSwitchLabel\":\"深浅模式\",\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2024 许大仙\"},\"outline\":{\"level\":[1,6],\"label\":\"目录\"},\"outlineTitle\":\"当前页大纲\"},\"locales\":{},\"scrollOffset\":134,\"cleanUrls\":false}");</script>
</body>
</html>

View File

@ -1 +1 @@
import{R as p}from"./chunks/theme.C6fZfLtk.js";import{U as o,a7 as u,a8 as c,a9 as l,aa as f,ab as d,ac as m,ad as h,ae as g,af as A,ag as y,d as P,u as v,y as w,x as C,ah as R,ai as b,aj as E,a5 as S}from"./chunks/framework.hMCIpNYY.js";function i(e){if(e.extends){const a=i(e.extends);return{...a,...e,async enhanceApp(t){a.enhanceApp&&await a.enhanceApp(t),e.enhanceApp&&await e.enhanceApp(t)}}}return e}const s=i(p),T=P({name:"VitePressApp",setup(){const{site:e,lang:a,dir:t}=v();return w(()=>{C(()=>{document.documentElement.lang=a.value,document.documentElement.dir=t.value})}),e.value.router.prefetchLinks&&R(),b(),E(),s.setup&&s.setup(),()=>S(s.Layout)}});async function j(){globalThis.__VITEPRESS__=!0;const e=D(),a=x();a.provide(c,e);const t=l(e.route);return a.provide(f,t),a.component("Content",d),a.component("ClientOnly",m),Object.defineProperties(a.config.globalProperties,{$frontmatter:{get(){return t.frontmatter.value}},$params:{get(){return t.page.value.params}}}),s.enhanceApp&&await s.enhanceApp({app:a,router:e,siteData:h}),{app:a,router:e,data:t}}function x(){return g(T)}function D(){let e=o,a;return A(t=>{let n=y(t),r=null;return n&&(e&&(a=n),(e||a===n)&&(n=n.replace(/\.js$/,".lean.js")),r=import(n)),o&&(e=!1),r},s.NotFound)}o&&j().then(({app:e,router:a,data:t})=>{a.go().then(()=>{u(a.route,t.site),e.mount("#app")})});export{j as createApp};
import{R as p}from"./chunks/theme.Ddh-lpYV.js";import{U as o,a7 as u,a8 as c,a9 as l,aa as f,ab as d,ac as m,ad as h,ae as g,af as A,ag as y,d as P,u as v,y as w,x as C,ah as R,ai as b,aj as E,a5 as S}from"./chunks/framework.hMCIpNYY.js";function i(e){if(e.extends){const a=i(e.extends);return{...a,...e,async enhanceApp(t){a.enhanceApp&&await a.enhanceApp(t),e.enhanceApp&&await e.enhanceApp(t)}}}return e}const s=i(p),T=P({name:"VitePressApp",setup(){const{site:e,lang:a,dir:t}=v();return w(()=>{C(()=>{document.documentElement.lang=a.value,document.documentElement.dir=t.value})}),e.value.router.prefetchLinks&&R(),b(),E(),s.setup&&s.setup(),()=>S(s.Layout)}});async function j(){globalThis.__VITEPRESS__=!0;const e=D(),a=x();a.provide(c,e);const t=l(e.route);return a.provide(f,t),a.component("Content",d),a.component("ClientOnly",m),Object.defineProperties(a.config.globalProperties,{$frontmatter:{get(){return t.frontmatter.value}},$params:{get(){return t.page.value.params}}}),s.enhanceApp&&await s.enhanceApp({app:a,router:e,siteData:h}),{app:a,router:e,data:t}}function x(){return g(T)}function D(){let e=o,a;return A(t=>{let n=y(t),r=null;return n&&(e&&(a=n),(e||a===n)&&(n=n.replace(/\.js$/,".lean.js")),r=import(n)),o&&(e=!1),r},s.NotFound)}o&&j().then(({app:e,router:a,data:t})=>{a.go().then(()=>{u(a.route,t.site),e.mount("#app")})});export{j as createApp};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
var Ft=Object.defineProperty;var Ot=(a,e,t)=>e in a?Ft(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t;var Ce=(a,e,t)=>Ot(a,typeof e!="symbol"?e+"":e,t);import{X as Rt,s as ne,h as ve,ak as et,al as Ct,am as Mt,v as je,an as At,d as Lt,G as ye,ao as tt,ap as Dt,aq as zt,x as Pt,ar as Vt,y as Me,R as de,Q as we,as as jt,at as $t,Y as Bt,U as Wt,a1 as Kt,o as Q,b as Jt,j as x,a2 as Ut,k as D,au as qt,av as Gt,aw as Qt,c as Z,n as st,e as _e,E as nt,F as it,a as he,t as fe,ax as Ht,p as Yt,l as Zt,ay as rt,a4 as Xt,aa as es,ag as ts,az as ss,_ as ns}from"./framework.hMCIpNYY.js";import{u as is,c as rs}from"./theme.C6fZfLtk.js";const as={root:()=>Rt(()=>import("./@localSearchIndexroot.MLJrk4XT.js"),[])};/*!
var Ft=Object.defineProperty;var Ot=(a,e,t)=>e in a?Ft(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t;var Ce=(a,e,t)=>Ot(a,typeof e!="symbol"?e+"":e,t);import{X as Rt,s as ne,h as ve,ak as et,al as Ct,am as Mt,v as je,an as At,d as Lt,G as ye,ao as tt,ap as Dt,aq as zt,x as Pt,ar as Vt,y as Me,R as de,Q as we,as as jt,at as $t,Y as Bt,U as Wt,a1 as Kt,o as Q,b as Jt,j as x,a2 as Ut,k as D,au as qt,av as Gt,aw as Qt,c as Z,n as st,e as _e,E as nt,F as it,a as he,t as fe,ax as Ht,p as Yt,l as Zt,ay as rt,a4 as Xt,aa as es,ag as ts,az as ss,_ as ns}from"./framework.hMCIpNYY.js";import{u as is,c as rs}from"./theme.Ddh-lpYV.js";const as={root:()=>Rt(()=>import("./@localSearchIndexroot.Drucd3OI.js"),[])};/*!
* tabbable 6.2.0
* @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
*/var mt=["input:not([inert])","select:not([inert])","textarea:not([inert])","a[href]:not([inert])","button:not([inert])","[tabindex]:not(slot):not([inert])","audio[controls]:not([inert])","video[controls]:not([inert])",'[contenteditable]:not([contenteditable="false"]):not([inert])',"details>summary:first-of-type:not([inert])","details:not([inert])"],Ie=mt.join(","),gt=typeof Element>"u",re=gt?function(){}:Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector,Ne=!gt&&Element.prototype.getRootNode?function(a){var e;return a==null||(e=a.getRootNode)===null||e===void 0?void 0:e.call(a)}:function(a){return a==null?void 0:a.ownerDocument},ke=function a(e,t){var s;t===void 0&&(t=!0);var n=e==null||(s=e.getAttribute)===null||s===void 0?void 0:s.call(e,"inert"),r=n===""||n==="true",i=r||t&&e&&a(e.parentNode);return i},os=function(e){var t,s=e==null||(t=e.getAttribute)===null||t===void 0?void 0:t.call(e,"contenteditable");return s===""||s==="true"},bt=function(e,t,s){if(ke(e))return[];var n=Array.prototype.slice.apply(e.querySelectorAll(Ie));return t&&re.call(e,Ie)&&n.unshift(e),n=n.filter(s),n},yt=function a(e,t,s){for(var n=[],r=Array.from(e);r.length;){var i=r.shift();if(!ke(i,!1))if(i.tagName==="SLOT"){var o=i.assignedElements(),c=o.length?o:i.children,l=a(c,!0,s);s.flatten?n.push.apply(n,l):n.push({scopeParent:i,candidates:l})}else{var h=re.call(i,Ie);h&&s.filter(i)&&(t||!e.includes(i))&&n.push(i);var v=i.shadowRoot||typeof s.getShadowRoot=="function"&&s.getShadowRoot(i),f=!ke(v,!1)&&(!s.shadowRootFilter||s.shadowRootFilter(i));if(v&&f){var b=a(v===!0?i.children:v.children,!0,s);s.flatten?n.push.apply(n,b):n.push({scopeParent:i,candidates:b})}else r.unshift.apply(r,i.children)}}return n},wt=function(e){return!isNaN(parseInt(e.getAttribute("tabindex"),10))},ie=function(e){if(!e)throw new Error("No node provided");return e.tabIndex<0&&(/^(AUDIO|VIDEO|DETAILS)$/.test(e.tagName)||os(e))&&!wt(e)?0:e.tabIndex},cs=function(e,t){var s=ie(e);return s<0&&t&&!wt(e)?0:s},ls=function(e,t){return e.tabIndex===t.tabIndex?e.documentOrder-t.documentOrder:e.tabIndex-t.tabIndex},_t=function(e){return e.tagName==="INPUT"},us=function(e){return _t(e)&&e.type==="hidden"},ds=function(e){var t=e.tagName==="DETAILS"&&Array.prototype.slice.apply(e.children).some(function(s){return s.tagName==="SUMMARY"});return t},hs=function(e,t){for(var s=0;s<e.length;s++)if(e[s].checked&&e[s].form===t)return e[s]},fs=function(e){if(!e.name)return!0;var t=e.form||Ne(e),s=function(o){return t.querySelectorAll('input[type="radio"][name="'+o+'"]')},n;if(typeof window<"u"&&typeof window.CSS<"u"&&typeof window.CSS.escape=="function")n=s(window.CSS.escape(e.name));else try{n=s(e.name)}catch(i){return console.error("Looks like you have a radio button with a name attribute containing invalid CSS selector characters and need the CSS.escape polyfill: %s",i.message),!1}var r=hs(n,e.form);return!r||r===e},ps=function(e){return _t(e)&&e.type==="radio"},vs=function(e){return ps(e)&&!fs(e)},ms=function(e){var t,s=e&&Ne(e),n=(t=s)===null||t===void 0?void 0:t.host,r=!1;if(s&&s!==e){var i,o,c;for(r=!!((i=n)!==null&&i!==void 0&&(o=i.ownerDocument)!==null&&o!==void 0&&o.contains(n)||e!=null&&(c=e.ownerDocument)!==null&&c!==void 0&&c.contains(e));!r&&n;){var l,h,v;s=Ne(n),n=(l=s)===null||l===void 0?void 0:l.host,r=!!((h=n)!==null&&h!==void 0&&(v=h.ownerDocument)!==null&&v!==void 0&&v.contains(n))}}return r},at=function(e){var t=e.getBoundingClientRect(),s=t.width,n=t.height;return s===0&&n===0},gs=function(e,t){var s=t.displayCheck,n=t.getShadowRoot;if(getComputedStyle(e).visibility==="hidden")return!0;var r=re.call(e,"details>summary:first-of-type"),i=r?e.parentElement:e;if(re.call(i,"details:not([open]) *"))return!0;if(!s||s==="full"||s==="legacy-full"){if(typeof n=="function"){for(var o=e;e;){var c=e.parentElement,l=Ne(e);if(c&&!c.shadowRoot&&n(c)===!0)return at(e);e.assignedSlot?e=e.assignedSlot:!c&&l!==e.ownerDocument?e=l.host:e=c}e=o}if(ms(e))return!e.getClientRects().length;if(s!=="legacy-full")return!0}else if(s==="non-zero-area")return at(e);return!1},bs=function(e){if(/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(e.tagName))for(var t=e.parentElement;t;){if(t.tagName==="FIELDSET"&&t.disabled){for(var s=0;s<t.children.length;s++){var n=t.children.item(s);if(n.tagName==="LEGEND")return re.call(t,"fieldset[disabled] *")?!0:!n.contains(e)}return!0}t=t.parentElement}return!1},Fe=function(e,t){return!(t.disabled||ke(t)||us(t)||gs(t,e)||ds(t)||bs(t))},$e=function(e,t){return!(vs(t)||ie(t)<0||!Fe(e,t))},ys=function(e){var t=parseInt(e.getAttribute("tabindex"),10);return!!(isNaN(t)||t>=0)},ws=function a(e){var t=[],s=[];return e.forEach(function(n,r){var i=!!n.scopeParent,o=i?n.scopeParent:n,c=cs(o,i),l=i?a(n.candidates):o;c===0?i?t.push.apply(t,l):t.push(o):s.push({documentOrder:r,tabIndex:c,item:n,isScope:i,content:l})}),s.sort(ls).reduce(function(n,r){return r.isScope?n.push.apply(n,r.content):n.push(r.content),n},[]).concat(t)},_s=function(e,t){t=t||{};var s;return t.getShadowRoot?s=yt([e],t.includeContainer,{filter:$e.bind(null,t),flatten:!1,getShadowRoot:t.getShadowRoot,shadowRootFilter:ys}):s=bt(e,t.includeContainer,$e.bind(null,t)),ws(s)},xs=function(e,t){t=t||{};var s;return t.getShadowRoot?s=yt([e],t.includeContainer,{filter:Fe.bind(null,t),flatten:!0,getShadowRoot:t.getShadowRoot}):s=bt(e,t.includeContainer,Fe.bind(null,t)),s},ae=function(e,t){if(t=t||{},!e)throw new Error("No node provided");return re.call(e,Ie)===!1?!1:$e(t,e)},Ss=mt.concat("iframe").join(","),Ae=function(e,t){if(t=t||{},!e)throw new Error("No node provided");return re.call(e,Ss)===!1?!1:Fe(t,e)};/*!

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
import{_ as s,c as a,o as i,a6 as n}from"./chunks/framework.hMCIpNYY.js";const l="/c/assets/1.D60Zf6_d.png",e="/c/assets/2.D2-G6nV2.png",p="/c/assets/3.DpzkVk5V.png",t="/c/assets/4.BXk95GIP.png",r="/c/assets/5.CbWTB08W.png",c="/c/assets/6.twO9TCIg.png",h="/c/assets/7.CKOjeIvS.png",d="/c/assets/8.DKmR0CxE.png",o="/c/assets/9.Cudf77_s.gif",k="/c/assets/10.BBUUlhRC.png",u="/c/assets/11.iLABkB7O.png",g="/c/assets/12.BQuYWOU9.png",b="/c/assets/13.CslpH6j0.png",m="/c/assets/14.BAyvZdKq.png",C="/c/assets/15.C3oC1iUd.png",y="/c/assets/16.Ds-jsEZn.png",E="/c/assets/17.Cd37gMYs.png",F="/c/assets/18.CAw2z3gc.png",_="/c/assets/19.DdPThnr-.png",v="/c/assets/20.q_rvlDnY.png",B="/c/assets/21.JRHg9RZA.png",f="/c/assets/22.Baq-Hb06.png",A="/c/assets/23.c1ht53mu.png",D="/c/assets/24.CAZmH5Py.png",x="/c/assets/25.DWeCYBe9.png",q="/c/assets/26.2XM8pYni.png",w="/c/assets/27.CN0t-fuo.png",S="/c/assets/28.AcDh3LXQ.png",L="/c/assets/29.CUkDFAc6.png",z="/c/assets/30.picNTNaJ.png",P="/c/assets/31.DKX92RgJ.png",W="/c/assets/32.Bxr7QKI3.png",T="/c/assets/33.DuFWsOgW.png",M="/c/assets/34.Da9qUcfr.png",U="/c/assets/35.7_gEABSX.gif",O="/c/assets/36.C2KQYoVC.gif",I="/c/assets/37.RTUP8Vtx.png",N="/c/assets/38.Dq21DxwL.png",R="/c/assets/39.QmpUaNxU.png",V="/c/assets/40.DP0C29gZ.png",G="/c/assets/41.DwzHokd4.png",X="/c/assets/42.Bi6K26yA.png",$="/c/assets/43.Bw8DcEQ_.png",H="/c/assets/44.DPc8Z9rS.png",K="/c/assets/45.S84xHMTl.png",Q="/c/assets/46.iw3JQUkn.png",J="/c/assets/47.ILeJt-HK.png",Y="/c/assets/48.CHgm7khh.png",j="/c/assets/49.N1nqJaEg.png",Z="/c/assets/50.DHsnibMi.png",ss="/c/assets/51.BQr6Q0uV.png",as="/c/assets/52.BVemi2Lh.png",is="/c/assets/53.BHR69UXx.png",ns="/c/assets/54.CPSU5SJI.png",ls="/c/assets/55.CaQLoDlw.png",es="/c/assets/56.aRGy4XbL.png",ps="/c/assets/57.kNO9fmPR.png",ts="/c/assets/58.D4EkoC4o.png",rs="/c/assets/59.V23Lo9e_.png",cs="/c/assets/60.Du9LVeMB.png",hs="/c/assets/61.DdFg75U9.png",ds="/c/assets/62.C6bz6KtT.png",os="/c/assets/63.CB6LAhB5.png",ks="/c/assets/64.Bip8bkua.png",us="/c/assets/65.DRNHRduW.png",gs="/c/assets/66.Cth4qqEn.png",bs="/c/assets/67.DWGWZ64P.png",ms="/c/assets/68.3hDIDdvx.png",Cs="/c/assets/69.Bw_dQ4ap.png",ys="/c/assets/70.Cn_ubTyA.png",Es="/c/assets/71.C84EBqwB.png",Fs="/c/assets/72.dZfJY4eR.png",_s="/c/assets/73.B0zm0Z79.png",vs="/c/assets/74.CaTcEy1Q.png",Bs="/c/assets/75.iEc8mo9g.png",fs="/c/assets/76.Co2KxM6t.png",As="/c/assets/77.CaUm8Qhc.png",Ds="/c/assets/78.kOkqIKG6.png",xs="/c/assets/79.CyeASH-c.png",qs="/c/assets/80.CFdk60La.png",ws="/c/assets/81.Bhl-0uK_.png",Ss="/c/assets/82.Dni9KbXV.png",Ls="/c/assets/83.BXx10MCV.png",zs="/c/assets/84.CXcIKX1T.png",Ps="/c/assets/85.DptbJqQo.png",Ws="/c/assets/86.CQ3_QCQT.png",Ts="/c/assets/87.CQoDRJM5.gif",Ms="/c/assets/88.CPfwZvD9.gif",Us="/c/assets/89.bxEomEjU.gif",Os="/c/assets/90.C_onhf2k.png",Is="/c/assets/91.Budj3s38.gif",Ns="/c/assets/92.CH8koQdu.gif",Rs="/c/assets/93.kUJhxMtg.png",Vs="/c/assets/94.BJeJJW4_.png",Gs="/c/assets/95.BCuK6eJL.gif",Xs="/c/assets/96.rKC-z4z-.gif",$s="/c/assets/97.BJE3xxuT.gif",Hs="/c/assets/98.DJOq__O0.gif",Ks="/c/assets/99.BDt_0fRR.png",Qs="/c/assets/100.Bo5OawW8.png",Js="/c/assets/101.sUWUfl5e.png",Ys="/c/assets/102.BK4jpnB8.png",js="/c/assets/103.EF8vdbSq.png",Zs="/c/assets/104.DjxdA_Co.png",sa="/c/assets/105.sp68q1hh.gif",aa="/c/assets/106.DhMRyxNN.gif",ia="/c/assets/107.CdcLZM0R.gif",na="/c/assets/108.D-5AsTTr.png",la="/c/assets/109.2RQKmAUa.png",ea="/c/assets/110.CI4xX8SM.png",pa="/c/assets/111.C8QUZ9v3.gif",ta="/c/assets/112.g5tQfhWz.gif",ra="/c/assets/113.CX0_1NsE.gif",ca="/c/assets/114.BrFJeoK6.png",ha="/c/assets/115.58TjSSjH.gif",da="/c/assets/116.DmiFIqcy.svg",oa="/c/assets/117.BasYWvkM.png",ka="/c/assets/118.CjFxJpBr.png",ua="/c/assets/119.Dm5Jspvp.gif",ga="/c/assets/120.1krCh8cy.gif",ba="/c/assets/121.DOSyahv7.gif",ma="/c/assets/122.BHEvX_FI.gif",Ca="/c/assets/123.DFA0g1_d.gif",ya="/c/assets/124.D50nO5eA.gif",Ea="/c/assets/125.cAvG1Qfq.png",Fa="/c/assets/126.DpakQFWz.gif",_a="/c/assets/127.Bg61j9QI.gif",va="/c/assets/128.DPvD9UCw.gif",Ba="/c/assets/129.Ceu65U_n.gif",fa="/c/assets/130.BWPFRK_8.gif",Aa="/c/assets/131.Ct4TfxPf.gif",Da="/c/assets/132.zsKtx_jV.png",xa="/c/assets/133.3oqDAW0w.png",qa="/c/assets/134.D9TSeAa9.gif",wa="/c/assets/135.CCRgYIVq.png",Sa="/c/assets/136.C1t2T6FV.gif",La="/c/assets/137.Rqa4uHq6.png",za="/c/assets/138.6yQYnjOa.gif",Pa="/c/assets/139.hYR9GiiD.gif",Wa="/c/assets/140.D3b-QIrA.gif",Ta="/c/assets/141.DGbA6qsW.gif",Ma="/c/assets/142.BToOkxf2.gif",Ua="/c/assets/143.C3wekjfY.png",Oa="/c/assets/144.CKuuzuQ_.png",Ia="/c/assets/145.B4r6Nv14.gif",Na="/c/assets/146.CvbhuZNK.png",Ra="/c/assets/147.BPgYm4ZX.gif",Va="/c/assets/148.DH2fri13.gif",Ga="/c/assets/149.CDDIqy03.gif",Xa="/c/assets/150.DCQsqYYC.gif",$a="/c/assets/151.CUjMoXNF.gif",Ha="/c/assets/152.BWbajkuB.gif",Ka="/c/assets/153.C1JnBDr7.png",Qa="/c/assets/154.DwN2p3bo.png",Ja="/c/assets/155.DdSfz-Pf.gif",Ya="/c/assets/156.BMocjVt7.gif",ja="/c/assets/157.BUU-wlaw.gif",Za="/c/assets/158.ssadIF0D.gif",si="/c/assets/159.Dq5lLq9v.gif",ai="/c/assets/160.CJ0_loZ8.gif",ii="/c/assets/161.BPOK9irZ.gif",ni="/c/assets/162.B1eB55rC.gif",li="/c/assets/163.VIcU-hkN.gif",ei="/c/assets/164.BM9viRZJ.gif",pi="/c/assets/165.DpMBA1SK.gif",ti="/c/assets/166.DgXuU6LF.png",ri="/c/assets/167.Dnw73s2h.gif",ci="/c/assets/168.SnFXRSaL.png",hi="/c/assets/169.DnoEqOjV.png",di="/c/assets/170.BJBdn7pw.png",oi="/c/assets/171.DXtQWYsM.gif",ki="/c/assets/172.hcERTQkN.gif",ui="/c/assets/173.CioraEUv.png",gi="/c/assets/174.kWHWwnc_.png",bi="/c/assets/175.DhVZ6aP-.gif",mi="/c/assets/176.CUl5g8VJ.png",Ci="/c/assets/177.FJeffiE3.gif",yi="/c/assets/178.Bee0LcNX.gif",Ei="/c/assets/179.BDqd1eDo.png",Li=JSON.parse('{"title":"第一章:开发环境的安装和配置(⭐)","description":"","frontmatter":{},"headers":[],"relativePath":"notes/01_c-basic/01_xdx/index.md","filePath":"notes/01_c-basic/01_xdx/index.md","lastUpdated":1724660795000}'),Fi={name:"notes/01_c-basic/01_xdx/index.md"},_i=n('<h1 id="第一章-开发环境的安装和配置-⭐" tabindex="-1">第一章:开发环境的安装和配置(⭐) <a class="header-anchor" href="#第一章-开发环境的安装和配置-⭐" aria-label="Permalink to &quot;第一章:开发环境的安装和配置(⭐)&quot;"></a></h1><h2 id="_1-1-什么是编译器" tabindex="-1">1.1 什么是编译器? <a class="header-anchor" href="#_1-1-什么是编译器" aria-label="Permalink to &quot;1.1 什么是编译器?&quot;"></a></h2><ul><li>要开发 C/C++ 程序,需要安装 C/C++ 编译器,目前有两种主流实现,即: <ul><li>GCCGNU Compiler Collection全平台实现即支持 Windows、MacOS、Linux 等。</li><li>MSVCMicrosoft Visual C++):只支持 Windows 系统。</li></ul></li><li>GCC 在 Windows 上的版本有很多,如:<a href="https://www.mingw-w64.org/" target="_blank" rel="noreferrer">MinGW-w64</a>、<a href="https://cygwin.com/" target="_blank" rel="noreferrer">Gygwin</a>、<a href="https://www.msys2.org/" target="_blank" rel="noreferrer">MSYS2</a>。它们之间的区别,如下所示:</li></ul><table tabindex="0"><thead><tr><th>特性</th><th>MinGW-w64</th><th>Cygwin</th><th>MSYS2</th></tr></thead><tbody><tr><td><strong>简介</strong></td><td>Minimalist GNU for Windows</td><td>POSIX 兼容环境和工具集</td><td>结合了 MinGW 和 Cygwin 的工具集</td></tr><tr><td><strong>编译器</strong></td><td>提供 GCC 编译器</td><td>提供 POSIX 兼容环境,包含大量工具</td><td>提供 MinGW-w64 工具链和 Cygwin 环境</td></tr><tr><td><strong>生成文件</strong></td><td>Windows 原生可执行文件</td><td>POSIX 兼容的可执行文件</td><td>可以生成 Windows 原生可执行文件或 POSIX 文件</td></tr><tr><td><strong>依赖</strong></td><td>无需额外依赖</td><td>依赖 Cygwin DLL</td><td>根据使用工具链决定MinGW-w64 无依赖Cygwin 有依赖)</td></tr><tr><td><strong>工具和库</strong></td><td>基本的编译工具</td><td>丰富的 Unix 工具和库</td><td>丰富的工具和库,强大的包管理系统</td></tr><tr><td><strong>性能</strong></td><td>性能较好</td><td>可能较低,因为通过兼容层调用系统</td><td>取决于使用的工具链MinGW-w64 性能较好)</td></tr><tr><td><strong>复杂度</strong></td><td>简单易用</td><td>设置和使用相对复杂</td><td>较为灵活,复杂度介于 MinGW-w64 和 Cygwin 之间</td></tr><tr><td><strong>适用场景</strong></td><td>开发 Windows 原生应用</td><td>运行和开发 Unix 程序</td><td>混合使用 Unix 工具和开发 Windows 原生应用</td></tr><tr><td><strong>优点</strong></td><td>轻量级,直接生成 Windows 应用</td><td>完整的 POSIX 兼容环境,丰富的工具</td><td>灵活的环境,强大的包管理系统</td></tr><tr><td><strong>缺点</strong></td><td>工具和库较少</td><td>生成文件依赖 Cygwin DLL性能可能较低</td><td>环境较大,占用更多空间,复杂性比 MinGW-w64 高</td></tr></tbody></table><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① MinGW-w64 、Cygwin 以及 MSYS2 任选其一安装即可。</li><li>② 目前的 Win10 和 Win11 版本支持 WSL2 Windows Sub Linux 2 ,即 Windows 的子系统 Linux可以实现在 Windows 系统上安装一个 Linux ,然后再运行 Linux 中的 GCC 工具链。</li><li>③ 本人的操作系统是 Win11 ,安装和配置都将以该系统为基础作为演示,后续不再赘述!!!</li></ul></div><h2 id="_1-2-编译器的安装和配置" tabindex="-1">1.2 编译器的安装和配置 <a class="header-anchor" href="#_1-2-编译器的安装和配置" aria-label="Permalink to &quot;1.2 编译器的安装和配置&quot;"></a></h2><h3 id="_1-2-2-mingw-w64-的安装和配置" tabindex="-1">1.2.2 MinGW-w64 的安装和配置 <a class="header-anchor" href="#_1-2-2-mingw-w64-的安装和配置" aria-label="Permalink to &quot;1.2.2 MinGW-w64 的安装和配置&quot;"></a></h3><h4 id="_1-2-2-1-安装" tabindex="-1">1.2.2.1 安装 <a class="header-anchor" href="#_1-2-2-1-安装" aria-label="Permalink to &quot;1.2.2.1 安装&quot;"></a></h4><ul><li>下载到本地:略。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>下载地址在<a href="https://github.com/niXman/mingw-builds-binaries/releases/download/13.2.0-rt_v11-rev1/x86_64-13.2.0-release-posix-seh-ucrt-rt_v11-rev1.7z" target="_blank" rel="noreferrer">这里</a>。</p></div><p><img src="'+l+'" alt="" loading="lazy"></p><ul><li>解压到指定的目录,即:</li></ul><p><img src="'+e+'" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>本人的解压目录是:<code>D:\\develop\\mingw64</code> 。</p></div><h4 id="_1-2-2-2-配置-path-环境变量" tabindex="-1">1.2.2.2 配置 path 环境变量 <a class="header-anchor" href="#_1-2-2-2-配置-path-环境变量" aria-label="Permalink to &quot;1.2.2.2 配置 path 环境变量&quot;"></a></h4><ul><li>配置环境变量,以便任意目录都可以执行 gcc 命令,即:</li></ul><p><img src="'+p+'" alt="" loading="lazy"></p><p><img src="'+t+'" alt="" loading="lazy"></p><p><img src="'+r+'" alt="" loading="lazy"></p><p><img src="'+c+'" alt="" loading="lazy"></p><p><img src="'+h+'" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>因为,本人安装 MinGW-w64 的目录是 <code>D:\\develop\\mingw64</code>,所以本人需要配置的 path 环境变量就是<code>D:\\develop\\mingw64\\bin</code>。</p></div><p><img src="'+d+'" alt="" loading="lazy"></p><ul><li>测试是否安装成功:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">gcc</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --version</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+o+'" alt="" loading="lazy"></p><h3 id="_1-2-3-cygwin-的安装和配置" tabindex="-1">1.2.3 Cygwin 的安装和配置 <a class="header-anchor" href="#_1-2-3-cygwin-的安装和配置" aria-label="Permalink to &quot;1.2.3 Cygwin 的安装和配置&quot;"></a></h3><h4 id="_1-2-3-1-安装" tabindex="-1">1.2.3.1 安装 <a class="header-anchor" href="#_1-2-3-1-安装" aria-label="Permalink to &quot;1.2.3.1 安装&quot;"></a></h4><ul><li>下载到本地:略。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>下载地址在<a href="https://www.cygwin.com/install.html" target="_blank" rel="noreferrer">这里</a>。</p></div><p><img src="'+k+'" alt="" loading="lazy"></p><ul><li>点击安装:</li></ul><p><img src="'+u+'" alt="" loading="lazy"></p><p><img src="'+g+'" alt="" loading="lazy"></p><p><img src="'+b+'" alt="" loading="lazy"></p><p><img src="'+m+'" alt="" loading="lazy"></p><p><img src="'+C+'" alt="" loading="lazy"></p><p><img src="'+y+'" alt="" loading="lazy"></p><p><img src="'+E+'" alt="" loading="lazy"></p><p><img src="'+F+'" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>默认是最小化安装,没有 GCC需要选择 gcc-core、gcc-g++、make、gdb、binutils 。</p></div><p><img src="'+_+'" alt="" loading="lazy"></p><p><img src="'+v+'" alt="" loading="lazy"></p><p><img src="'+B+'" alt="" loading="lazy"></p><p><img src="'+f+'" alt="" loading="lazy"></p><p><img src="'+A+'" alt="" loading="lazy"></p><p><img src="'+D+'" alt="" loading="lazy"></p><p><img src="'+x+'" alt="" loading="lazy"></p><p><img src="'+q+'" alt="" loading="lazy"></p><p><img src="'+w+'" alt="" loading="lazy"></p><h4 id="_1-2-3-2-配置-path-环境变量" tabindex="-1">1.2.3.2 配置 path 环境变量 <a class="header-anchor" href="#_1-2-3-2-配置-path-环境变量" aria-label="Permalink to &quot;1.2.3.2 配置 path 环境变量&quot;"></a></h4><ul><li>和 <code>1.2.2.2 配置 path 环境变量</code> 步骤相同:略。</li></ul><h3 id="_1-2-4-msys2-推荐" tabindex="-1">1.2.4 MSYS2推荐 <a class="header-anchor" href="#_1-2-4-msys2-推荐" aria-label="Permalink to &quot;1.2.4 MSYS2推荐&quot;"></a></h3><h4 id="_1-2-4-1-安装" tabindex="-1">1.2.4.1 安装 <a class="header-anchor" href="#_1-2-4-1-安装" aria-label="Permalink to &quot;1.2.4.1 安装&quot;"></a></h4><ul><li>下载到本地:略。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>下载地址在<a href="https://www.msys2.org/" target="_blank" rel="noreferrer">这里</a>。</p></div><p><img src="'+S+'" alt="" loading="lazy"></p><ul><li>点击安装:</li></ul><p><img src="'+L+'" alt="" loading="lazy"></p><p><img src="'+z+'" alt="" loading="lazy"></p><p><img src="'+P+'" alt="" loading="lazy"></p><p><img src="'+W+'" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>可能很多人,会遇到安装到 <code>50%</code> 就一直卡死在那边,不用慌,关闭它,再次重新安装即可。</p></div><p><img src="'+T+'" alt="" loading="lazy"></p><ul><li>出现命令终端:</li></ul><p><img src="'+M+`" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>如果没有出现命令终端,也不要慌,去 Win11 操作系统的<code>开始</code>菜单,那边找一下,就能找到。</p></div><ul><li>替换清华镜像源(可选):</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sed</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -i</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \\</span></span>
import{_ as s,c as a,o as i,a6 as n}from"./chunks/framework.hMCIpNYY.js";const l="/c/assets/1.D60Zf6_d.png",e="/c/assets/2.D2-G6nV2.png",p="/c/assets/3.DpzkVk5V.png",t="/c/assets/4.BXk95GIP.png",r="/c/assets/5.CbWTB08W.png",c="/c/assets/6.twO9TCIg.png",h="/c/assets/7.CKOjeIvS.png",d="/c/assets/8.DKmR0CxE.png",o="/c/assets/9.Cudf77_s.gif",k="/c/assets/10.BBUUlhRC.png",u="/c/assets/11.iLABkB7O.png",g="/c/assets/12.BQuYWOU9.png",b="/c/assets/13.CslpH6j0.png",m="/c/assets/14.BAyvZdKq.png",C="/c/assets/15.C3oC1iUd.png",y="/c/assets/16.Ds-jsEZn.png",E="/c/assets/17.Cd37gMYs.png",F="/c/assets/18.CAw2z3gc.png",_="/c/assets/19.DdPThnr-.png",v="/c/assets/20.q_rvlDnY.png",B="/c/assets/21.JRHg9RZA.png",f="/c/assets/22.Baq-Hb06.png",A="/c/assets/23.c1ht53mu.png",D="/c/assets/24.CAZmH5Py.png",x="/c/assets/25.DWeCYBe9.png",q="/c/assets/26.2XM8pYni.png",w="/c/assets/27.CN0t-fuo.png",L="/c/assets/28.AcDh3LXQ.png",S="/c/assets/29.CUkDFAc6.png",z="/c/assets/30.picNTNaJ.png",P="/c/assets/31.DKX92RgJ.png",W="/c/assets/32.Bxr7QKI3.png",T="/c/assets/33.DuFWsOgW.png",M="/c/assets/34.Da9qUcfr.png",U="/c/assets/35.7_gEABSX.gif",O="/c/assets/36.C2KQYoVC.gif",I="/c/assets/37.RTUP8Vtx.png",N="/c/assets/38.Dq21DxwL.png",R="/c/assets/39.QmpUaNxU.png",V="/c/assets/40.DP0C29gZ.png",G="/c/assets/41.DwzHokd4.png",X="/c/assets/42.Bi6K26yA.png",$="/c/assets/43.Bw8DcEQ_.png",H="/c/assets/44.DPc8Z9rS.png",K="/c/assets/45.S84xHMTl.png",Q="/c/assets/46.iw3JQUkn.png",J="/c/assets/47.ILeJt-HK.png",Y="/c/assets/48.CHgm7khh.png",j="/c/assets/49.N1nqJaEg.png",Z="/c/assets/50.DHsnibMi.png",ss="/c/assets/51.BQr6Q0uV.png",as="/c/assets/52.BVemi2Lh.png",is="/c/assets/53.BHR69UXx.png",ns="/c/assets/54.CPSU5SJI.png",ls="/c/assets/55.CaQLoDlw.png",es="/c/assets/56.aRGy4XbL.png",ps="/c/assets/57.kNO9fmPR.png",ts="/c/assets/58.D4EkoC4o.png",rs="/c/assets/59.V23Lo9e_.png",cs="/c/assets/60.Du9LVeMB.png",hs="/c/assets/61.DdFg75U9.png",ds="/c/assets/62.C6bz6KtT.png",os="/c/assets/63.CB6LAhB5.png",ks="/c/assets/64.Bip8bkua.png",us="/c/assets/65.DRNHRduW.png",gs="/c/assets/66.Cth4qqEn.png",bs="/c/assets/67.DWGWZ64P.png",ms="/c/assets/68.3hDIDdvx.png",Cs="/c/assets/69.Bw_dQ4ap.png",ys="/c/assets/70.Cn_ubTyA.png",Es="/c/assets/71.C84EBqwB.png",Fs="/c/assets/72.dZfJY4eR.png",_s="/c/assets/73.B0zm0Z79.png",vs="/c/assets/74.CaTcEy1Q.png",Bs="/c/assets/75.iEc8mo9g.png",fs="/c/assets/76.Co2KxM6t.png",As="/c/assets/77.CaUm8Qhc.png",Ds="/c/assets/78.kOkqIKG6.png",xs="/c/assets/79.CyeASH-c.png",qs="/c/assets/80.CFdk60La.png",ws="/c/assets/81.Bhl-0uK_.png",Ls="/c/assets/82.Dni9KbXV.png",Ss="/c/assets/83.BXx10MCV.png",zs="/c/assets/84.CXcIKX1T.png",Ps="/c/assets/85.DptbJqQo.png",Ws="/c/assets/86.CQ3_QCQT.png",Ts="/c/assets/87.CQoDRJM5.gif",Ms="/c/assets/88.CPfwZvD9.gif",Us="/c/assets/89.bxEomEjU.gif",Os="/c/assets/90.C_onhf2k.png",Is="/c/assets/91.Budj3s38.gif",Ns="/c/assets/92.CH8koQdu.gif",Rs="/c/assets/93.kUJhxMtg.png",Vs="/c/assets/94.BJeJJW4_.png",Gs="/c/assets/95.BCuK6eJL.gif",Xs="/c/assets/96.rKC-z4z-.gif",$s="/c/assets/97.BJE3xxuT.gif",Hs="/c/assets/98.DJOq__O0.gif",Ks="/c/assets/99.BDt_0fRR.png",Qs="/c/assets/100.Bo5OawW8.png",Js="/c/assets/101.sUWUfl5e.png",Ys="/c/assets/102.BK4jpnB8.png",js="/c/assets/103.EF8vdbSq.png",Zs="/c/assets/104.DjxdA_Co.png",sa="/c/assets/105.sp68q1hh.gif",aa="/c/assets/106.DhMRyxNN.gif",ia="/c/assets/107.CdcLZM0R.gif",na="/c/assets/108.D-5AsTTr.png",la="/c/assets/109.2RQKmAUa.png",ea="/c/assets/110.CI4xX8SM.png",pa="/c/assets/111.C8QUZ9v3.gif",ta="/c/assets/112.g5tQfhWz.gif",ra="/c/assets/113.CX0_1NsE.gif",ca="/c/assets/114.BrFJeoK6.png",ha="/c/assets/115.58TjSSjH.gif",da="/c/assets/116.DmiFIqcy.svg",oa="/c/assets/117.BasYWvkM.png",ka="/c/assets/118.CjFxJpBr.png",ua="/c/assets/119.Dm5Jspvp.gif",ga="/c/assets/120.1krCh8cy.gif",ba="/c/assets/121.DOSyahv7.gif",ma="/c/assets/122.BHEvX_FI.gif",Ca="/c/assets/123.DFA0g1_d.gif",ya="/c/assets/124.D50nO5eA.gif",Ea="/c/assets/125.cAvG1Qfq.png",Fa="/c/assets/126.DpakQFWz.gif",_a="/c/assets/127.Bg61j9QI.gif",va="/c/assets/128.DPvD9UCw.gif",Ba="/c/assets/129.Ceu65U_n.gif",fa="/c/assets/130.BWPFRK_8.gif",Aa="/c/assets/131.Ct4TfxPf.gif",Da="/c/assets/132.zsKtx_jV.png",xa="/c/assets/133.3oqDAW0w.png",qa="/c/assets/134.D9TSeAa9.gif",wa="/c/assets/135.CCRgYIVq.png",La="/c/assets/136.C1t2T6FV.gif",Sa="/c/assets/137.Rqa4uHq6.png",za="/c/assets/138.6yQYnjOa.gif",Pa="/c/assets/139.hYR9GiiD.gif",Wa="/c/assets/140.D3b-QIrA.gif",Ta="/c/assets/141.DGbA6qsW.gif",Ma="/c/assets/142.BToOkxf2.gif",Ua="/c/assets/143.C3wekjfY.png",Oa="/c/assets/144.CKuuzuQ_.png",Ia="/c/assets/145.B4r6Nv14.gif",Na="/c/assets/146.CvbhuZNK.png",Ra="/c/assets/147.BPgYm4ZX.gif",Va="/c/assets/148.DH2fri13.gif",Ga="/c/assets/149.CDDIqy03.gif",Xa="/c/assets/150.DCQsqYYC.gif",$a="/c/assets/151.CUjMoXNF.gif",Ha="/c/assets/152.BWbajkuB.gif",Ka="/c/assets/153.C1JnBDr7.png",Qa="/c/assets/154.DwN2p3bo.png",Ja="/c/assets/155.DdSfz-Pf.gif",Ya="/c/assets/156.BMocjVt7.gif",ja="/c/assets/157.BUU-wlaw.gif",Za="/c/assets/158.ssadIF0D.gif",si="/c/assets/159.Dq5lLq9v.gif",ai="/c/assets/160.CJ0_loZ8.gif",ii="/c/assets/161.BPOK9irZ.gif",ni="/c/assets/162.B1eB55rC.gif",li="/c/assets/163.VIcU-hkN.gif",ei="/c/assets/164.BM9viRZJ.gif",pi="/c/assets/165.DpMBA1SK.gif",ti="/c/assets/166.DgXuU6LF.png",ri="/c/assets/167.Dnw73s2h.gif",ci="/c/assets/168.SnFXRSaL.png",hi="/c/assets/169.DnoEqOjV.png",di="/c/assets/170.BJBdn7pw.png",oi="/c/assets/171.DXtQWYsM.gif",ki="/c/assets/172.hcERTQkN.gif",ui="/c/assets/173.CioraEUv.png",gi="/c/assets/174.kWHWwnc_.png",bi="/c/assets/175.DhVZ6aP-.gif",mi="/c/assets/176.CUl5g8VJ.png",Ci="/c/assets/177.FJeffiE3.gif",yi="/c/assets/178.Bee0LcNX.gif",Ei="/c/assets/179.BDqd1eDo.png",Si=JSON.parse('{"title":"第一章:开发环境的安装和配置(⭐)","description":"","frontmatter":{},"headers":[],"relativePath":"notes/01_c-basic/01_xdx/index.md","filePath":"notes/01_c-basic/01_xdx/index.md","lastUpdated":1724728274000}'),Fi={name:"notes/01_c-basic/01_xdx/index.md"},_i=n('<h1 id="第一章-开发环境的安装和配置-⭐" tabindex="-1">第一章:开发环境的安装和配置(⭐) <a class="header-anchor" href="#第一章-开发环境的安装和配置-⭐" aria-label="Permalink to &quot;第一章:开发环境的安装和配置(⭐)&quot;"></a></h1><h2 id="_1-1-什么是编译器" tabindex="-1">1.1 什么是编译器? <a class="header-anchor" href="#_1-1-什么是编译器" aria-label="Permalink to &quot;1.1 什么是编译器?&quot;"></a></h2><ul><li>要开发 C/C++ 程序,需要安装 C/C++ 编译器,目前有两种主流实现,即: <ul><li>GCCGNU Compiler Collection全平台实现即支持 Windows、MacOS、Linux 等。</li><li>MSVCMicrosoft Visual C++):只支持 Windows 系统。</li></ul></li><li>GCC 在 Windows 上的版本有很多,如:<a href="https://www.mingw-w64.org/" target="_blank" rel="noreferrer">MinGW-w64</a>、<a href="https://cygwin.com/" target="_blank" rel="noreferrer">Gygwin</a>、<a href="https://www.msys2.org/" target="_blank" rel="noreferrer">MSYS2</a>。它们之间的区别,如下所示:</li></ul><table tabindex="0"><thead><tr><th>特性</th><th>MinGW-w64</th><th>Cygwin</th><th>MSYS2</th></tr></thead><tbody><tr><td><strong>简介</strong></td><td>Minimalist GNU for Windows</td><td>POSIX 兼容环境和工具集</td><td>结合了 MinGW 和 Cygwin 的工具集</td></tr><tr><td><strong>编译器</strong></td><td>提供 GCC 编译器</td><td>提供 POSIX 兼容环境,包含大量工具</td><td>提供 MinGW-w64 工具链和 Cygwin 环境</td></tr><tr><td><strong>生成文件</strong></td><td>Windows 原生可执行文件</td><td>POSIX 兼容的可执行文件</td><td>可以生成 Windows 原生可执行文件或 POSIX 文件</td></tr><tr><td><strong>依赖</strong></td><td>无需额外依赖</td><td>依赖 Cygwin DLL</td><td>根据使用工具链决定MinGW-w64 无依赖Cygwin 有依赖)</td></tr><tr><td><strong>工具和库</strong></td><td>基本的编译工具</td><td>丰富的 Unix 工具和库</td><td>丰富的工具和库,强大的包管理系统</td></tr><tr><td><strong>性能</strong></td><td>性能较好</td><td>可能较低,因为通过兼容层调用系统</td><td>取决于使用的工具链MinGW-w64 性能较好)</td></tr><tr><td><strong>复杂度</strong></td><td>简单易用</td><td>设置和使用相对复杂</td><td>较为灵活,复杂度介于 MinGW-w64 和 Cygwin 之间</td></tr><tr><td><strong>适用场景</strong></td><td>开发 Windows 原生应用</td><td>运行和开发 Unix 程序</td><td>混合使用 Unix 工具和开发 Windows 原生应用</td></tr><tr><td><strong>优点</strong></td><td>轻量级,直接生成 Windows 应用</td><td>完整的 POSIX 兼容环境,丰富的工具</td><td>灵活的环境,强大的包管理系统</td></tr><tr><td><strong>缺点</strong></td><td>工具和库较少</td><td>生成文件依赖 Cygwin DLL性能可能较低</td><td>环境较大,占用更多空间,复杂性比 MinGW-w64 高</td></tr></tbody></table><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① MinGW-w64 、Cygwin 以及 MSYS2 任选其一安装即可。</li><li>② 目前的 Win10 和 Win11 版本支持 WSL2 Windows Sub Linux 2 ,即 Windows 的子系统 Linux可以实现在 Windows 系统上安装一个 Linux ,然后再运行 Linux 中的 GCC 工具链。</li><li>③ 本人的操作系统是 Win11 ,安装和配置都将以该系统为基础作为演示,后续不再赘述!!!</li></ul></div><h2 id="_1-2-编译器的安装和配置" tabindex="-1">1.2 编译器的安装和配置 <a class="header-anchor" href="#_1-2-编译器的安装和配置" aria-label="Permalink to &quot;1.2 编译器的安装和配置&quot;"></a></h2><h3 id="_1-2-2-mingw-w64-的安装和配置" tabindex="-1">1.2.2 MinGW-w64 的安装和配置 <a class="header-anchor" href="#_1-2-2-mingw-w64-的安装和配置" aria-label="Permalink to &quot;1.2.2 MinGW-w64 的安装和配置&quot;"></a></h3><h4 id="_1-2-2-1-安装" tabindex="-1">1.2.2.1 安装 <a class="header-anchor" href="#_1-2-2-1-安装" aria-label="Permalink to &quot;1.2.2.1 安装&quot;"></a></h4><ul><li>下载到本地:略。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>下载地址在<a href="https://github.com/niXman/mingw-builds-binaries/releases/download/13.2.0-rt_v11-rev1/x86_64-13.2.0-release-posix-seh-ucrt-rt_v11-rev1.7z" target="_blank" rel="noreferrer">这里</a>。</p></div><p><img src="'+l+'" alt="" loading="lazy"></p><ul><li>解压到指定的目录,即:</li></ul><p><img src="'+e+'" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>本人的解压目录是:<code>D:\\develop\\mingw64</code> 。</p></div><h4 id="_1-2-2-2-配置-path-环境变量" tabindex="-1">1.2.2.2 配置 path 环境变量 <a class="header-anchor" href="#_1-2-2-2-配置-path-环境变量" aria-label="Permalink to &quot;1.2.2.2 配置 path 环境变量&quot;"></a></h4><ul><li>配置环境变量,以便任意目录都可以执行 gcc 命令,即:</li></ul><p><img src="'+p+'" alt="" loading="lazy"></p><p><img src="'+t+'" alt="" loading="lazy"></p><p><img src="'+r+'" alt="" loading="lazy"></p><p><img src="'+c+'" alt="" loading="lazy"></p><p><img src="'+h+'" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>因为,本人安装 MinGW-w64 的目录是 <code>D:\\develop\\mingw64</code>,所以本人需要配置的 path 环境变量就是<code>D:\\develop\\mingw64\\bin</code>。</p></div><p><img src="'+d+'" alt="" loading="lazy"></p><ul><li>测试是否安装成功:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">gcc</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --version</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+o+'" alt="" loading="lazy"></p><h3 id="_1-2-3-cygwin-的安装和配置" tabindex="-1">1.2.3 Cygwin 的安装和配置 <a class="header-anchor" href="#_1-2-3-cygwin-的安装和配置" aria-label="Permalink to &quot;1.2.3 Cygwin 的安装和配置&quot;"></a></h3><h4 id="_1-2-3-1-安装" tabindex="-1">1.2.3.1 安装 <a class="header-anchor" href="#_1-2-3-1-安装" aria-label="Permalink to &quot;1.2.3.1 安装&quot;"></a></h4><ul><li>下载到本地:略。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>下载地址在<a href="https://www.cygwin.com/install.html" target="_blank" rel="noreferrer">这里</a>。</p></div><p><img src="'+k+'" alt="" loading="lazy"></p><ul><li>点击安装:</li></ul><p><img src="'+u+'" alt="" loading="lazy"></p><p><img src="'+g+'" alt="" loading="lazy"></p><p><img src="'+b+'" alt="" loading="lazy"></p><p><img src="'+m+'" alt="" loading="lazy"></p><p><img src="'+C+'" alt="" loading="lazy"></p><p><img src="'+y+'" alt="" loading="lazy"></p><p><img src="'+E+'" alt="" loading="lazy"></p><p><img src="'+F+'" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>默认是最小化安装,没有 GCC需要选择 gcc-core、gcc-g++、make、gdb、binutils 。</p></div><p><img src="'+_+'" alt="" loading="lazy"></p><p><img src="'+v+'" alt="" loading="lazy"></p><p><img src="'+B+'" alt="" loading="lazy"></p><p><img src="'+f+'" alt="" loading="lazy"></p><p><img src="'+A+'" alt="" loading="lazy"></p><p><img src="'+D+'" alt="" loading="lazy"></p><p><img src="'+x+'" alt="" loading="lazy"></p><p><img src="'+q+'" alt="" loading="lazy"></p><p><img src="'+w+'" alt="" loading="lazy"></p><h4 id="_1-2-3-2-配置-path-环境变量" tabindex="-1">1.2.3.2 配置 path 环境变量 <a class="header-anchor" href="#_1-2-3-2-配置-path-环境变量" aria-label="Permalink to &quot;1.2.3.2 配置 path 环境变量&quot;"></a></h4><ul><li>和 <code>1.2.2.2 配置 path 环境变量</code> 步骤相同:略。</li></ul><h3 id="_1-2-4-msys2-推荐" tabindex="-1">1.2.4 MSYS2推荐 <a class="header-anchor" href="#_1-2-4-msys2-推荐" aria-label="Permalink to &quot;1.2.4 MSYS2推荐&quot;"></a></h3><h4 id="_1-2-4-1-安装" tabindex="-1">1.2.4.1 安装 <a class="header-anchor" href="#_1-2-4-1-安装" aria-label="Permalink to &quot;1.2.4.1 安装&quot;"></a></h4><ul><li>下载到本地:略。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>下载地址在<a href="https://www.msys2.org/" target="_blank" rel="noreferrer">这里</a>。</p></div><p><img src="'+L+'" alt="" loading="lazy"></p><ul><li>点击安装:</li></ul><p><img src="'+S+'" alt="" loading="lazy"></p><p><img src="'+z+'" alt="" loading="lazy"></p><p><img src="'+P+'" alt="" loading="lazy"></p><p><img src="'+W+'" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>可能很多人,会遇到安装到 <code>50%</code> 就一直卡死在那边,不用慌,关闭它,再次重新安装即可。</p></div><p><img src="'+T+'" alt="" loading="lazy"></p><ul><li>出现命令终端:</li></ul><p><img src="'+M+`" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>如果没有出现命令终端,也不要慌,去 Win11 操作系统的<code>开始</code>菜单,那边找一下,就能找到。</p></div><ul><li>替换清华镜像源(可选):</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sed</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -i</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \\</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;s#https\\?://mirror.msys2.org/#https://mirrors.tuna.tsinghua.edu.cn/msys2/#g&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \\</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /etc/pacman.d/mirrorlist</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">*</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p><img src="`+U+'" alt="" loading="lazy"></p><ul><li> gcc </li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">pacman</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -Syu</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --noconfirm</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # </span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">pacman</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -Sy</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> base-devel</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --noconfirm</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # </span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">pacman</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -Sy</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> mingw-w64-ucrt-x86_64-toolchain</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --noconfirm</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # gcc </span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p> <code>pacman -Sy mingw-w64-x86_64-toolchain --noconfirm</code></p><ul><li> <code>mingw-w64-x86_64-toolchain</code> 使 MSVCRT MinGW C </li><li> <code>mingw-w64-ucrt-x86_64-toolchain</code> 使 Microsoft UCRT Windows </li></ul></div><p><img src="'+O+'" alt="" loading="lazy"></p><h4 id="_1-2-4-2--path-" tabindex="-1">1.2.4.2 path <a class="header-anchor" href="#_1-2-4-2--path-" aria-label="Permalink to &quot;1.2.4.2 path &quot;"></a></h4><ul><li> <code>1.2.2.2 path </code> </li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p> path <code>C:\\msys64\\ucrt64\\bin</code> </p></div><h2 id="_1-3--ide-" tabindex="-1">1.3 IDE <a class="header-anchor" href="#_1-3--ide-" aria-label="Permalink to &quot;1.3 IDE&quot;"></a></h2><ul><li><p><code></code></p><ul><li>便</li><li></li><li></li><li></li><li>便</li></ul></li><li><p>Visual StudioCLion VS Code IDEIntegrated Development Environment</p></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li> IDE IDE UIDE 使 IDE </li><li> VS Code IDE IDE Visual Studio CLion IDE</li><li> 使 IDE 使<code></code><code>vi/vim</code> 使<code></code> <code>vi/vim</code>使 IDE IDE IDE IDE </li></ul></div><h2 id="_1-4-ide-" tabindex="-1">1.4 IDE <a class="header-anchor" href="#_1-4-ide-" aria-label="Permalink to &quot;1.4 IDE &quot;"></a></h2><h3 id="_1-4-1-clion" tabindex="-1">1.4.1 CLion <a class="header-anchor" href="#_1-4-1-clion" aria-label="Permalink to &quot;1.4.1 CLion&quot;"></a></h3><h4 id="_1-4-1-1-" tabindex="-1">1.4.1.1 <a class="header-anchor" href="#_1-4-1-1-" aria-label="Permalink to &quot;1.4.1.1 &quot;"></a></h4><ul><li><a href="https://www.jetbrains.com/clion/" target="_blank" rel="noreferrer">CLion</a> JetBrains C/C++ IDECMake C/C++ </li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li> CLion 2024.1.4 </li><li> CLion IDE C Windows MinGWCLion C Windows 使 MSYS2 </li></ul></div><h4 id="_1-4-1-2-" tabindex="-1">1.4.1.2 <a class="header-anchor" href="#_1-4-1-2-" aria-label="Permalink to &quot;1.4.1.2 &quot;"></a></h4><ul><li></li></ul><p><img src="'+I+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+N+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+R+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+V+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+G+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+X+'" alt="" loading="lazy"></p><h4 id="_1-4-1-3-" tabindex="-1">1.4.1.3 <a class="header-anchor" href="#_1-4-1-3-" aria-label="Permalink to &quot;1.4.1.3 &quot;"></a></h4><ul><li> CLion </li></ul><p><img src="'+$+'" alt="" loading="lazy"></p><ul><li></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>CLion 2024.2 </p></div><p><img src="'+H+'" alt="" loading="lazy"></p><p><img src="'+K+'" alt="" loading="lazy"></p><ul><li> UI </li></ul><p><img src="'+Q+'" alt="" loading="lazy"></p><p><img src="'+J+'" alt="" loading="lazy"></p><ul><li> UI </li></ul><p><img src="'+Y+'" alt="" loading="lazy"></p><ul><li><code></code></li></ul><p><img src="'+j+'" alt="" loading="lazy"></p><ul><li><code></code> UTF-8</li></ul><p><img src="'+Z+'" alt="" loading="lazy"></p><ul><li><code></code> UTF-8</li></ul><p><img src="'+ss+'" alt="" loading="lazy"></p><ul><li><code></code></li></ul><p><img src="'+as+'" alt="" loading="lazy"></p><ul><li><code></code></li></ul><p><img src="'+is+'" alt="" loading="lazy"></p><ul><li> GCC </li></ul><p><img src="'+ns+'" alt="" loading="lazy"></p><h3 id="_1-4-2-vs-code" tabindex="-1">1.4.2 VS Code <a class="header-anchor" href="#_1-4-2-vs-code" aria-label="Permalink to &quot;1.4.2 VS Code&quot;"></a></h3><h4 id="_1-4-2-1-" tabindex="-1">1.4.2.1 <a class="header-anchor" href="#_1-4-2-1-" aria-label="Permalink to &quot;1.4.2.1 &quot;"></a></h4><ul><li><a href="https://code.visualstudio.com/" target="_blank" rel="noreferrer">Visual Studio Code (VS Code)</a> WindowsMacOS Linux IntelliSenseGitVS Code Azure </li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li> Visual Studio Code C/C++ </li><li> Visual Studio Code 使</li></ul></div><h4 id="_1-4-2-2-" tabindex="-1">1.4.2.2 <a class="header-anchor" href="#_1-4-2-2-" aria-label="Permalink to &quot;1.4.2.2 &quot;"></a></h4><ul><li></li></ul><p><img src="'+ls+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+es+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+ps+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+ts+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+rs+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+cs+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+hs+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+ds+'" alt="" loading="lazy"></p><h4 id="_1-4-2-3-" tabindex="-1">1.4.2.3 <a class="header-anchor" href="#_1-4-2-3-" aria-label="Permalink to &quot;1.4.2.3 &quot;"></a></h4><ul><li><code></code></li></ul><p><img src="'+os+'" alt="" loading="lazy"></p><p><img src="'+ks+'" alt="" loading="lazy"></p><ul><li> <code>C/C++</code> </li></ul><p><img src="'+us+'" alt="" loading="lazy"></p><p><img src="'+gs+'" alt="" loading="lazy"></p><h3 id="_1-4-3-microsoft-visual-studio" tabindex="-1">1.4.3 Microsoft Visual Studio <a class="header-anchor" href="#_1-4-3-microsoft-visual-studio" aria-label="Permalink to &quot;1.4.3 Microsoft Visual Studio&quot;"></a></h3><h4 id="_1-4-3-1-" tabindex="-1">1.4.3.1 <a class="header-anchor" href="#_1-4-3-1-" aria-label="Permalink to &quot;1.4.3.1 &quot;"></a></h4><ul><li><a href="https://visualstudio.microsoft.com/" target="_blank" rel="noreferrer">Visual Studio</a> VSUML Git </li><li>Visual Studio C/C++C#F#VB Web </li><li>Visual Studio 使</li><li>Visual Studio IDE IDE</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p> Visual Studio Visual Studio 2022 </p></div><h4 id="_1-4-3-2-" tabindex="-1">1.4.3.2 <a class="header-anchor" href="#_1-4-3-2-" aria-label="Permalink to &quot;1.4.3.2 &quot;"></a></h4><ul><li></li></ul><p><img src="'+bs+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+ms+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+Cs+'" alt="" loading="lazy"></p><ul><li>使 C++ </li></ul><p><img src="'+ys+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+Es+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+Fs+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+_s+'" alt="" loading="lazy"></p><ul><li><code> SDK</code></li></ul><p><img src="'+vs+'" alt="" loading="lazy"></p><ul><li><code></code></li></ul><p><img src="'+Bs+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+fs+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+As+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+Ds+'" alt="" loading="lazy"></p><h4 id="_1-4-3-3-" tabindex="-1">1.4.3.3 <a class="header-anchor" href="#_1-4-3-3-" aria-label="Permalink to &quot;1.4.3.3 &quot;"></a></h4><ul><li> VS </li></ul><p><img src="'+xs+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+qs+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+ws+'" alt="" loading="lazy"></p><ul><li> VS </li></ul><p><img src="'+Ss+'" alt="" loading="lazy"></p><ul><li></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li> Pro <code>TD244-P4NB7-YQ6XK-Y8MMM-YWV2J</code></li><li> Enterprise <code>VHF9H-NXBBB-638P6-6JHCY-88JWH</code></li></ul></div><p><img src="'+Ls+'" alt="" loading="lazy"></p><p><img src="'+zs+'" alt="" loading="lazy"></p><h2 id="_1-5--" tabindex="-1">1.5 / <a class="header-anchor" href="#_1-5--" aria-label="Permalink to &quot;1.5 / &quot;"></a></h2><h3 id="_1-5-1-" tabindex="-1">1.5.1 <a class="header-anchor" href="#_1-5-1-" aria-label="Permalink to &quot;1.5.1 &quot;"></a></h3><ul><li></li><li></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p></p></div><ul><li></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p></p><ul><li> 使</li><li> </li></ul></div><ul><li> IDE </li></ul><p><img src="'+Ps+'" alt="" loading="lazy"></p><h3 id="_1-5-2--" tabindex="-1">1.5.2 / <a class="header-anchor" href="#_1-5-2--" aria-label="Permalink to &quot;1.5.2 /&quot;"></a></h3><ul><li><p></p><ul><li>Console ApplicationUnix/Linux <code>ls</code>Windows <code>cmd.exe</code></li><li>GUI Graphical User Interface ProgramGUI QQ </li><li> <ul><li> C/C++ <code>.lib</code>Windows<code>.a</code>Unix/Linux</li><li> Windows<code>.dll</code> Unix/Linux <code>.so</code></li></ul></li></ul></li><li><p>GUI IDE IDE </p></li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li> </li><li> GUI </li></ul></div><h1 id="-c--helloworld-" tabindex="-1">C HelloWorld <a class="header-anchor" href="#-c--helloworld-" aria-label="Permalink to &quot;C HelloWorld&quot;"></a></h1><h2 id="_2-1-" tabindex="-1">2.1 <a class="header-anchor" href="#_2-1-" aria-label="Permalink to &quot;2.1 &quot;"></a></h2><ul><li> <code>HelloWorld.c</code> </li></ul><p><img src="'+Ws+`" alt="" loading="lazy"></p><ul><li> <code></code></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /etc/pacman.d/mirrorlist</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">*</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p><img src="`+U+'" alt="" loading="lazy"></p><ul><li> gcc </li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">pacman</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -Syu</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --noconfirm</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # </span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">pacman</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -Sy</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> base-devel</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --noconfirm</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # </span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">pacman</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -Sy</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> mingw-w64-ucrt-x86_64-toolchain</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --noconfirm</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # gcc </span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p> <code>pacman -Sy mingw-w64-x86_64-toolchain --noconfirm</code></p><ul><li> <code>mingw-w64-x86_64-toolchain</code> 使 MSVCRT MinGW C </li><li> <code>mingw-w64-ucrt-x86_64-toolchain</code> 使 Microsoft UCRT Windows </li></ul></div><p><img src="'+O+'" alt="" loading="lazy"></p><h4 id="_1-2-4-2--path-" tabindex="-1">1.2.4.2 path <a class="header-anchor" href="#_1-2-4-2--path-" aria-label="Permalink to &quot;1.2.4.2 path &quot;"></a></h4><ul><li> <code>1.2.2.2 path </code> </li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p> path <code>C:\\msys64\\ucrt64\\bin</code> </p></div><h2 id="_1-3--ide-" tabindex="-1">1.3 IDE <a class="header-anchor" href="#_1-3--ide-" aria-label="Permalink to &quot;1.3 IDE&quot;"></a></h2><ul><li><p><code></code></p><ul><li>便</li><li></li><li></li><li></li><li>便</li></ul></li><li><p>Visual StudioCLion VS Code IDEIntegrated Development Environment</p></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li> IDE IDE UIDE 使 IDE </li><li> VS Code IDE IDE Visual Studio CLion IDE</li><li> 使 IDE 使<code></code><code>vi/vim</code> 使<code></code> <code>vi/vim</code>使 IDE IDE IDE IDE </li></ul></div><h2 id="_1-4-ide-" tabindex="-1">1.4 IDE <a class="header-anchor" href="#_1-4-ide-" aria-label="Permalink to &quot;1.4 IDE &quot;"></a></h2><h3 id="_1-4-1-clion" tabindex="-1">1.4.1 CLion <a class="header-anchor" href="#_1-4-1-clion" aria-label="Permalink to &quot;1.4.1 CLion&quot;"></a></h3><h4 id="_1-4-1-1-" tabindex="-1">1.4.1.1 <a class="header-anchor" href="#_1-4-1-1-" aria-label="Permalink to &quot;1.4.1.1 &quot;"></a></h4><ul><li><a href="https://www.jetbrains.com/clion/" target="_blank" rel="noreferrer">CLion</a> JetBrains C/C++ IDECMake C/C++ </li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li> CLion 2024.1.4 </li><li> CLion IDE C Windows MinGWCLion C Windows 使 MSYS2 </li></ul></div><h4 id="_1-4-1-2-" tabindex="-1">1.4.1.2 <a class="header-anchor" href="#_1-4-1-2-" aria-label="Permalink to &quot;1.4.1.2 &quot;"></a></h4><ul><li></li></ul><p><img src="'+I+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+N+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+R+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+V+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+G+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+X+'" alt="" loading="lazy"></p><h4 id="_1-4-1-3-" tabindex="-1">1.4.1.3 <a class="header-anchor" href="#_1-4-1-3-" aria-label="Permalink to &quot;1.4.1.3 &quot;"></a></h4><ul><li> CLion </li></ul><p><img src="'+$+'" alt="" loading="lazy"></p><ul><li></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>CLion 2024.2 </p></div><p><img src="'+H+'" alt="" loading="lazy"></p><p><img src="'+K+'" alt="" loading="lazy"></p><ul><li> UI </li></ul><p><img src="'+Q+'" alt="" loading="lazy"></p><p><img src="'+J+'" alt="" loading="lazy"></p><ul><li> UI </li></ul><p><img src="'+Y+'" alt="" loading="lazy"></p><ul><li><code></code></li></ul><p><img src="'+j+'" alt="" loading="lazy"></p><ul><li><code></code> UTF-8</li></ul><p><img src="'+Z+'" alt="" loading="lazy"></p><ul><li><code></code> UTF-8</li></ul><p><img src="'+ss+'" alt="" loading="lazy"></p><ul><li><code></code></li></ul><p><img src="'+as+'" alt="" loading="lazy"></p><ul><li><code></code></li></ul><p><img src="'+is+'" alt="" loading="lazy"></p><ul><li> GCC </li></ul><p><img src="'+ns+'" alt="" loading="lazy"></p><h3 id="_1-4-2-vs-code" tabindex="-1">1.4.2 VS Code <a class="header-anchor" href="#_1-4-2-vs-code" aria-label="Permalink to &quot;1.4.2 VS Code&quot;"></a></h3><h4 id="_1-4-2-1-" tabindex="-1">1.4.2.1 <a class="header-anchor" href="#_1-4-2-1-" aria-label="Permalink to &quot;1.4.2.1 &quot;"></a></h4><ul><li><a href="https://code.visualstudio.com/" target="_blank" rel="noreferrer">Visual Studio Code (VS Code)</a> WindowsMacOS Linux IntelliSenseGitVS Code Azure </li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li> Visual Studio Code C/C++ </li><li> Visual Studio Code 使</li></ul></div><h4 id="_1-4-2-2-" tabindex="-1">1.4.2.2 <a class="header-anchor" href="#_1-4-2-2-" aria-label="Permalink to &quot;1.4.2.2 &quot;"></a></h4><ul><li></li></ul><p><img src="'+ls+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+es+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+ps+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+ts+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+rs+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+cs+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+hs+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+ds+'" alt="" loading="lazy"></p><h4 id="_1-4-2-3-" tabindex="-1">1.4.2.3 <a class="header-anchor" href="#_1-4-2-3-" aria-label="Permalink to &quot;1.4.2.3 &quot;"></a></h4><ul><li><code></code></li></ul><p><img src="'+os+'" alt="" loading="lazy"></p><p><img src="'+ks+'" alt="" loading="lazy"></p><ul><li> <code>C/C++</code> </li></ul><p><img src="'+us+'" alt="" loading="lazy"></p><p><img src="'+gs+'" alt="" loading="lazy"></p><h3 id="_1-4-3-microsoft-visual-studio" tabindex="-1">1.4.3 Microsoft Visual Studio <a class="header-anchor" href="#_1-4-3-microsoft-visual-studio" aria-label="Permalink to &quot;1.4.3 Microsoft Visual Studio&quot;"></a></h3><h4 id="_1-4-3-1-" tabindex="-1">1.4.3.1 <a class="header-anchor" href="#_1-4-3-1-" aria-label="Permalink to &quot;1.4.3.1 &quot;"></a></h4><ul><li><a href="https://visualstudio.microsoft.com/" target="_blank" rel="noreferrer">Visual Studio</a> VSUML Git </li><li>Visual Studio C/C++C#F#VB Web </li><li>Visual Studio 使</li><li>Visual Studio IDE IDE</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p> Visual Studio Visual Studio 2022 </p></div><h4 id="_1-4-3-2-" tabindex="-1">1.4.3.2 <a class="header-anchor" href="#_1-4-3-2-" aria-label="Permalink to &quot;1.4.3.2 &quot;"></a></h4><ul><li></li></ul><p><img src="'+bs+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+ms+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+Cs+'" alt="" loading="lazy"></p><ul><li>使 C++ </li></ul><p><img src="'+ys+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+Es+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+Fs+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+_s+'" alt="" loading="lazy"></p><ul><li><code> SDK</code></li></ul><p><img src="'+vs+'" alt="" loading="lazy"></p><ul><li><code></code></li></ul><p><img src="'+Bs+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+fs+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+As+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+Ds+'" alt="" loading="lazy"></p><h4 id="_1-4-3-3-" tabindex="-1">1.4.3.3 <a class="header-anchor" href="#_1-4-3-3-" aria-label="Permalink to &quot;1.4.3.3 &quot;"></a></h4><ul><li> VS </li></ul><p><img src="'+xs+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+qs+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+ws+'" alt="" loading="lazy"></p><ul><li> VS </li></ul><p><img src="'+Ls+'" alt="" loading="lazy"></p><ul><li></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li> Pro <code>TD244-P4NB7-YQ6XK-Y8MMM-YWV2J</code></li><li> Enterprise <code>VHF9H-NXBBB-638P6-6JHCY-88JWH</code></li></ul></div><p><img src="'+Ss+'" alt="" loading="lazy"></p><p><img src="'+zs+'" alt="" loading="lazy"></p><h2 id="_1-5--" tabindex="-1">1.5 / <a class="header-anchor" href="#_1-5--" aria-label="Permalink to &quot;1.5 / &quot;"></a></h2><h3 id="_1-5-1-" tabindex="-1">1.5.1 <a class="header-anchor" href="#_1-5-1-" aria-label="Permalink to &quot;1.5.1 &quot;"></a></h3><ul><li></li><li></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p></p></div><ul><li></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p></p><ul><li> 使</li><li> </li></ul></div><ul><li> IDE </li></ul><p><img src="'+Ps+'" alt="" loading="lazy"></p><h3 id="_1-5-2--" tabindex="-1">1.5.2 / <a class="header-anchor" href="#_1-5-2--" aria-label="Permalink to &quot;1.5.2 /&quot;"></a></h3><ul><li><p></p><ul><li>Console ApplicationUnix/Linux <code>ls</code>Windows <code>cmd.exe</code></li><li>GUI Graphical User Interface ProgramGUI QQ </li><li> <ul><li> C/C++ <code>.lib</code>Windows<code>.a</code>Unix/Linux</li><li> Windows<code>.dll</code> Unix/Linux <code>.so</code></li></ul></li></ul></li><li><p>GUI IDE IDE </p></li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li> </li><li> GUI </li></ul></div><h1 id="-c--helloworld-" tabindex="-1">C HelloWorld <a class="header-anchor" href="#-c--helloworld-" aria-label="Permalink to &quot;C HelloWorld&quot;"></a></h1><h2 id="_2-1-" tabindex="-1">2.1 <a class="header-anchor" href="#_2-1-" aria-label="Permalink to &quot;2.1 &quot;"></a></h2><ul><li> <code>HelloWorld.c</code> </li></ul><p><img src="'+Ws+`" alt="" loading="lazy"></p><ul><li> <code></code></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(){</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;Hello World&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
@ -185,7 +185,7 @@ import{_ as s,c as a,o as i,a6 as n}from"./chunks/framework.hMCIpNYY.js";const l
<span class="line"><span>SpacesInCStyleCastParentheses: false</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br></div></div><ul><li>CLion <code></code><code></code></li></ul><p><img src="`+qa+'" alt="" loading="lazy"></p><h2 id="_6-5--gitignore-" tabindex="-1">6.5 .gitignore <a class="header-anchor" href="#_6-5--gitignore-" aria-label="Permalink to &quot;6.5 .gitignore &quot;"></a></h2><ul><li> <code>.gitignore</code> 便 Git </li></ul><p><img src="'+wa+`" alt="" loading="lazy"></p><ul><li><code>.gitignore</code> </li></ul><div class="language-txt vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">txt</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>.vscode</span></span>
<span class="line"><span>.idea</span></span>
<span class="line"><span>cmake-build-*</span></span>
<span class="line"><span>build</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h2 id="_6-6-" tabindex="-1">6.6 <a class="header-anchor" href="#_6-6-" aria-label="Permalink to &quot;6.6 &quot;"></a></h2><ul><li></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p><code> CMake </code></p></div><p><img src="`+Sa+'" alt="" loading="lazy"></p><h1 id="-c--" tabindex="-1">C <a class="header-anchor" href="#-c--" aria-label="Permalink to &quot;C &quot;"></a></h1><h2 id="_7-1-" tabindex="-1">7.1 <a class="header-anchor" href="#_7-1-" aria-label="Permalink to &quot;7.1 &quot;"></a></h2><ul><li>C </li></ul><p><img src="'+La+'" alt="" loading="lazy"></p><ul><li> C </li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p> <code>.c</code> </p></div><ul><li> C <code></code> <code>.obj</code> <code>.o</code> C </li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li><p> <code></code><code></code><code></code><code></code></p></li><li><p> <code></code><code>#include</code><code>#define</code></p><ul><li><p><code>#include &lt;stdio.h&gt;</code><code>stdio.h</code></p></li><li><p><code>#define PI 3.14</code><code>PI</code><code>3.14</code></p></li><li><p><code>#ifdef</code><code>#ifndef</code></p></li><li><p></p></li><li><p><code>.i</code></p></li></ul></li><li><p> <code></code><code>.s</code></p></li><li><p> <code></code><code>.o</code> <code>.obj</code></p></li></ul></div><ul><li> <code>*.obj</code> <code>*.o</code><code></code> <code>*.exe</code></li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li></li><li> C 使 C <code>&lt;stdio.h&gt;</code> <code>printf()</code> C Linux crt0.ccrti.c main() </li></ul></div><ul><li> <code>*.exe</code> <code>*.exe</code> </li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p><code></code><code></code><code></code> <code>*.exe</code></p></div><h2 id="_7-2-gcc-" tabindex="-1">7.2 GCC <a class="header-anchor" href="#_7-2-gcc-" aria-label="Permalink to &quot;7.2 GCC &quot;"></a></h2><ul><li>vim vscode </li><li></li><li>gccGNU Compiler CollectionGNU GNU gcc GNU Unix LinuxBSDMac OS X gcc Windows </li><li>gcc C gcc CC++JavaAdafortranObject CObject C++Go </li></ul><h2 id="_7-3--gcc-" tabindex="-1">7.3 gcc <a class="header-anchor" href="#_7-3--gcc-" aria-label="Permalink to &quot;7.3 gcc &quot;"></a></h2><ul><li></li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">gcc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> HelloWorld.c</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> HelloWorld.exe</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+za+`" alt="" loading="lazy"></p><h2 id="_7-4--gcc-" tabindex="-1">7.4 gcc <a class="header-anchor" href="#_7-4--gcc-" aria-label="Permalink to &quot;7.4 gcc &quot;"></a></h2><h3 id="_7-3-1-" tabindex="-1">7.3.1 <a class="header-anchor" href="#_7-3-1-" aria-label="Permalink to &quot;7.3.1 &quot;"></a></h3><ul><li></li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># .i </span></span>
<span class="line"><span>build</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h2 id="_6-6-" tabindex="-1">6.6 <a class="header-anchor" href="#_6-6-" aria-label="Permalink to &quot;6.6 &quot;"></a></h2><ul><li></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p><code> CMake </code></p></div><p><img src="`+La+'" alt="" loading="lazy"></p><h1 id="-c--" tabindex="-1">C <a class="header-anchor" href="#-c--" aria-label="Permalink to &quot;C &quot;"></a></h1><h2 id="_7-1-" tabindex="-1">7.1 <a class="header-anchor" href="#_7-1-" aria-label="Permalink to &quot;7.1 &quot;"></a></h2><ul><li>C </li></ul><p><img src="'+Sa+'" alt="" loading="lazy"></p><ul><li> C </li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p> <code>.c</code> </p></div><ul><li> C <code></code> <code>.obj</code> <code>.o</code> C </li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li><p> <code></code><code></code><code></code><code></code></p></li><li><p> <code></code><code>#include</code><code>#define</code></p><ul><li><p><code>#include &lt;stdio.h&gt;</code><code>stdio.h</code></p></li><li><p><code>#define PI 3.14</code><code>PI</code><code>3.14</code></p></li><li><p><code>#ifdef</code><code>#ifndef</code></p></li><li><p></p></li><li><p><code>.i</code></p></li></ul></li><li><p> <code></code><code>.s</code></p></li><li><p> <code></code><code>.o</code> <code>.obj</code></p></li></ul></div><ul><li> <code>*.obj</code> <code>*.o</code><code></code> <code>*.exe</code></li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li></li><li> C 使 C <code>&lt;stdio.h&gt;</code> <code>printf()</code> C Linux crt0.ccrti.c main() </li></ul></div><ul><li> <code>*.exe</code> <code>*.exe</code> </li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p><code></code><code></code><code></code> <code>*.exe</code></p></div><h2 id="_7-2-gcc-" tabindex="-1">7.2 GCC <a class="header-anchor" href="#_7-2-gcc-" aria-label="Permalink to &quot;7.2 GCC &quot;"></a></h2><ul><li>vim vscode </li><li></li><li>gccGNU Compiler CollectionGNU GNU gcc GNU Unix LinuxBSDMac OS X gcc Windows </li><li>gcc C gcc CC++JavaAdafortranObject CObject C++Go </li></ul><h2 id="_7-3--gcc-" tabindex="-1">7.3 gcc <a class="header-anchor" href="#_7-3--gcc-" aria-label="Permalink to &quot;7.3 gcc &quot;"></a></h2><ul><li></li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">gcc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> HelloWorld.c</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> HelloWorld.exe</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+za+`" alt="" loading="lazy"></p><h2 id="_7-4--gcc-" tabindex="-1">7.4 gcc <a class="header-anchor" href="#_7-4--gcc-" aria-label="Permalink to &quot;7.4 gcc &quot;"></a></h2><h3 id="_7-3-1-" tabindex="-1">7.3.1 <a class="header-anchor" href="#_7-3-1-" aria-label="Permalink to &quot;7.3.1 &quot;"></a></h3><ul><li></li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># .i </span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">gcc</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -E</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> .c</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> .i</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><ul><li></li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Linux .s Windows .asm </span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">gcc</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -S</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> .i</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> .s</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><ul><li></li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Linux .o Windows .obj </span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">gcc</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -c</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> .s</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> .o</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><ul><li></li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Linux .out Windows .exe </span></span>
@ -290,8 +290,8 @@ import{_ as s,c as a,o as i,a6 as n}from"./chunks/framework.hMCIpNYY.js";const l
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> libelf++0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> libbfb0-dev</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> python-dev-is-python3</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><p><img src="`+ii+`" alt="" loading="lazy"></p><ul><li></li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">git</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> clone</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \\</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --depth</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \\</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --single-branch</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --branch=linux-msft-wsl-\${</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">KERNEL_VERSION</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">}</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \\</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> https://github.com/microsoft/WSL2-Linux-Kernel.git</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p><img src="`+ni+'" alt="" loading="lazy"></p><ul><li>编译内核代码:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">cd</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> WSL2-Linux-Kernel</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">make</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -j</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">nproc</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">KCONFIG_CONFIG=Microsoft/config-wsl</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+li+'" alt="" loading="lazy"></p><ul><li>编译 perf 工具:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">cd</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> tools/perf</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">make</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> clean</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &amp;&amp; </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">make</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+ei+'" alt="" loading="lazy"></p><ul><li>复制到 PATH 变量所指向的路径中:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">cp</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> perf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /usr/bin/</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+pi+'" alt="" loading="lazy"></p><h3 id="_8-4-3-整合" tabindex="-1">8.4.3 整合 <a class="header-anchor" href="#_8-4-3-整合" aria-label="Permalink to &quot;8.4.3 整合&quot;"></a></h3><ul><li>CLion 中配置 perf 的路径:</li></ul><p><img src="'+ti+'" alt="" loading="lazy"></p><ul><li>在 CLion 中通过 perf 运行代码:</li></ul><p><img src="'+ri+'" alt="" loading="lazy"></p><h2 id="_8-5-win-中文乱码问题" tabindex="-1">8.5 Win 中文乱码问题 <a class="header-anchor" href="#_8-5-win-中文乱码问题" aria-label="Permalink to &quot;8.5 Win 中文乱码问题&quot;"></a></h2><ul><li>前文,我们提及到,在 Win 中,如果出现<code>中文乱码</code>问题,就需要去<code>语言和区别</code>设置<code>系统区域</code>的编码为 UTF-8 但是这样可能会造成其它的软件出现中文乱码问题Xshell 等。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 之所以,修改系统的编码为 UTF-8 会出现问题,是因为早期的 Win 系统的中文默认编码是 GBK目前也是Win 并没有强制第三方软件使用 UTF-8 编码) ,而 Xshell 等也使用的这些编码,一旦我们修改为 UTF-8 之后,可能会造成这些第三方软件出现中文乱码问题(第三方软件适配问题,相信将来应该都会切换为 UTF-8 编码),体验较差!!!</li><li>② 在 Linux 或 MacOS 之所以不会出现中文乱码的问题,是因为这些系统默认的编码就是 UTF-8 。</li></ul></div><ul><li>其实,还有一种解决方案,如下所示:</li></ul><p><img src="'+ci+'" alt="" loading="lazy"></p><p><img src="'+hi+'" alt="" loading="lazy"></p><p><img src="'+di+'" alt="" loading="lazy"></p><ul><li>测试一下,是否配置成功:</li></ul><p><img src="'+oi+'" alt="" loading="lazy"></p><h2 id="_8-6-clion-中自动导入头文件" tabindex="-1">8.6 CLion 中自动导入头文件 <a class="header-anchor" href="#_8-6-clion-中自动导入头文件" aria-label="Permalink to &quot;8.6 CLion 中自动导入头文件&quot;"></a></h2><ul><li>在 CLion 中,最为强大的功能就是直接输入函数,然后让 IDE 帮我们自动导入头文件,包括自定义的头文件,相当实用。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① CLion 中的<code>自动导入头文件</code>的<code>快捷键</code>是 <code>Alt + Enter</code> 。</li><li>② CLion 中的<code>自动提取变量的类型</code>的<code>快捷键</code>是 <code>Ctrl + Alt + V</code> 。</li></ul></div><p><img src="'+ki+'" alt="" loading="lazy"></p><ul><li>开启自动导入头文件的步骤,如下所示:</li></ul><p><img src="'+ui+'" alt="" loading="lazy"></p><p><img src="'+gi+'" alt="" loading="lazy"></p><h2 id="_8-7-wsl2-启用-systemd" tabindex="-1">8.7 WSL2 启用 systemd <a class="header-anchor" href="#_8-7-wsl2-启用-systemd" aria-label="Permalink to &quot;8.7 WSL2 启用 systemd&quot;"></a></h2><h3 id="_8-7-1-概述" tabindex="-1">8.7.1 概述 <a class="header-anchor" href="#_8-7-1-概述" aria-label="Permalink to &quot;8.7.1 概述&quot;"></a></h3><ul><li>根据 <a href="https://systemd.io/" target="_blank" rel="noreferrer">systemd.io</a>“systemd 是 Linux 系统的基本构建基块套件。 它提供一个系统和服务管理器,该管理器作为 PID 1 运行并启动系统的其余部分。”</li><li>Systemd 主要是一个 init 系统和服务管理器,它包括按需启动守护程序、装载和自动装载点维护、快照支持以及使用 Linux 控制组进行跟踪等功能。</li><li>大多数主要的 Linux 发行版现在都运行 systemd因此在 WSL2 上启用它可使体验更接近于使用裸机 Linux。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 默认情况下,在 WSL2 中,只有 Ubuntu 才会将 systemd 作为 pid-1 的守护进程。</li><li>② 但是,基于 WSL2 为内核的其余 Linux 发行版本并非将 systemd 作为 pid-1 的守护进程。</li><li> 本次以 AlmaLinux9 作为演示!!!</li></ul></div><ul><li>检查进程树,判断 systemd 是否正在运行:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">ps</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -p</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> comm=</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 如果显示 systemd ,则表示 systemd 正在运行</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+bi+`" alt="" loading="lazy"></p><h3 id="_8-7-2-操作步骤" tabindex="-1">8.7.2 操作步骤 <a class="header-anchor" href="#_8-7-2-操作步骤" aria-label="Permalink to &quot;8.7.2 操作步骤&quot;"></a></h3><ul><li>① 查询 WSL2 的版本,确保 WSL2 的版本为 <code>0.67.6</code> 或更高版本:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 如果未满足要求,则使用 wsl --update 更新 WSL2 版本</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> https://github.com/microsoft/WSL2-Linux-Kernel.git</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p><img src="`+ni+'" alt="" loading="lazy"></p><ul><li>编译内核代码:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">cd</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> WSL2-Linux-Kernel</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">make</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -j</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">nproc</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">KCONFIG_CONFIG=Microsoft/config-wsl</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+li+'" alt="" loading="lazy"></p><ul><li>编译 perf 工具:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">cd</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> tools/perf</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">make</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> clean</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &amp;&amp; </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">make</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+ei+'" alt="" loading="lazy"></p><ul><li>复制到 PATH 变量所指向的路径中:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">cp</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> perf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /usr/bin/</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+pi+'" alt="" loading="lazy"></p><h3 id="_8-4-3-整合" tabindex="-1">8.4.3 整合 <a class="header-anchor" href="#_8-4-3-整合" aria-label="Permalink to &quot;8.4.3 整合&quot;"></a></h3><ul><li>CLion 中配置 perf 的路径:</li></ul><p><img src="'+ti+'" alt="" loading="lazy"></p><ul><li>在 CLion 中通过 perf 运行代码:</li></ul><p><img src="'+ri+'" alt="" loading="lazy"></p><h2 id="_8-5-win-中文乱码问题" tabindex="-1">8.5 Win 中文乱码问题 <a class="header-anchor" href="#_8-5-win-中文乱码问题" aria-label="Permalink to &quot;8.5 Win 中文乱码问题&quot;"></a></h2><ul><li>前文,我们提及到,在 Win 中,如果出现<code>中文乱码</code>问题,就需要去<code>语言和区别</code>设置<code>系统区域</code>的编码为 UTF-8 但是这样可能会造成其它的软件出现中文乱码问题Xshell 等。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 之所以,修改系统的编码为 UTF-8 会出现问题,是因为早期的 Win 系统的中文默认编码是 GBK目前也是Win 并没有强制第三方软件使用 UTF-8 编码) ,而 Xshell 等也使用的这些编码,一旦我们修改为 UTF-8 之后,可能会造成这些第三方软件出现中文乱码问题(第三方软件适配问题,相信将来应该都会切换为 UTF-8 编码),体验较差!!!</li><li>② 在 Linux 或 MacOS 之所以不会出现中文乱码的问题,是因为这些系统默认的编码就是 UTF-8 。</li></ul></div><ul><li>其实,还有一种解决方案,如下所示:</li></ul><p><img src="'+ci+'" alt="" loading="lazy"></p><p><img src="'+hi+'" alt="" loading="lazy"></p><p><img src="'+di+'" alt="" loading="lazy"></p><ul><li>测试一下,是否配置成功:</li></ul><p><img src="'+oi+'" alt="" loading="lazy"></p><h2 id="_8-6-clion-中自动导入头文件" tabindex="-1">8.6 CLion 中自动导入头文件 <a class="header-anchor" href="#_8-6-clion-中自动导入头文件" aria-label="Permalink to &quot;8.6 CLion 中自动导入头文件&quot;"></a></h2><ul><li>在 CLion 中,最为强大的功能就是直接输入函数,然后让 IDE 帮我们自动导入头文件,包括自定义的头文件,相当实用。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① CLion 中的<code>自动导入头文件</code>的<code>快捷键</code>是 <code>Alt + Enter</code> 。</li><li>② CLion 中的<code>自动提取变量的类型</code>的<code>快捷键</code>是 <code>Ctrl + Alt + V</code> 。</li></ul></div><p><img src="'+ki+'" alt="" loading="lazy"></p><ul><li>开启自动导入头文件的步骤,如下所示:</li></ul><p><img src="'+ui+'" alt="" loading="lazy"></p><p><img src="'+gi+'" alt="" loading="lazy"></p><h2 id="_8-7-wsl2-启用-systemd" tabindex="-1">8.7 WSL2 启用 systemd <a class="header-anchor" href="#_8-7-wsl2-启用-systemd" aria-label="Permalink to &quot;8.7 WSL2 启用 systemd&quot;"></a></h2><h3 id="_8-7-1-概述" tabindex="-1">8.7.1 概述 <a class="header-anchor" href="#_8-7-1-概述" aria-label="Permalink to &quot;8.7.1 概述&quot;"></a></h3><ul><li>根据 <a href="https://systemd.io/" target="_blank" rel="noreferrer">systemd.io</a>“systemd 是 Linux 系统的基本构建基块套件。 它提供一个系统和服务管理器,该管理器作为 PID 1 运行并启动系统的其余部分。”</li><li>Systemd 主要是一个 init 系统和服务管理器,它包括按需启动守护程序、装载和自动装载点维护、快照支持以及使用 Linux 控制组进行跟踪等功能。</li><li>大多数主要的 Linux 发行版现在都运行 systemd因此在 WSL2 上启用它可使体验更接近于使用裸机 Linux。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 默认情况下,在 WSL2 中,只有 Ubuntu 才会将 systemd 作为 pid-1 的守护进程(微软维护和定制的 Ubuntu 版本,在 GitHub 的 Codespace 中默认的 Linux 环境就是 Ubuntu但是,基于 WSL2 为内核的其余 Linux 发行版本并非将 systemd 作为 pid-1 的守护进程。</li><li> 本次以 AlmaLinux9 作为演示!!!</li></ul></div><ul><li>检查进程树,判断 systemd 是否正在运行:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">ps</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -p</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> comm=</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 如果显示 systemd ,则表示 systemd 正在运行</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+bi+`" alt="" loading="lazy"></p><h3 id="_8-7-2-操作步骤" tabindex="-1">8.7.2 操作步骤 <a class="header-anchor" href="#_8-7-2-操作步骤" aria-label="Permalink to &quot;8.7.2 操作步骤&quot;"></a></h3><ul><li>① 查询 WSL2 的版本,确保 WSL2 的版本为 <code>0.67.6</code> 或更高版本:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 如果未满足要求,则使用 wsl --update 更新 WSL2 版本</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">wsl</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --version</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # win cmd PowerShell </span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p><img src="`+mi+`" alt="" loading="lazy"></p><ul><li> <code>/etc/wsl.conf</code> </li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">cat</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &lt;&lt;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">EOF</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> |</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> tee</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /etc/wsl.conf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">[boot]</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">systemd=true</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">EOF</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p><img src="`+Ci+'" alt="" loading="lazy"></p><ul><li> WSL </li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">wsl</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --shutdown</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # win cmd PowerShell </span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+yi+'" alt="" loading="lazy"></p><ul><li> </li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">ps</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -p</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> comm=</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+Ei+'" alt="" loading="lazy"></p>',592),vi=[_i];function Bi(fi,Ai,Di,xi,qi,wi){return i(),a("div",null,vi)}const zi=s(Fi,[["render",Bi]]);export{Li as __pageData,zi as default};
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">EOF</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p><img src="`+Ci+'" alt="" loading="lazy"></p><ul><li> WSL </li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">wsl</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --shutdown</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # win cmd PowerShell </span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+yi+'" alt="" loading="lazy"></p><ul><li> </li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">ps</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -p</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> comm=</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+Ei+'" alt="" loading="lazy"></p>',592),vi=[_i];function Bi(fi,Ai,Di,xi,qi,wi){return i(),a("div",null,vi)}const zi=s(Fi,[["render",Bi]]);export{Si as __pageData,zi as default};

View File

@ -1 +1 @@
import{_ as s,c as a,o as i,a6 as n}from"./chunks/framework.hMCIpNYY.js";const l="/c/assets/1.D60Zf6_d.png",e="/c/assets/2.D2-G6nV2.png",p="/c/assets/3.DpzkVk5V.png",t="/c/assets/4.BXk95GIP.png",r="/c/assets/5.CbWTB08W.png",c="/c/assets/6.twO9TCIg.png",h="/c/assets/7.CKOjeIvS.png",d="/c/assets/8.DKmR0CxE.png",o="/c/assets/9.Cudf77_s.gif",k="/c/assets/10.BBUUlhRC.png",u="/c/assets/11.iLABkB7O.png",g="/c/assets/12.BQuYWOU9.png",b="/c/assets/13.CslpH6j0.png",m="/c/assets/14.BAyvZdKq.png",C="/c/assets/15.C3oC1iUd.png",y="/c/assets/16.Ds-jsEZn.png",E="/c/assets/17.Cd37gMYs.png",F="/c/assets/18.CAw2z3gc.png",_="/c/assets/19.DdPThnr-.png",v="/c/assets/20.q_rvlDnY.png",B="/c/assets/21.JRHg9RZA.png",f="/c/assets/22.Baq-Hb06.png",A="/c/assets/23.c1ht53mu.png",D="/c/assets/24.CAZmH5Py.png",x="/c/assets/25.DWeCYBe9.png",q="/c/assets/26.2XM8pYni.png",w="/c/assets/27.CN0t-fuo.png",S="/c/assets/28.AcDh3LXQ.png",L="/c/assets/29.CUkDFAc6.png",z="/c/assets/30.picNTNaJ.png",P="/c/assets/31.DKX92RgJ.png",W="/c/assets/32.Bxr7QKI3.png",T="/c/assets/33.DuFWsOgW.png",M="/c/assets/34.Da9qUcfr.png",U="/c/assets/35.7_gEABSX.gif",O="/c/assets/36.C2KQYoVC.gif",I="/c/assets/37.RTUP8Vtx.png",N="/c/assets/38.Dq21DxwL.png",R="/c/assets/39.QmpUaNxU.png",V="/c/assets/40.DP0C29gZ.png",G="/c/assets/41.DwzHokd4.png",X="/c/assets/42.Bi6K26yA.png",$="/c/assets/43.Bw8DcEQ_.png",H="/c/assets/44.DPc8Z9rS.png",K="/c/assets/45.S84xHMTl.png",Q="/c/assets/46.iw3JQUkn.png",J="/c/assets/47.ILeJt-HK.png",Y="/c/assets/48.CHgm7khh.png",j="/c/assets/49.N1nqJaEg.png",Z="/c/assets/50.DHsnibMi.png",ss="/c/assets/51.BQr6Q0uV.png",as="/c/assets/52.BVemi2Lh.png",is="/c/assets/53.BHR69UXx.png",ns="/c/assets/54.CPSU5SJI.png",ls="/c/assets/55.CaQLoDlw.png",es="/c/assets/56.aRGy4XbL.png",ps="/c/assets/57.kNO9fmPR.png",ts="/c/assets/58.D4EkoC4o.png",rs="/c/assets/59.V23Lo9e_.png",cs="/c/assets/60.Du9LVeMB.png",hs="/c/assets/61.DdFg75U9.png",ds="/c/assets/62.C6bz6KtT.png",os="/c/assets/63.CB6LAhB5.png",ks="/c/assets/64.Bip8bkua.png",us="/c/assets/65.DRNHRduW.png",gs="/c/assets/66.Cth4qqEn.png",bs="/c/assets/67.DWGWZ64P.png",ms="/c/assets/68.3hDIDdvx.png",Cs="/c/assets/69.Bw_dQ4ap.png",ys="/c/assets/70.Cn_ubTyA.png",Es="/c/assets/71.C84EBqwB.png",Fs="/c/assets/72.dZfJY4eR.png",_s="/c/assets/73.B0zm0Z79.png",vs="/c/assets/74.CaTcEy1Q.png",Bs="/c/assets/75.iEc8mo9g.png",fs="/c/assets/76.Co2KxM6t.png",As="/c/assets/77.CaUm8Qhc.png",Ds="/c/assets/78.kOkqIKG6.png",xs="/c/assets/79.CyeASH-c.png",qs="/c/assets/80.CFdk60La.png",ws="/c/assets/81.Bhl-0uK_.png",Ss="/c/assets/82.Dni9KbXV.png",Ls="/c/assets/83.BXx10MCV.png",zs="/c/assets/84.CXcIKX1T.png",Ps="/c/assets/85.DptbJqQo.png",Ws="/c/assets/86.CQ3_QCQT.png",Ts="/c/assets/87.CQoDRJM5.gif",Ms="/c/assets/88.CPfwZvD9.gif",Us="/c/assets/89.bxEomEjU.gif",Os="/c/assets/90.C_onhf2k.png",Is="/c/assets/91.Budj3s38.gif",Ns="/c/assets/92.CH8koQdu.gif",Rs="/c/assets/93.kUJhxMtg.png",Vs="/c/assets/94.BJeJJW4_.png",Gs="/c/assets/95.BCuK6eJL.gif",Xs="/c/assets/96.rKC-z4z-.gif",$s="/c/assets/97.BJE3xxuT.gif",Hs="/c/assets/98.DJOq__O0.gif",Ks="/c/assets/99.BDt_0fRR.png",Qs="/c/assets/100.Bo5OawW8.png",Js="/c/assets/101.sUWUfl5e.png",Ys="/c/assets/102.BK4jpnB8.png",js="/c/assets/103.EF8vdbSq.png",Zs="/c/assets/104.DjxdA_Co.png",sa="/c/assets/105.sp68q1hh.gif",aa="/c/assets/106.DhMRyxNN.gif",ia="/c/assets/107.CdcLZM0R.gif",na="/c/assets/108.D-5AsTTr.png",la="/c/assets/109.2RQKmAUa.png",ea="/c/assets/110.CI4xX8SM.png",pa="/c/assets/111.C8QUZ9v3.gif",ta="/c/assets/112.g5tQfhWz.gif",ra="/c/assets/113.CX0_1NsE.gif",ca="/c/assets/114.BrFJeoK6.png",ha="/c/assets/115.58TjSSjH.gif",da="/c/assets/116.DmiFIqcy.svg",oa="/c/assets/117.BasYWvkM.png",ka="/c/assets/118.CjFxJpBr.png",ua="/c/assets/119.Dm5Jspvp.gif",ga="/c/assets/120.1krCh8cy.gif",ba="/c/assets/121.DOSyahv7.gif",ma="/c/assets/122.BHEvX_FI.gif",Ca="/c/assets/123.DFA0g1_d.gif",ya="/c/assets/124.D50nO5eA.gif",Ea="/c/assets/125.cAvG1Qfq.png",Fa="/c/assets/126.DpakQFWz.gif",_a="/c/assets/127.Bg61j9QI.gif",va="/c/assets/128.DPvD9UCw.gif",Ba="/c/assets/129.Ceu65U_n.gif",fa="/c/assets/130.BWPFRK_8.gif",Aa="/c/assets/131.Ct4TfxPf.gif",Da="/c/assets/132.zsKtx_jV.png",xa="/c/assets/133.3oqDAW0w.png",qa="/c/assets/134.D9TSeAa9.gif",wa="/c/assets/135.CCRgYIVq.png",Sa="/c/assets/136.C1t2T6FV.gif",La="/c/assets/137.Rqa4uHq6.png",za="/c/assets/138.6yQYnjOa.gif",Pa="/c/assets/139.hYR9GiiD.gif",Wa="/c/assets/140.D3b-QIrA.gif",Ta="/c/assets/141.DGbA6qsW.gif",Ma="/c/assets/142.BToOkxf2.gif",Ua="/c/assets/143.C3wekjfY.png",Oa="/c/assets/144.CKuuzuQ_.png",Ia="/c/assets/145.B4r6Nv14.gif",Na="/c/assets/146.CvbhuZNK.png",Ra="/c/assets/147.BPgYm4ZX.gif",Va="/c/assets/148.DH2fri13.gif",Ga="/c/assets/149.CDDIqy03.gif",Xa="/c/assets/150.DCQsqYYC.gif",$a="/c/assets/151.CUjMoXNF.gif",Ha="/c/assets/152.BWbajkuB.gif",Ka="/c/assets/153.C1JnBDr7.png",Qa="/c/assets/154.DwN2p3bo.png",Ja="/c/assets/155.DdSfz-Pf.gif",Ya="/c/assets/156.BMocjVt7.gif",ja="/c/assets/157.BUU-wlaw.gif",Za="/c/assets/158.ssadIF0D.gif",si="/c/assets/159.Dq5lLq9v.gif",ai="/c/assets/160.CJ0_loZ8.gif",ii="/c/assets/161.BPOK9irZ.gif",ni="/c/assets/162.B1eB55rC.gif",li="/c/assets/163.VIcU-hkN.gif",ei="/c/assets/164.BM9viRZJ.gif",pi="/c/assets/165.DpMBA1SK.gif",ti="/c/assets/166.DgXuU6LF.png",ri="/c/assets/167.Dnw73s2h.gif",ci="/c/assets/168.SnFXRSaL.png",hi="/c/assets/169.DnoEqOjV.png",di="/c/assets/170.BJBdn7pw.png",oi="/c/assets/171.DXtQWYsM.gif",ki="/c/assets/172.hcERTQkN.gif",ui="/c/assets/173.CioraEUv.png",gi="/c/assets/174.kWHWwnc_.png",bi="/c/assets/175.DhVZ6aP-.gif",mi="/c/assets/176.CUl5g8VJ.png",Ci="/c/assets/177.FJeffiE3.gif",yi="/c/assets/178.Bee0LcNX.gif",Ei="/c/assets/179.BDqd1eDo.png",Li=JSON.parse('{"title":"第一章:开发环境的安装和配置(⭐)","description":"","frontmatter":{},"headers":[],"relativePath":"notes/01_c-basic/01_xdx/index.md","filePath":"notes/01_c-basic/01_xdx/index.md","lastUpdated":1724660795000}'),Fi={name:"notes/01_c-basic/01_xdx/index.md"},_i=n("",592),vi=[_i];function Bi(fi,Ai,Di,xi,qi,wi){return i(),a("div",null,vi)}const zi=s(Fi,[["render",Bi]]);export{Li as __pageData,zi as default};
import{_ as s,c as a,o as i,a6 as n}from"./chunks/framework.hMCIpNYY.js";const l="/c/assets/1.D60Zf6_d.png",e="/c/assets/2.D2-G6nV2.png",p="/c/assets/3.DpzkVk5V.png",t="/c/assets/4.BXk95GIP.png",r="/c/assets/5.CbWTB08W.png",c="/c/assets/6.twO9TCIg.png",h="/c/assets/7.CKOjeIvS.png",d="/c/assets/8.DKmR0CxE.png",o="/c/assets/9.Cudf77_s.gif",k="/c/assets/10.BBUUlhRC.png",u="/c/assets/11.iLABkB7O.png",g="/c/assets/12.BQuYWOU9.png",b="/c/assets/13.CslpH6j0.png",m="/c/assets/14.BAyvZdKq.png",C="/c/assets/15.C3oC1iUd.png",y="/c/assets/16.Ds-jsEZn.png",E="/c/assets/17.Cd37gMYs.png",F="/c/assets/18.CAw2z3gc.png",_="/c/assets/19.DdPThnr-.png",v="/c/assets/20.q_rvlDnY.png",B="/c/assets/21.JRHg9RZA.png",f="/c/assets/22.Baq-Hb06.png",A="/c/assets/23.c1ht53mu.png",D="/c/assets/24.CAZmH5Py.png",x="/c/assets/25.DWeCYBe9.png",q="/c/assets/26.2XM8pYni.png",w="/c/assets/27.CN0t-fuo.png",L="/c/assets/28.AcDh3LXQ.png",S="/c/assets/29.CUkDFAc6.png",z="/c/assets/30.picNTNaJ.png",P="/c/assets/31.DKX92RgJ.png",W="/c/assets/32.Bxr7QKI3.png",T="/c/assets/33.DuFWsOgW.png",M="/c/assets/34.Da9qUcfr.png",U="/c/assets/35.7_gEABSX.gif",O="/c/assets/36.C2KQYoVC.gif",I="/c/assets/37.RTUP8Vtx.png",N="/c/assets/38.Dq21DxwL.png",R="/c/assets/39.QmpUaNxU.png",V="/c/assets/40.DP0C29gZ.png",G="/c/assets/41.DwzHokd4.png",X="/c/assets/42.Bi6K26yA.png",$="/c/assets/43.Bw8DcEQ_.png",H="/c/assets/44.DPc8Z9rS.png",K="/c/assets/45.S84xHMTl.png",Q="/c/assets/46.iw3JQUkn.png",J="/c/assets/47.ILeJt-HK.png",Y="/c/assets/48.CHgm7khh.png",j="/c/assets/49.N1nqJaEg.png",Z="/c/assets/50.DHsnibMi.png",ss="/c/assets/51.BQr6Q0uV.png",as="/c/assets/52.BVemi2Lh.png",is="/c/assets/53.BHR69UXx.png",ns="/c/assets/54.CPSU5SJI.png",ls="/c/assets/55.CaQLoDlw.png",es="/c/assets/56.aRGy4XbL.png",ps="/c/assets/57.kNO9fmPR.png",ts="/c/assets/58.D4EkoC4o.png",rs="/c/assets/59.V23Lo9e_.png",cs="/c/assets/60.Du9LVeMB.png",hs="/c/assets/61.DdFg75U9.png",ds="/c/assets/62.C6bz6KtT.png",os="/c/assets/63.CB6LAhB5.png",ks="/c/assets/64.Bip8bkua.png",us="/c/assets/65.DRNHRduW.png",gs="/c/assets/66.Cth4qqEn.png",bs="/c/assets/67.DWGWZ64P.png",ms="/c/assets/68.3hDIDdvx.png",Cs="/c/assets/69.Bw_dQ4ap.png",ys="/c/assets/70.Cn_ubTyA.png",Es="/c/assets/71.C84EBqwB.png",Fs="/c/assets/72.dZfJY4eR.png",_s="/c/assets/73.B0zm0Z79.png",vs="/c/assets/74.CaTcEy1Q.png",Bs="/c/assets/75.iEc8mo9g.png",fs="/c/assets/76.Co2KxM6t.png",As="/c/assets/77.CaUm8Qhc.png",Ds="/c/assets/78.kOkqIKG6.png",xs="/c/assets/79.CyeASH-c.png",qs="/c/assets/80.CFdk60La.png",ws="/c/assets/81.Bhl-0uK_.png",Ls="/c/assets/82.Dni9KbXV.png",Ss="/c/assets/83.BXx10MCV.png",zs="/c/assets/84.CXcIKX1T.png",Ps="/c/assets/85.DptbJqQo.png",Ws="/c/assets/86.CQ3_QCQT.png",Ts="/c/assets/87.CQoDRJM5.gif",Ms="/c/assets/88.CPfwZvD9.gif",Us="/c/assets/89.bxEomEjU.gif",Os="/c/assets/90.C_onhf2k.png",Is="/c/assets/91.Budj3s38.gif",Ns="/c/assets/92.CH8koQdu.gif",Rs="/c/assets/93.kUJhxMtg.png",Vs="/c/assets/94.BJeJJW4_.png",Gs="/c/assets/95.BCuK6eJL.gif",Xs="/c/assets/96.rKC-z4z-.gif",$s="/c/assets/97.BJE3xxuT.gif",Hs="/c/assets/98.DJOq__O0.gif",Ks="/c/assets/99.BDt_0fRR.png",Qs="/c/assets/100.Bo5OawW8.png",Js="/c/assets/101.sUWUfl5e.png",Ys="/c/assets/102.BK4jpnB8.png",js="/c/assets/103.EF8vdbSq.png",Zs="/c/assets/104.DjxdA_Co.png",sa="/c/assets/105.sp68q1hh.gif",aa="/c/assets/106.DhMRyxNN.gif",ia="/c/assets/107.CdcLZM0R.gif",na="/c/assets/108.D-5AsTTr.png",la="/c/assets/109.2RQKmAUa.png",ea="/c/assets/110.CI4xX8SM.png",pa="/c/assets/111.C8QUZ9v3.gif",ta="/c/assets/112.g5tQfhWz.gif",ra="/c/assets/113.CX0_1NsE.gif",ca="/c/assets/114.BrFJeoK6.png",ha="/c/assets/115.58TjSSjH.gif",da="/c/assets/116.DmiFIqcy.svg",oa="/c/assets/117.BasYWvkM.png",ka="/c/assets/118.CjFxJpBr.png",ua="/c/assets/119.Dm5Jspvp.gif",ga="/c/assets/120.1krCh8cy.gif",ba="/c/assets/121.DOSyahv7.gif",ma="/c/assets/122.BHEvX_FI.gif",Ca="/c/assets/123.DFA0g1_d.gif",ya="/c/assets/124.D50nO5eA.gif",Ea="/c/assets/125.cAvG1Qfq.png",Fa="/c/assets/126.DpakQFWz.gif",_a="/c/assets/127.Bg61j9QI.gif",va="/c/assets/128.DPvD9UCw.gif",Ba="/c/assets/129.Ceu65U_n.gif",fa="/c/assets/130.BWPFRK_8.gif",Aa="/c/assets/131.Ct4TfxPf.gif",Da="/c/assets/132.zsKtx_jV.png",xa="/c/assets/133.3oqDAW0w.png",qa="/c/assets/134.D9TSeAa9.gif",wa="/c/assets/135.CCRgYIVq.png",La="/c/assets/136.C1t2T6FV.gif",Sa="/c/assets/137.Rqa4uHq6.png",za="/c/assets/138.6yQYnjOa.gif",Pa="/c/assets/139.hYR9GiiD.gif",Wa="/c/assets/140.D3b-QIrA.gif",Ta="/c/assets/141.DGbA6qsW.gif",Ma="/c/assets/142.BToOkxf2.gif",Ua="/c/assets/143.C3wekjfY.png",Oa="/c/assets/144.CKuuzuQ_.png",Ia="/c/assets/145.B4r6Nv14.gif",Na="/c/assets/146.CvbhuZNK.png",Ra="/c/assets/147.BPgYm4ZX.gif",Va="/c/assets/148.DH2fri13.gif",Ga="/c/assets/149.CDDIqy03.gif",Xa="/c/assets/150.DCQsqYYC.gif",$a="/c/assets/151.CUjMoXNF.gif",Ha="/c/assets/152.BWbajkuB.gif",Ka="/c/assets/153.C1JnBDr7.png",Qa="/c/assets/154.DwN2p3bo.png",Ja="/c/assets/155.DdSfz-Pf.gif",Ya="/c/assets/156.BMocjVt7.gif",ja="/c/assets/157.BUU-wlaw.gif",Za="/c/assets/158.ssadIF0D.gif",si="/c/assets/159.Dq5lLq9v.gif",ai="/c/assets/160.CJ0_loZ8.gif",ii="/c/assets/161.BPOK9irZ.gif",ni="/c/assets/162.B1eB55rC.gif",li="/c/assets/163.VIcU-hkN.gif",ei="/c/assets/164.BM9viRZJ.gif",pi="/c/assets/165.DpMBA1SK.gif",ti="/c/assets/166.DgXuU6LF.png",ri="/c/assets/167.Dnw73s2h.gif",ci="/c/assets/168.SnFXRSaL.png",hi="/c/assets/169.DnoEqOjV.png",di="/c/assets/170.BJBdn7pw.png",oi="/c/assets/171.DXtQWYsM.gif",ki="/c/assets/172.hcERTQkN.gif",ui="/c/assets/173.CioraEUv.png",gi="/c/assets/174.kWHWwnc_.png",bi="/c/assets/175.DhVZ6aP-.gif",mi="/c/assets/176.CUl5g8VJ.png",Ci="/c/assets/177.FJeffiE3.gif",yi="/c/assets/178.Bee0LcNX.gif",Ei="/c/assets/179.BDqd1eDo.png",Si=JSON.parse('{"title":"第一章:开发环境的安装和配置(⭐)","description":"","frontmatter":{},"headers":[],"relativePath":"notes/01_c-basic/01_xdx/index.md","filePath":"notes/01_c-basic/01_xdx/index.md","lastUpdated":1724728274000}'),Fi={name:"notes/01_c-basic/01_xdx/index.md"},_i=n("",592),vi=[_i];function Bi(fi,Ai,Di,xi,qi,wi){return i(),a("div",null,vi)}const zi=s(Fi,[["render",Bi]]);export{Si as __pageData,zi as default};

View File

@ -1,4 +1,4 @@
import{_ as p,c as n,j as s,a as i,a6 as a,o as l}from"./chunks/framework.hMCIpNYY.js";const t="/c/assets/1.L8V3GBrc.png",h="/c/assets/2.nqdAY_P3.png",e="/c/assets/3.D7eNbwzQ.jpg",k="/c/assets/4.DElD8M7P.svg",d="/c/assets/5.BE2mwvAQ.svg",r="/c/assets/6.aMDLQtj3.svg",c="/c/assets/7.eAeDlr0I.svg",E="/c/assets/8.CiYoL9Pa.svg",g="/c/assets/9.f3_OgcWU.svg",o="/c/assets/10.Dx5GM3xz.svg",F="/c/assets/11.DNH2vSdC.svg",y="/c/assets/12.NlBmD7pA.png",u="/c/assets/13.ZiBq6Pno.png",b="/c/assets/14.DAgmsf-w.png",m="/c/assets/15.B2iC37fw.png",C="/c/assets/16.BlE3ZFud.png",B="/c/assets/17.CBpay1zM.svg",A="/c/assets/18.g66usGgc.svg",D="/c/assets/19.BW4hoq9o.svg",v="/c/assets/20.DBXyt0gx.svg",T="/c/assets/21.QOjKI_7K.svg",Q="/c/assets/22.BPFvANo_.svg",f="/c/assets/23.BSJo8a0j.svg",q="/c/assets/24.r8ZG8Rvh.svg",_="/c/assets/25.rY0SPMAM.svg",x="/c/assets/26.CX-aIacs.svg",w="/c/assets/27.B6oI9aDx.svg",L="/c/assets/28.BK--PMbQ.svg",z="/c/assets/29.CJ87msb8.svg",H="/c/assets/30.CjsU-QJv.svg",P="/c/assets/31.s4BF2CMv.svg",M="/c/assets/32.DCGI6iJG.svg",N="/c/assets/33.C1jQxCuu.svg",I="/c/assets/35.CGTVELeO.png",V="/c/assets/36.Bz4_lEH0.gif",S="/c/assets/37.CcDWE4nn.png",U="/c/assets/38.B7y2_JVX.gif",O="/c/assets/39.Btcc3rs2.gif",Z="/c/assets/40.CR4ARW8y.png",R="/c/assets/39.Btcc3rs2.gif",G="/c/assets/42.DOX3ymYP.gif",j="/c/assets/43.Cie9_tkP.gif",J="/c/assets/44.DLjH9Ges.png",X="/c/assets/45.DhSh546m.gif",W="/c/assets/46.CCFwxiA0.gif",K="/c/assets/47.DCdP5ufU.gif",$="/c/assets/48.CjdgNuy4.gif",Y="/c/assets/49.Bg9sWT0a.gif",ss="/c/assets/50.Ma73wRvf.gif",is="/c/assets/51.rJLsU7Sw.gif",as="/c/assets/52.3DsEIiSv.gif",vs=JSON.parse('{"title":"第一章:数据类型(⭐)","description":"","frontmatter":{},"headers":[],"relativePath":"notes/01_c-basic/03_xdx/index.md","filePath":"notes/01_c-basic/03_xdx/index.md","lastUpdated":1724661257000}'),ns={name:"notes/01_c-basic/03_xdx/index.md"},ls=a('<h1 id="第一章-数据类型-⭐" tabindex="-1">第一章:数据类型(⭐) <a class="header-anchor" href="#第一章-数据类型-⭐" aria-label="Permalink to &quot;第一章:数据类型(⭐)&quot;"></a></h1><h2 id="_1-1-概述" tabindex="-1">1.1 概述 <a class="header-anchor" href="#_1-1-概述" aria-label="Permalink to &quot;1.1 概述&quot;"></a></h2><ul><li><p>根据<code>变量</code>中<code>存储</code>的<code>值</code>的<code>不同</code>,我们可以将<code>变量</code>分为两类:</p><ul><li><code>普通变量</code>:变量所对应的内存中存储的是<code>普通值</code>。</li><li><code>指针变量</code>:变量所对应的内存中存储的是<code>另一个变量的地址</code>。</li></ul></li><li><p>如下图所示:</p></li></ul><p><img src="'+t+'" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>普通变量和指针变量的相同点:</p><ul><li>普通变量有内存空间,指针变量也有内存空间。</li><li>普通变量有内存地址,指针变量也有内存地址。</li><li>普通变量所对应的内存空间中有值,指针变量所对应的内存空间中也有值。</li></ul><p>普通变量和指针变量的不同点:</p><ul><li>普通变量所对应的内存空间存储的是普通的值,如:整数、小数、字符等;指针变量所对应的内存空间存储的是另外一个变量的地址。</li><li>普通变量有普通变量的运算方式,而指针变量有指针变量的运算方式(后续讲解)。</li></ul></div><ul><li>那么,在 C 语言中变量的数据类型就可以这么划分,如下所示:</li></ul><p><img src="'+h+`" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>根据<code>普通变量</code>中<code>存储</code>的<code>值</code>的类型不同,可以将<code>普通变量类型</code>划分为<code>基本数据类型</code>(整型、字符类型、浮点类型、布尔类型)和<code>复合数据类型</code>(数组类型、结构体类型、共用体类型、枚举类型)。</li><li>根据<code>指针变量</code>所<code>指向空间</code>中<code>存储</code>的<code>值</code>的类型不同,可以将<code>指针类型</code>分为<code>基本数据类型指针</code>、<code>复合数据类型指针</code>、<code>函数指针</code>、<code>数组指针</code>等,例如:如果指针所指向的空间保存的是 int 类型,那么该指针就是 int 类型的指针。</li></ul></div><h2 id="_1-2-整数类型" tabindex="-1">1.2 整数类型 <a class="header-anchor" href="#_1-2-整数类型" aria-label="Permalink to &quot;1.2 整数类型&quot;"></a></h2><h3 id="_1-2-1-概述" tabindex="-1">1.2.1 概述 <a class="header-anchor" href="#_1-2-1-概述" aria-label="Permalink to &quot;1.2.1 概述&quot;"></a></h3><ul><li>整数类型简称整型用于存储整数值12、20、50 等。</li><li>根据所占<code>内存空间</code>大小的不同,可以将整数类型划分为:</li><li>① 短整型:</li></ul><table tabindex="0"><thead><tr><th>类型</th><th>存储空间(内存空间)</th><th>取值范围</th></tr></thead><tbody><tr><td>unsigned short (无符号短整型)</td><td>2 字节</td><td>0 ~ 65,535 (2^16 - 1)</td></tr><tr><td>[signed] short有符号短整型默认</td><td>2 字节</td><td>-32,768 (- 2^15) ~ 32,767 (2^15 -1)</td></tr></tbody></table><ul><li>② 整型:</li></ul><table tabindex="0"><thead><tr><th>类型</th><th>存储空间(内存空间)</th><th>取值范围</th></tr></thead><tbody><tr><td>unsigned int无符号整型</td><td>4 字节(通常)</td><td>0 ~ 4294967295 (0 ~2^32 -1)</td></tr><tr><td>[signed] int有符号整型默认</td><td>4 字节(通常)</td><td>-2147483648- 2^31 ~ 2147483647 (2^31-1)</td></tr></tbody></table><ul><li>③ 长整型:</li></ul><table tabindex="0"><thead><tr><th>类型</th><th>存储空间(内存空间)</th><th>取值范围</th></tr></thead><tbody><tr><td>unsigned long无符号长整型</td><td>4 字节(通常)</td><td>0 ~2^32 -1</td></tr><tr><td>[signed] long有符号长整型默认</td><td>4 字节(通常)</td><td>- 2^31 ~ 2^31-1</td></tr></tbody></table><ul><li>④ 长长整型:</li></ul><table tabindex="0"><thead><tr><th>类型</th><th>存储空间(内存空间)</th><th>取值范围</th></tr></thead><tbody><tr><td>unsigned long long无符号长整型</td><td>8 字节(通常)</td><td>0 ~2^64 -1</td></tr><tr><td>[signed] long long有符号长整型默认</td><td>8 字节(通常)</td><td>- 2^63 ~ 2^63-1</td></tr></tbody></table><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li><p>① 数据类型在内存中占用的存储单元字节数就称为该数据类型的长度步长short 占用 2 个字节的内存,就称 short 的长度(步长)是 2。</p></li><li><p>② C 语言并没有严格规定各种整数数据类型在内存中所占存储单元的长度,只做了宽泛的限制:</p><ul><li>short 至少占用 2 个字节的存储单元。</li><li>int 建议为一个机器字长(指计算机的处理器在一次操作中能够处理的二进制数据的位数,机器字长是处理器的“字”长度,它决定了处理器在一个时钟周期内能够处理的数据量,如:早期的计算机的处理器通常是 8 位的机器字长,意味着处理器一次只能处理 8 位(二进制)数据;之后的计算机的处理器有 16 位的机器字长,意味着处理器一次可以处理 16 位的数据;再之后计算机的处理器有 32 位或 64 位的机器字长,意味着处理器一次可以处理 32 位或 64位的数据。即32 位环境下 int 占用 4 个字节的存储单元64 位环境下 int 占用 8 个字节的存储单元。</li><li>short 的长度(步长)不能大于 intlong 的长度(步长)不能小于 intlong long 不能小于 long。</li></ul></li><li><p>③ 那么,各种整数数据类型在内存中所占存储单元的长度的公式就是 <code>2 ≤ sizeof(short) ≤ sizeof(int) ≤ sizeof(long) ≤ sizeof(long long)</code>,具体的存储空间由编译系统自行决定。其中,<code>sizeof</code> 是测量类型或变量、常量长度的<code>运算符</code>。</p></li></ul></div><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li>① 之所以这么规定,是为了可以让 C 语言长久使用,因为目前主流的 CPU 都是 64 位,但是在 C 语言刚刚出现的时候CPU 还是以 8 位和 16 位为主。如果当时就将整型定死为 8 位或 16 位,那么现在我们肯定不会再学习 C 语言了。</li><li>② 整型分为有符号 signed 和无符号 unsigned 两种,默认是 signed。</li><li>③ 在实际开发中,<code>最常用的整数类型</code>就是 <code>int</code> 类型了,如果取值范围不够,就使用 long 或 long long 。</li><li>④ C 语言中的<code>格式占位符</code>非常多,只需要大致了解即可;因为,我们在实际开发中,一般都会使用 C++ 或 Rust 以及其它的高级编程语言Java 等,早已经解决了必须通过<code>格式占位符</code>来才能将变量进行输入和输出。</li></ul></div><h3 id="_1-2-2-短整型-了解" tabindex="-1">1.2.2 短整型(了解) <a class="header-anchor" href="#_1-2-2-短整型-了解" aria-label="Permalink to &quot;1.2.2 短整型(了解)&quot;"></a></h3><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">unsigned</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> short</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> x </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 无符号短整型</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">short</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> x </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> -</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 有符号短整型</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 有符号表示的是正数、负数和 0 ,即有正负号。无符号表示的是 0 和正数,即正整数,没有符号。</li><li>② 在 <code>printf</code> 中<code>无符号短整型unsigned short</code>的<code>格式占位符</code>是 <code>%hu</code> <code>有符号短整型signed short</code>的<code>格式占位符</code>是 <code>%hd</code> 。</li><li>③ 可以通过 <code>sizeof</code> 运算符获取<code>无符号短整型unsigned short</code> 和 <code>有符号短整型signed short</code> 的<code>存储空间(所占内存空间)</code>。</li><li>③ 可以通过 <code>#include &lt;limits.h&gt;</code> 来获取 <code>无符号短整型unsigned short</code> 和<code>有符号短整型signed short</code>的<code>取值范围</code>。</li></ul></div><ul><li>示例:定义和打印短整型变量</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
import{_ as p,c as n,j as s,a as i,a6 as a,o as l}from"./chunks/framework.hMCIpNYY.js";const t="/c/assets/1.L8V3GBrc.png",h="/c/assets/2.nqdAY_P3.png",e="/c/assets/3.D7eNbwzQ.jpg",k="/c/assets/4.DElD8M7P.svg",d="/c/assets/5.BE2mwvAQ.svg",r="/c/assets/6.aMDLQtj3.svg",c="/c/assets/7.eAeDlr0I.svg",E="/c/assets/8.CiYoL9Pa.svg",g="/c/assets/9.f3_OgcWU.svg",o="/c/assets/10.Dx5GM3xz.svg",F="/c/assets/11.DNH2vSdC.svg",y="/c/assets/12.NlBmD7pA.png",u="/c/assets/13.ZiBq6Pno.png",b="/c/assets/14.DAgmsf-w.png",m="/c/assets/15.B2iC37fw.png",C="/c/assets/16.BlE3ZFud.png",A="/c/assets/17.CBpay1zM.svg",B="/c/assets/18.g66usGgc.svg",D="/c/assets/19.BW4hoq9o.svg",v="/c/assets/20.DBXyt0gx.svg",T="/c/assets/21.QOjKI_7K.svg",Q="/c/assets/22.BPFvANo_.svg",q="/c/assets/23.BSJo8a0j.svg",f="/c/assets/24.r8ZG8Rvh.svg",_="/c/assets/25.rY0SPMAM.svg",x="/c/assets/26.CX-aIacs.svg",w="/c/assets/27.B6oI9aDx.svg",L="/c/assets/28.BK--PMbQ.svg",z="/c/assets/29.CJ87msb8.svg",H="/c/assets/30.CjsU-QJv.svg",I="/c/assets/31.s4BF2CMv.svg",U="/c/assets/32.DCGI6iJG.svg",P="/c/assets/33.C1jQxCuu.svg",N="/c/assets/35.CGTVELeO.png",M="/c/assets/36.Bz4_lEH0.gif",S="/c/assets/37.CcDWE4nn.png",V="/c/assets/38.B7y2_JVX.gif",O="/c/assets/39.Btcc3rs2.gif",Z="/c/assets/40.CR4ARW8y.png",R="/c/assets/39.Btcc3rs2.gif",G="/c/assets/42.DOX3ymYP.gif",j="/c/assets/43.Cie9_tkP.gif",J="/c/assets/44.DLjH9Ges.png",X="/c/assets/45.DhSh546m.gif",W="/c/assets/46.CCFwxiA0.gif",K="/c/assets/47.DCdP5ufU.gif",$="/c/assets/48.CjdgNuy4.gif",Y="/c/assets/49.Bg9sWT0a.gif",ss="/c/assets/50.Ma73wRvf.gif",is="/c/assets/51.rJLsU7Sw.gif",as="/c/assets/52.3DsEIiSv.gif",vs=JSON.parse('{"title":"第一章:数据类型(⭐)","description":"","frontmatter":{},"headers":[],"relativePath":"notes/01_c-basic/03_xdx/index.md","filePath":"notes/01_c-basic/03_xdx/index.md","lastUpdated":1724728274000}'),ns={name:"notes/01_c-basic/03_xdx/index.md"},ls=a('<h1 id="第一章-数据类型-⭐" tabindex="-1">第一章:数据类型(⭐) <a class="header-anchor" href="#第一章-数据类型-⭐" aria-label="Permalink to &quot;第一章:数据类型(⭐)&quot;"></a></h1><h2 id="_1-1-概述" tabindex="-1">1.1 概述 <a class="header-anchor" href="#_1-1-概述" aria-label="Permalink to &quot;1.1 概述&quot;"></a></h2><ul><li><p>根据<code>变量</code>中<code>存储</code>的<code>值</code>的<code>不同</code>,我们可以将<code>变量</code>分为两类:</p><ul><li><code>普通变量</code>:变量所对应的内存中存储的是<code>普通值</code>。</li><li><code>指针变量</code>:变量所对应的内存中存储的是<code>另一个变量的地址</code>。</li></ul></li><li><p>如下图所示:</p></li></ul><p><img src="'+t+'" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>普通变量和指针变量的相同点:</p><ul><li>普通变量有内存空间,指针变量也有内存空间。</li><li>普通变量有内存地址,指针变量也有内存地址。</li><li>普通变量所对应的内存空间中有值,指针变量所对应的内存空间中也有值。</li></ul><p>普通变量和指针变量的不同点:</p><ul><li>普通变量所对应的内存空间存储的是普通的值,如:整数、小数、字符等;指针变量所对应的内存空间存储的是另外一个变量的地址。</li><li>普通变量有普通变量的运算方式,而指针变量有指针变量的运算方式(后续讲解)。</li></ul></div><ul><li>那么,在 C 语言中变量的数据类型就可以这么划分,如下所示:</li></ul><p><img src="'+h+`" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>根据<code>普通变量</code>中<code>存储</code>的<code>值</code>的类型不同,可以将<code>普通变量类型</code>划分为<code>基本数据类型</code>(整型、字符类型、浮点类型、布尔类型)和<code>复合数据类型</code>(数组类型、结构体类型、共用体类型、枚举类型)。</li><li>根据<code>指针变量</code>所<code>指向空间</code>中<code>存储</code>的<code>值</code>的类型不同,可以将<code>指针类型</code>分为<code>基本数据类型指针</code>、<code>复合数据类型指针</code>、<code>函数指针</code>、<code>数组指针</code>等,例如:如果指针所指向的空间保存的是 int 类型,那么该指针就是 int 类型的指针。</li></ul></div><h2 id="_1-2-整数类型" tabindex="-1">1.2 整数类型 <a class="header-anchor" href="#_1-2-整数类型" aria-label="Permalink to &quot;1.2 整数类型&quot;"></a></h2><h3 id="_1-2-1-概述" tabindex="-1">1.2.1 概述 <a class="header-anchor" href="#_1-2-1-概述" aria-label="Permalink to &quot;1.2.1 概述&quot;"></a></h3><ul><li>整数类型简称整型用于存储整数值12、20、50 等。</li><li>根据所占<code>内存空间</code>大小的不同,可以将整数类型划分为:</li><li>① 短整型:</li></ul><table tabindex="0"><thead><tr><th>类型</th><th>存储空间(内存空间)</th><th>取值范围</th></tr></thead><tbody><tr><td>unsigned short (无符号短整型)</td><td>2 字节</td><td>0 ~ 65,535 (2^16 - 1)</td></tr><tr><td>[signed] short有符号短整型默认</td><td>2 字节</td><td>-32,768 (- 2^15) ~ 32,767 (2^15 -1)</td></tr></tbody></table><ul><li>② 整型:</li></ul><table tabindex="0"><thead><tr><th>类型</th><th>存储空间(内存空间)</th><th>取值范围</th></tr></thead><tbody><tr><td>unsigned int无符号整型</td><td>4 字节(通常)</td><td>0 ~ 4294967295 (0 ~2^32 -1)</td></tr><tr><td>[signed] int有符号整型默认</td><td>4 字节(通常)</td><td>-2147483648- 2^31 ~ 2147483647 (2^31-1)</td></tr></tbody></table><ul><li>③ 长整型:</li></ul><table tabindex="0"><thead><tr><th>类型</th><th>存储空间(内存空间)</th><th>取值范围</th></tr></thead><tbody><tr><td>unsigned long无符号长整型</td><td>4 字节(通常)</td><td>0 ~2^32 -1</td></tr><tr><td>[signed] long有符号长整型默认</td><td>4 字节(通常)</td><td>- 2^31 ~ 2^31-1</td></tr></tbody></table><ul><li>④ 长长整型:</li></ul><table tabindex="0"><thead><tr><th>类型</th><th>存储空间(内存空间)</th><th>取值范围</th></tr></thead><tbody><tr><td>unsigned long long无符号长整型</td><td>8 字节(通常)</td><td>0 ~2^64 -1</td></tr><tr><td>[signed] long long有符号长整型默认</td><td>8 字节(通常)</td><td>- 2^63 ~ 2^63-1</td></tr></tbody></table><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li><p>① 数据类型在内存中占用的存储单元字节数就称为该数据类型的长度步长short 占用 2 个字节的内存,就称 short 的长度(步长)是 2。</p></li><li><p>② C 语言并没有严格规定各种整数数据类型在内存中所占存储单元的长度,只做了宽泛的限制:</p><ul><li>short 至少占用 2 个字节的存储单元。</li><li>int 建议为一个机器字长(指计算机的处理器在一次操作中能够处理的二进制数据的位数,机器字长是处理器的“字”长度,它决定了处理器在一个时钟周期内能够处理的数据量,如:早期的计算机的处理器通常是 8 位的机器字长,意味着处理器一次只能处理 8 位(二进制)数据;之后的计算机的处理器有 16 位的机器字长,意味着处理器一次可以处理 16 位的数据;再之后计算机的处理器有 32 位或 64 位的机器字长,意味着处理器一次可以处理 32 位或 64位的数据。即32 位环境下 int 占用 4 个字节的存储单元64 位环境下 int 占用 8 个字节的存储单元。</li><li>short 的长度(步长)不能大于 intlong 的长度(步长)不能小于 intlong long 不能小于 long。</li></ul></li><li><p>③ 那么,各种整数数据类型在内存中所占存储单元的长度的公式就是 <code>2 ≤ sizeof(short) ≤ sizeof(int) ≤ sizeof(long) ≤ sizeof(long long)</code>,具体的存储空间由编译系统自行决定。其中,<code>sizeof</code> 是测量类型或变量、常量长度的<code>运算符</code>。</p></li></ul></div><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li>① 之所以这么规定,是为了可以让 C 语言长久使用,因为目前主流的 CPU 都是 64 位,但是在 C 语言刚刚出现的时候CPU 还是以 8 位和 16 位为主。如果当时就将整型定死为 8 位或 16 位,那么现在我们肯定不会再学习 C 语言了。</li><li>② 整型分为有符号 signed 和无符号 unsigned 两种,默认是 signed。</li><li>③ 在实际开发中,<code>最常用的整数类型</code>就是 <code>int</code> 类型了,如果取值范围不够,就使用 long 或 long long 。</li><li>④ C 语言中的<code>格式占位符</code>非常多,只需要大致了解即可;因为,我们在实际开发中,一般都会使用 C++ 或 Rust 以及其它的高级编程语言Java 等,早已经解决了必须通过<code>格式占位符</code>来才能将变量进行输入和输出。</li></ul></div><h3 id="_1-2-2-短整型-了解" tabindex="-1">1.2.2 短整型(了解) <a class="header-anchor" href="#_1-2-2-短整型-了解" aria-label="Permalink to &quot;1.2.2 短整型(了解)&quot;"></a></h3><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">unsigned</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> short</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> x </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 无符号短整型</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">short</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> x </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> -</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 有符号短整型</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 有符号表示的是正数、负数和 0 ,即有正负号。无符号表示的是 0 和正数,即正整数,没有符号。</li><li>② 在 <code>printf</code> 中<code>无符号短整型unsigned short</code>的<code>格式占位符</code>是 <code>%hu</code> <code>有符号短整型signed short</code>的<code>格式占位符</code>是 <code>%hd</code> 。</li><li>③ 可以通过 <code>sizeof</code> 运算符获取<code>无符号短整型unsigned short</code> 和 <code>有符号短整型signed short</code> 的<code>存储空间(所占内存空间)</code>。</li><li>③ 可以通过 <code>#include &lt;limits.h&gt;</code> 来获取 <code>无符号短整型unsigned short</code> 和<code>有符号短整型signed short</code>的<code>取值范围</code>。</li></ul></div><ul><li>示例:定义和打印短整型变量</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
@ -345,7 +345,7 @@ import{_ as p,c as n,j as s,a as i,a6 as a,o as l}from"./chunks/framework.hMCIpN
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> b </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 123.00</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // </span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;b=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, b);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // b=123</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><h2 id="_1-5-" tabindex="-1">1.5 <a class="header-anchor" href="#_1-5-" aria-label="Permalink to &quot;1.5 &quot;"></a></h2><h3 id="_1-5-1-" tabindex="-1">1.5.1 <a class="header-anchor" href="#_1-5-1-" aria-label="Permalink to &quot;1.5.1 &quot;"></a></h3><ul><li> <code></code> <code></code> <code>10</code> C char</li><li> C <code></code><code></code><code>&#39;1&#39;</code><code>&#39;A&#39;</code><code>&#39;&amp;&#39;</code></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li> C 1972 · 1 a-zA-Z0-9 C </li><li> a-zA-Z0-9 </li><li> C 使char </li><li> C 使char </li><li> C++Java String Unicode便</li></ul></div><ul><li> C 使<code> \\</code></li></ul><table tabindex="0"><thead><tr><th><strong></strong></th><th><strong></strong></th></tr></thead><tbody><tr><td><code>\\b</code></td><td>退</td></tr><tr><td><code>\\n</code></td><td></td></tr><tr><td><code>\\r</code></td><td></td></tr><tr><td><code>\\t</code></td><td></td></tr><tr><td><code>\\&quot;</code></td><td></td></tr><tr><td><code>\\&#39;</code></td><td></td></tr><tr><td><code>\\\\</code></td><td></td></tr><tr><td>...</td><td></td></tr></tbody></table><h3 id="_1-5-2-" tabindex="-1">1.5.2 <a class="header-anchor" href="#_1-5-2-" aria-label="Permalink to &quot;1.5.2 &quot;"></a></h3><ul><li><p> C 使 <code>%c</code> char </p></li><li><p></p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><h2 id="_1-5-" tabindex="-1">1.5 <a class="header-anchor" href="#_1-5-" aria-label="Permalink to &quot;1.5 &quot;"></a></h2><h3 id="_1-5-1-" tabindex="-1">1.5.1 <a class="header-anchor" href="#_1-5-1-" aria-label="Permalink to &quot;1.5.1 &quot;"></a></h3><ul><li> <code></code> <code></code> <code>10</code> C <code></code>char<code></code><code></code>使<code>&#39;&#39;</code><code>&#39;1&#39;</code><code>&#39;A&#39;</code><code>&#39;&amp;&#39;</code></li><li><code></code><code></code> C <code></code>String<code></code><code></code>使<code>&quot;&quot;</code><code>&quot;1&quot;</code><code>&quot;A&quot;</code><code>&quot;&amp;&quot;</code><code>&quot;&quot;</code></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li> C 1972 · 1 a-zA-Z0-9 C </li><li> a-zA-Z0-9 </li><li> C 使char </li><li> C 使char </li><li> C++Java String Unicode便</li></ul></div><ul><li> C 使<code> \\</code></li></ul><table tabindex="0"><thead><tr><th><strong></strong></th><th><strong></strong></th></tr></thead><tbody><tr><td><code>\\b</code></td><td>退</td></tr><tr><td><code>\\n</code></td><td></td></tr><tr><td><code>\\r</code></td><td></td></tr><tr><td><code>\\t</code></td><td></td></tr><tr><td><code>\\&quot;</code></td><td></td></tr><tr><td><code>\\&#39;</code></td><td></td></tr><tr><td><code>\\\\</code></td><td></td></tr><tr><td>...</td><td></td></tr></tbody></table><h3 id="_1-5-2-" tabindex="-1">1.5.2 <a class="header-anchor" href="#_1-5-2-" aria-label="Permalink to &quot;1.5.2 &quot;"></a></h3><ul><li><p> C 使 <code>%c</code> char </p></li><li><p></p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
@ -401,7 +401,45 @@ import{_ as p,c as n,j as s,a as i,a6 as a,o as l}from"./chunks/framework.hMCIpN
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;c1=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">, c2=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">, c3=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, c1, c2, c3);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br></div></div><h2 id="_1-6-" tabindex="-1">1.6 <a class="header-anchor" href="#_1-6-" aria-label="Permalink to &quot;1.6 &quot;"></a></h2><h3 id="_1-6-1-" tabindex="-1">1.6.1 <a class="header-anchor" href="#_1-6-1-" aria-label="Permalink to &quot;1.6.1 &quot;"></a></h3><ul><li> truefalse</li></ul><h3 id="_1-6-2-" tabindex="-1">1.6.2 <a class="header-anchor" href="#_1-6-2-" aria-label="Permalink to &quot;1.6.2 &quot;"></a></h3><ul><li><p> C C89使 <code>0</code> <code>false</code><code> 0</code> <code>true</code></p></li><li><p></p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br></div></div><h3 id="_1-5-6--" tabindex="-1">1.5.6 <a class="header-anchor" href="#_1-5-6--" aria-label="Permalink to &quot;1.5.6 &quot;"></a></h3><ul><li> C 使 <code>printf()</code> 使 <code>putchar()</code></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li> <code>putchar()</code> <code>printf()</code> <code>char</code> <code>%c</code></li><li> 使 <code>printf()</code> </li></ul></div><ul><li></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> a </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;1&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> b </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;2&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> c </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;&amp;&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> /* 12&amp; */</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> putchar</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(a);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> putchar</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(b);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> putchar</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(c);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><h3 id="_1-5-7--" tabindex="-1">1.5.7 <a class="header-anchor" href="#_1-5-7--" aria-label="Permalink to &quot;1.5.7 &quot;"></a></h3><ul><li> C 使<code></code>使</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li> C <code></code><code></code><code></code>使<code></code></li><li> C 使 <code>puts()</code> <code>puts()</code> <code>\\n</code> </li><li> C 使 <code>printf()</code> <code>%s</code> <code>puts()</code> <code>printf()</code> <code>\\n</code></li><li> 使 <code>printf()</code> </li></ul></div><ul><li></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 存储字符串</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> str</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">str2 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> puts</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(str);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // </span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> puts</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(str2);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // </span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><ul><li></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 存储字符串</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> str</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">str2 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%s\\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, str);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // </span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%s\\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, str2);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // </span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><h2 id="_1-6-" tabindex="-1">1.6 <a class="header-anchor" href="#_1-6-" aria-label="Permalink to &quot;1.6 &quot;"></a></h2><h3 id="_1-6-1-" tabindex="-1">1.6.1 <a class="header-anchor" href="#_1-6-1-" aria-label="Permalink to &quot;1.6.1 &quot;"></a></h3><ul><li> truefalse</li></ul><h3 id="_1-6-2-" tabindex="-1">1.6.2 <a class="header-anchor" href="#_1-6-2-" aria-label="Permalink to &quot;1.6.2 &quot;"></a></h3><ul><li><p> C C89使 <code>0</code> <code>false</code><code> 0</code> <code>true</code></p></li><li><p></p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 禁用 stdout 缓冲区</span></span>
@ -592,7 +630,7 @@ import{_ as p,c as n,j as s,a as i,a6 as a,o as l}from"./chunks/framework.hMCIpN
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;num3=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num3);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><h2 id="_1-8-" tabindex="-1">1.8 <a class="header-anchor" href="#_1-8-" aria-label="Permalink to &quot;1.8 &quot;"></a></h2><ul><li><p>CPU CPU CPU </p></li><li><p>CPU 1 Bytes = 8 bit</p></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li> MMUVirtual Address Mapping使使使</li><li> 便 CPU 便</li><li> 0 1 </li></ul></div><p><img src="`+B+'" alt="" loading="lazy"></p><ul><li>便</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p><code></code><code></code><code></code><code></code></p></div><p><img src="'+A+'" alt="" loading="lazy"></p><ul><li></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p></p><ul><li> </li><li> </li><li> </li></ul></div><ul><li></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li> 便 </li><li> 10 int 4 + 4 </li><li> </li></ul></div><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li> 使</li><li> </li><li> JavaScript TypeScript JavaScript </li></ul></div><p><img src="'+D+'" alt="" loading="lazy"></p><h1 id="--" tabindex="-1"> <a class="header-anchor" href="#--" aria-label="Permalink to &quot;&quot;"></a></h1><h2 id="_2-1-" tabindex="-1">2.1 <a class="header-anchor" href="#_2-1-" aria-label="Permalink to &quot;2.1 &quot;"></a></h2><ul><li></li><li><code></code><code></code></li></ul><p><img src="'+v+'" alt="" loading="lazy"></p><ul><li><code></code><code></code><code></code><code></code></li></ul><p><img src="'+T+`" alt="" loading="lazy"></p><ul><li><code></code><code></code> <ul><li></li><li></li><li></li></ul></li><li><code></code> <ul><li></li><li></li><li></li><li></li><li></li><li></li><li></li></ul></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p></p><ul><li> </li><li> </li><li> </li><li> </li></ul></div><h2 id="_2-2-" tabindex="-1">2.2 <a class="header-anchor" href="#_2-2-" aria-label="Permalink to &quot;2.2 &quot;"></a></h2><ul><li></li></ul><table tabindex="0"><thead><tr><th></th><th></th><th></th><th></th><th></th></tr></thead><tbody><tr><td><code>+</code></td><td></td><td>1</td><td></td><td></td></tr><tr><td><code>-</code></td><td></td><td>1</td><td></td><td></td></tr><tr><td><code>+</code></td><td></td><td>2</td><td></td><td></td></tr><tr><td><code>-</code></td><td></td><td>2</td><td></td><td></td></tr><tr><td><code>*</code></td><td></td><td>2</td><td></td><td></td></tr><tr><td><code>/</code></td><td></td><td>2</td><td></td><td></td></tr><tr><td><code>%</code></td><td></td><td>2</td><td></td><td></td></tr><tr><td><code>++</code></td><td></td><td>1</td><td></td><td></td></tr><tr><td><code>--</code></td><td></td><td>1</td><td></td><td></td></tr></tbody></table><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p></p><ul><li> </li><li> </li><li> <code>++</code> 1 <code>++</code> 1 </li><li> <code>--</code> 1 <code>--</code> 1 </li><li> <code>i++</code> <code>i--</code> C/C++Java Python Go <code>i++</code> <code>i--</code> </li></ul></div><ul><li></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><h2 id="_1-8-" tabindex="-1">1.8 <a class="header-anchor" href="#_1-8-" aria-label="Permalink to &quot;1.8 &quot;"></a></h2><ul><li><p>CPU CPU CPU </p></li><li><p>CPU 1 Bytes = 8 bit</p></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li> MMUVirtual Address Mapping使使使</li><li> 便 CPU 便</li><li> 0 1 </li></ul></div><p><img src="`+A+'" alt="" loading="lazy"></p><ul><li>便</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p><code></code><code></code><code></code><code></code></p></div><p><img src="'+B+'" alt="" loading="lazy"></p><ul><li></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p></p><ul><li> </li><li> </li><li> </li></ul></div><ul><li></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li> 便 </li><li> 10 int 4 + 4 </li><li> </li></ul></div><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li> 使</li><li> </li><li> JavaScript TypeScript JavaScript </li></ul></div><p><img src="'+D+'" alt="" loading="lazy"></p><h1 id="--" tabindex="-1"> <a class="header-anchor" href="#--" aria-label="Permalink to &quot;&quot;"></a></h1><h2 id="_2-1-" tabindex="-1">2.1 <a class="header-anchor" href="#_2-1-" aria-label="Permalink to &quot;2.1 &quot;"></a></h2><ul><li></li><li><code></code><code></code></li></ul><p><img src="'+v+'" alt="" loading="lazy"></p><ul><li><code></code><code></code><code></code><code></code></li></ul><p><img src="'+T+`" alt="" loading="lazy"></p><ul><li><code></code><code></code> <ul><li></li><li></li><li></li></ul></li><li><code></code> <ul><li></li><li></li><li></li><li></li><li></li><li></li><li></li></ul></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p></p><ul><li> </li><li> </li><li> </li><li> </li></ul></div><h2 id="_2-2-" tabindex="-1">2.2 <a class="header-anchor" href="#_2-2-" aria-label="Permalink to &quot;2.2 &quot;"></a></h2><ul><li></li></ul><table tabindex="0"><thead><tr><th></th><th></th><th></th><th></th><th></th></tr></thead><tbody><tr><td><code>+</code></td><td></td><td>1</td><td></td><td></td></tr><tr><td><code>-</code></td><td></td><td>1</td><td></td><td></td></tr><tr><td><code>+</code></td><td></td><td>2</td><td></td><td></td></tr><tr><td><code>-</code></td><td></td><td>2</td><td></td><td></td></tr><tr><td><code>*</code></td><td></td><td>2</td><td></td><td></td></tr><tr><td><code>/</code></td><td></td><td>2</td><td></td><td></td></tr><tr><td><code>%</code></td><td></td><td>2</td><td></td><td></td></tr><tr><td><code>++</code></td><td></td><td>1</td><td></td><td></td></tr><tr><td><code>--</code></td><td></td><td>1</td><td></td><td></td></tr></tbody></table><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p></p><ul><li> </li><li> </li><li> <code>++</code> 1 <code>++</code> 1 </li><li> <code>--</code> 1 <code>--</code> 1 </li><li> <code>i++</code> <code>i--</code> C/C++Java Python Go <code>i++</code> <code>i--</code> </li></ul></div><ul><li></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
@ -806,7 +844,7 @@ import{_ as p,c as n,j as s,a as i,a6 as a,o as l}from"./chunks/framework.hMCIpN
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot; </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%s</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, b, </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">getBinary</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(b));</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br></div></div><h3 id="_2-6-3-" tabindex="-1">2.6.3 <a class="header-anchor" href="#_2-6-3-" aria-label="Permalink to &quot;2.6.3 &quot;"></a></h3><ul><li><p> <code>&amp;</code> 1 1 0 </p><ul><li><code>1 &amp; 1</code> <code>1</code> </li><li><code>1 &amp; 0</code> <code>0</code> </li><li><code>0 &amp; 1</code> <code>0</code> </li><li><code>0 &amp; 0</code> <code>0</code> </li></ul></li><li><p><code>9 &amp; 7 = 1</code></p></li></ul><p><img src="`+Q+'" alt="" loading="lazy"></p><ul><li><code>-9 &amp; 7 = 7</code></li></ul><p><img src="'+f+'" alt="" loading="lazy"></p><h3 id="_2-6-4-" tabindex="-1">2.6.4 <a class="header-anchor" href="#_2-6-4-" aria-label="Permalink to &quot;2.6.4 &quot;"></a></h3><ul><li><p> <code>|</code> 1 1 0 </p><ul><li><code>1 | 1</code> <code>1</code> </li><li><code>1 | 0</code> <code>1</code> </li><li><code>0 | 1</code> <code>1</code> </li><li><code>0 | 0</code> <code>0</code> </li></ul></li><li><p><code>9 | 7 = 15</code></p></li></ul><p><img src="'+q+'" alt="" loading="lazy"></p><ul><li><code>-9 | 7 = -9</code></li></ul><p><img src="'+_+'" alt="" loading="lazy"></p><h3 id="_2-6-5-" tabindex="-1">2.6.5 <a class="header-anchor" href="#_2-6-5-" aria-label="Permalink to &quot;2.6.5 &quot;"></a></h3><ul><li> <code>^</code> 1 0 1 0 <ul><li><code>1 ^ 1</code> <code>0</code> </li><li><code>1 ^ 0</code> <code>1</code> </li><li><code>0 ^ 1</code> <code>1</code> </li><li><code>0 ^ 0</code> <code>0</code> </li></ul></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p></p><ul><li> 使</li><li> </li><li> RAID-3 </li><li></li></ul></div><ul><li><code>9 ^ 7 = 14</code></li></ul><p><img src="'+x+'" alt="" loading="lazy"></p><ul><li><code>-9 ^ 7 = -16</code></li></ul><p><img src="'+w+'" alt="" loading="lazy"></p><h3 id="_2-6-6-" tabindex="-1">2.6.6 <a class="header-anchor" href="#_2-6-6-" aria-label="Permalink to &quot;2.6.6 &quot;"></a></h3><ul><li><p> 1 0 0 1 </p><ul><li><code>~0</code> <code>1</code> </li><li><code>~1</code> <code>0</code> </li></ul></li><li><p><code>~9 = -10</code></p></li></ul><p><img src="'+L+'" alt="" loading="lazy"></p><ul><li><code>~-9 = 8</code></li></ul><p><img src="'+z+'" alt="" loading="lazy"></p><h3 id="_2-6-7-" tabindex="-1">2.6.7 <a class="header-anchor" href="#_2-6-7-" aria-label="Permalink to &quot;2.6.7 &quot;"></a></h3><ul><li><p> × 2</p></li><li><p><code>3 &lt;&lt; 4 = 48</code> 3 × 2^4</p></li></ul><p><img src="'+H+'" alt="" loading="lazy"></p><ul><li><code>-3 &lt;&lt; 4 = -48</code> -3 × 2 ^4</li></ul><p><img src="'+P+'" alt="" loading="lazy"></p><h3 id="_2-6-8-" tabindex="-1">2.6.8 <a class="header-anchor" href="#_2-6-8-" aria-label="Permalink to &quot;2.6.8 &quot;"></a></h3><ul><li> ÷ 2</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li> </li><li> </li></ul></div><ul><li><code>69 &gt;&gt; 4 = 4</code> 69 ÷ 2^4 </li></ul><p><img src="'+M+'" alt="" loading="lazy"></p><ul><li><code>-69 &gt;&gt; 4 = -5</code> -69 ÷ 2^4 </li></ul><p><img src="'+N+`" alt="" loading="lazy"></p><h2 id="_2-7-" tabindex="-1">2.7 <a class="header-anchor" href="#_2-7-" aria-label="Permalink to &quot;2.7 &quot;"></a></h2><ul><li></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">?</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 1 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 2 ;</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li> 0 1 </li><li> 0 2 </li></ul></div><ul><li></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br></div></div><h3 id="_2-6-3-" tabindex="-1">2.6.3 <a class="header-anchor" href="#_2-6-3-" aria-label="Permalink to &quot;2.6.3 &quot;"></a></h3><ul><li><p> <code>&amp;</code> 1 1 0 </p><ul><li><code>1 &amp; 1</code> <code>1</code> </li><li><code>1 &amp; 0</code> <code>0</code> </li><li><code>0 &amp; 1</code> <code>0</code> </li><li><code>0 &amp; 0</code> <code>0</code> </li></ul></li><li><p><code>9 &amp; 7 = 1</code></p></li></ul><p><img src="`+Q+'" alt="" loading="lazy"></p><ul><li><code>-9 &amp; 7 = 7</code></li></ul><p><img src="'+q+'" alt="" loading="lazy"></p><h3 id="_2-6-4-" tabindex="-1">2.6.4 <a class="header-anchor" href="#_2-6-4-" aria-label="Permalink to &quot;2.6.4 &quot;"></a></h3><ul><li><p> <code>|</code> 1 1 0 </p><ul><li><code>1 | 1</code> <code>1</code> </li><li><code>1 | 0</code> <code>1</code> </li><li><code>0 | 1</code> <code>1</code> </li><li><code>0 | 0</code> <code>0</code> </li></ul></li><li><p><code>9 | 7 = 15</code></p></li></ul><p><img src="'+f+'" alt="" loading="lazy"></p><ul><li><code>-9 | 7 = -9</code></li></ul><p><img src="'+_+'" alt="" loading="lazy"></p><h3 id="_2-6-5-" tabindex="-1">2.6.5 <a class="header-anchor" href="#_2-6-5-" aria-label="Permalink to &quot;2.6.5 &quot;"></a></h3><ul><li> <code>^</code> 1 0 1 0 <ul><li><code>1 ^ 1</code> <code>0</code> </li><li><code>1 ^ 0</code> <code>1</code> </li><li><code>0 ^ 1</code> <code>1</code> </li><li><code>0 ^ 0</code> <code>0</code> </li></ul></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p></p><ul><li> 使</li><li> </li><li> RAID-3 </li><li></li></ul></div><ul><li><code>9 ^ 7 = 14</code></li></ul><p><img src="'+x+'" alt="" loading="lazy"></p><ul><li><code>-9 ^ 7 = -16</code></li></ul><p><img src="'+w+'" alt="" loading="lazy"></p><h3 id="_2-6-6-" tabindex="-1">2.6.6 <a class="header-anchor" href="#_2-6-6-" aria-label="Permalink to &quot;2.6.6 &quot;"></a></h3><ul><li><p> 1 0 0 1 </p><ul><li><code>~0</code> <code>1</code> </li><li><code>~1</code> <code>0</code> </li></ul></li><li><p><code>~9 = -10</code></p></li></ul><p><img src="'+L+'" alt="" loading="lazy"></p><ul><li><code>~-9 = 8</code></li></ul><p><img src="'+z+'" alt="" loading="lazy"></p><h3 id="_2-6-7-" tabindex="-1">2.6.7 <a class="header-anchor" href="#_2-6-7-" aria-label="Permalink to &quot;2.6.7 &quot;"></a></h3><ul><li><p> × 2</p></li><li><p><code>3 &lt;&lt; 4 = 48</code> 3 × 2^4</p></li></ul><p><img src="'+H+'" alt="" loading="lazy"></p><ul><li><code>-3 &lt;&lt; 4 = -48</code> -3 × 2 ^4</li></ul><p><img src="'+I+'" alt="" loading="lazy"></p><h3 id="_2-6-8-" tabindex="-1">2.6.8 <a class="header-anchor" href="#_2-6-8-" aria-label="Permalink to &quot;2.6.8 &quot;"></a></h3><ul><li> ÷ 2</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li> </li><li> </li></ul></div><ul><li><code>69 &gt;&gt; 4 = 4</code> 69 ÷ 2^4 </li></ul><p><img src="'+U+'" alt="" loading="lazy"></p><ul><li><code>-69 &gt;&gt; 4 = -5</code> -69 ÷ 2^4 </li></ul><p><img src="'+P+`" alt="" loading="lazy"></p><h2 id="_2-7-" tabindex="-1">2.7 <a class="header-anchor" href="#_2-7-" aria-label="Permalink to &quot;2.7 &quot;"></a></h2><ul><li></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">?</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 1 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 2 ;</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li> 0 1 </li><li> 0 2 </li></ul></div><ul><li></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
@ -816,4 +854,4 @@ import{_ as p,c as n,j as s,a as i,a6 as a,o as l}from"./chunks/framework.hMCIpN
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;result = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, result);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // result = 110</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><h2 id="_2-8-" tabindex="-1">2.8 <a class="header-anchor" href="#_2-8-" aria-label="Permalink to &quot;2.8 &quot;"></a></h2><ul><li>C </li></ul><table tabindex="0"><thead><tr><th><strong></strong></th><th><strong></strong></th><th><strong></strong></th><th><strong></strong></th></tr></thead><tbody><tr><td><strong>1</strong></td><td><code>[]</code></td><td></td><td></td></tr><tr><td></td><td><code>()</code></td><td></td><td></td></tr><tr><td></td><td><code>.</code></td><td></td><td></td></tr><tr><td></td><td><code>-&gt;</code></td><td></td><td></td></tr><tr><td><strong>2</strong></td><td><code>-</code></td><td></td><td></td></tr><tr><td></td><td><code></code></td><td></td><td></td></tr><tr><td></td><td><code>++</code></td><td></td><td></td></tr><tr><td></td><td><code>--</code></td><td></td><td></td></tr><tr><td></td><td><code>*</code></td><td></td><td></td></tr><tr><td></td><td><code>&amp;</code></td><td></td><td></td></tr><tr><td></td><td><code>!</code></td><td></td><td></td></tr><tr><td></td><td><code>~</code></td><td></td><td></td></tr><tr><td></td><td><code>sizeof</code></td><td></td><td></td></tr><tr><td><strong>3</strong></td><td><code>/</code></td><td></td><td></td></tr><tr><td></td><td><code>*</code></td><td></td><td></td></tr><tr><td></td><td><code>%</code></td><td></td><td></td></tr><tr><td><strong>4</strong></td><td><code>+</code></td><td></td><td></td></tr><tr><td></td><td><code>-</code></td><td></td><td></td></tr><tr><td><strong>5</strong></td><td><code>&lt;&lt;</code></td><td></td><td></td></tr><tr><td></td><td><code>&gt;&gt;</code></td><td></td><td></td></tr><tr><td><strong>6</strong></td><td><code>&gt;</code></td><td></td><td></td></tr><tr><td></td><td><code>&gt;=</code></td><td></td><td></td></tr><tr><td></td><td><code>&lt;</code></td><td></td><td></td></tr><tr><td></td><td><code>&lt;=</code></td><td></td><td></td></tr><tr><td><strong>7</strong></td><td><code>==</code></td><td></td><td></td></tr><tr><td></td><td><code>!=</code></td><td></td><td></td></tr><tr><td><strong>8</strong></td><td><code>&amp;</code></td><td></td><td></td></tr><tr><td><strong>9</strong></td><td><code>^</code></td><td></td><td></td></tr><tr><td><strong>10</strong></td><td><code>|</code></td><td></td><td></td></tr><tr><td><strong>11</strong></td><td><code>&amp;&amp;</code></td><td></td><td></td></tr><tr><td><strong>12</strong></td><td><code>||</code></td><td></td><td></td></tr><tr><td><strong>13</strong></td><td><code>?:</code></td><td></td><td></td></tr><tr><td><strong>14</strong></td><td><code>=</code></td><td></td><td></td></tr><tr><td></td><td><code>/=</code></td><td></td><td></td></tr><tr><td></td><td><code>*=</code></td><td></td><td></td></tr><tr><td></td><td><code>%=</code></td><td></td><td></td></tr><tr><td></td><td><code>+=</code></td><td></td><td></td></tr><tr><td></td><td><code>-=</code></td><td></td><td></td></tr><tr><td></td><td><code>&lt;&lt;=</code></td><td></td><td></td></tr><tr><td></td><td><code>&gt;&gt;=</code></td><td></td><td></td></tr><tr><td></td><td><code>&amp;=</code></td><td></td><td></td></tr><tr><td></td><td><code>^=</code></td><td></td><td></td></tr><tr><td></td><td><code>|=</code></td><td></td><td></td></tr><tr><td><strong>15</strong></td><td><code>,</code></td><td></td><td></td></tr></tbody></table><div class="warning custom-block github-alert"><p class="custom-block-title">WARNING</p><p></p><ul><li> <code>使</code></li><li> <code></code></li><li> &gt; &gt; &gt; &gt; &gt; </li></ul></div><h1 id="-" tabindex="-1"> <a class="header-anchor" href="#-" aria-label="Permalink to &quot;&quot;"></a></h1><h2 id="_3-1-" tabindex="-1">3.1 <a class="header-anchor" href="#_3-1-" aria-label="Permalink to &quot;3.1 &quot;"></a></h2><h3 id="_3-3-1-" tabindex="-1">3.3.1 <a class="header-anchor" href="#_3-3-1-" aria-label="Permalink to &quot;3.3.1 &quot;"></a></h3><ul><li></li><li>Character Set<code></code><code></code></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>ASCII 128 0 127 </p></div><ul><li>Character Encoding<code></code></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>ASCII ASCII 7 <code>&#39;A&#39;</code> ASCII <code>1000001</code> <code>65</code> </p></div><ul><li><code></code><code></code></li></ul><p><img src="`+I+'" alt="" loading="lazy"></p><ul><li>Linux </li></ul><p><img src="'+V+'" alt="" loading="lazy"></p><h3 id="_3-3-2-ascii-" tabindex="-1">3.3.2 ASCII <a class="header-anchor" href="#_3-3-2-ascii-" aria-label="Permalink to &quot;3.3.2 ASCII &quot;"></a></h3><ul><li><code>·</code><code></code><code></code><code></code></li></ul><p><img src="'+S+'" alt="" loading="lazy"></p><ul><li> 60 ASCII American Standard Code for Information Interchange <ul><li>ASCII 128 0 - 127</li><li>ASCII 使 7 1 B = 8 0 </li></ul></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li> </li><li> <code>a-zA-Z0-9</code><code></code> <code>128</code> ASCII 使 7 2^7 = 128 </li></ul></div><ul><li>Linux 使</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">man</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ascii</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+U+'" alt="" loading="lazy"></p><ul><li> ASCII </li></ul><p><img src="'+O+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+Z+'" alt="" loading="lazy"></p><ul><li> ASCII ISO8859-1 <ul><li>ISO8859-1 西 <code>è</code> <code>ü</code> </li><li>ISO 8859-1 8 256 2^8 0 255</li><li>ISO 8859-1 128 ASCII 使 ASCII ISO 8859-1 </li></ul></li></ul><p><img src="'+R+'" alt="" loading="lazy"></p><p><img src="'+G+'" alt="" loading="lazy"></p><ul><li> <ul><li> Shift-JIS <ul><li> ASCII 0 - 127</li><li> <ul><li>129 - 159 224 - 239 </li><li>64 - 126 128 - 252 </li></ul></li></ul></li><li> EUC-KR <ul><li> ASCII 0 - 127</li><li> 41281 - 65278</li></ul></li><li> GBK <ul><li> ASCII 0 - 127</li><li>33088 - 65278 </li></ul></li></ul></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li> </li><li> GBK </li></ul></div><h3 id="_3-3-3-unicode-" tabindex="-1">3.3.3 Unicode <a class="header-anchor" href="#_3-3-3-unicode-" aria-label="Permalink to &quot;3.3.3 Unicode &quot;"></a></h3><ul><li><p> Unicode ASCIIISO 8859 GBKShift-JISEUC-KR </p><ul><li><code></code></li><li><code></code></li><li><code></code></li><li></li></ul></li><li><p>Unicode Unicode 使使使使</p><ul><li><code> (UCS)</code>Unicode <code></code> Universal Character SetUCS <code>U+</code> <code>U+0041</code> <code>A</code></li><li><code></code>Unicode Planes 6553616^4Unicode 17 0 16 BMP 0 16 Unicode 11017*65536</li></ul></li><li><p>Unicode </p></li></ul><p><img src="'+j+'" alt="" loading="lazy"></p><ul><li> Unicode UTF-8UTF-16 UTF-32 <ul><li><strong>UTF-8</strong>使 1 - 4 Unicode ASCII</li><li><strong>UTF-16</strong>使 2 - 4 Unicode </li><li><strong>UTF-32</strong>使 4 Unicode </li></ul></li><li><code>Unicode </code><code>UTF-8 </code></li></ul><p><img src="'+J+'" alt="" loading="lazy"></p><h2 id="_3-2-wsl2-" tabindex="-1">3.2 WSL2 <a class="header-anchor" href="#_3-2-wsl2-" aria-label="Permalink to &quot;3.2 WSL2 &quot;"></a></h2><h3 id="_3-2-1-" tabindex="-1">3.2.1 <a class="header-anchor" href="#_3-2-1-" aria-label="Permalink to &quot;3.2.1 &quot;"></a></h3><ul><li> WSL2 Linux </li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $LANG</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+X+'" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p><code>C.UTF-8</code> <code>C</code> <code>UTF-8</code> </p><ul><li> <strong>C </strong><code>C</code> ASCII <code>C</code> </li><li> <strong>UTF-8 </strong>UTF-8 Unicode 广使 UTF-8 14使 ASCII ASCII UTF-8 使</li></ul><p><code>C.UTF-8</code> <code>C</code> UTF-8 使 <code>C.UTF-8</code> 广</p></div><h3 id="_3-2-2-almalinux9-" tabindex="-1">3.2.2 AlmaLinux9 <a class="header-anchor" href="#_3-2-2-almalinux9-" aria-label="Permalink to &quot;3.2.2 AlmaLinux9 &quot;"></a></h3><ul><li> </li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">dnf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> search</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> locale</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> zh</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+W+'" alt="" loading="lazy"></p><ul><li> </li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">dnf</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> glibc-langpack-zh</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+K+'" alt="" loading="lazy"></p><ul><li> </li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">localectl</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> set-locale</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> LANG=zh_CN.UTF-8</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+$+'" alt="" loading="lazy"></p><ul><li> 使</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">source</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /etc/locale.conf</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+Y+'" alt="" loading="lazy"></p><h3 id="_3-2-3-ubuntu-22-04-" tabindex="-1">3.2.3 Ubuntu 22.04 <a class="header-anchor" href="#_3-2-3-ubuntu-22-04-" aria-label="Permalink to &quot;3.2.3 Ubuntu 22.04 &quot;"></a></h3><ul><li> </li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">apt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> update</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &amp;&amp; </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">apt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> language-pack-zh-hans</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+ss+'" alt="" loading="lazy"></p><ul><li> </li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">update-locale</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> LANG=zh_CN.UTF-8</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> LANGUAGE=zh_CN:zh</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+is+'" alt="" loading="lazy"></p><ul><li> 使</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">source</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /etc/default/locale</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+as+'" alt="" loading="lazy"></p>',309);function ys(us,bs,ms,Cs,Bs,As){return l(),n("div",null,[ls,s("p",null,[s("mjx-container",ps,[(l(),n("svg",ts,es)),ks])]),s("ul",null,[s("li",null,[s("p",null,[i(""),s("mjx-container",ds,[(l(),n("svg",rs,Es)),gs])])]),os]),Fs])}const Ts=p(ns,[["render",ys]]);export{vs as __pageData,Ts as default};
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><h2 id="_2-8-" tabindex="-1">2.8 <a class="header-anchor" href="#_2-8-" aria-label="Permalink to &quot;2.8 &quot;"></a></h2><ul><li>C </li></ul><table tabindex="0"><thead><tr><th><strong></strong></th><th><strong></strong></th><th><strong></strong></th><th><strong></strong></th></tr></thead><tbody><tr><td><strong>1</strong></td><td><code>[]</code></td><td></td><td></td></tr><tr><td></td><td><code>()</code></td><td></td><td></td></tr><tr><td></td><td><code>.</code></td><td></td><td></td></tr><tr><td></td><td><code>-&gt;</code></td><td></td><td></td></tr><tr><td><strong>2</strong></td><td><code>-</code></td><td></td><td></td></tr><tr><td></td><td><code></code></td><td></td><td></td></tr><tr><td></td><td><code>++</code></td><td></td><td></td></tr><tr><td></td><td><code>--</code></td><td></td><td></td></tr><tr><td></td><td><code>*</code></td><td></td><td></td></tr><tr><td></td><td><code>&amp;</code></td><td></td><td></td></tr><tr><td></td><td><code>!</code></td><td></td><td></td></tr><tr><td></td><td><code>~</code></td><td></td><td></td></tr><tr><td></td><td><code>sizeof</code></td><td></td><td></td></tr><tr><td><strong>3</strong></td><td><code>/</code></td><td></td><td></td></tr><tr><td></td><td><code>*</code></td><td></td><td></td></tr><tr><td></td><td><code>%</code></td><td></td><td></td></tr><tr><td><strong>4</strong></td><td><code>+</code></td><td></td><td></td></tr><tr><td></td><td><code>-</code></td><td></td><td></td></tr><tr><td><strong>5</strong></td><td><code>&lt;&lt;</code></td><td></td><td></td></tr><tr><td></td><td><code>&gt;&gt;</code></td><td></td><td></td></tr><tr><td><strong>6</strong></td><td><code>&gt;</code></td><td></td><td></td></tr><tr><td></td><td><code>&gt;=</code></td><td></td><td></td></tr><tr><td></td><td><code>&lt;</code></td><td></td><td></td></tr><tr><td></td><td><code>&lt;=</code></td><td></td><td></td></tr><tr><td><strong>7</strong></td><td><code>==</code></td><td></td><td></td></tr><tr><td></td><td><code>!=</code></td><td></td><td></td></tr><tr><td><strong>8</strong></td><td><code>&amp;</code></td><td></td><td></td></tr><tr><td><strong>9</strong></td><td><code>^</code></td><td></td><td></td></tr><tr><td><strong>10</strong></td><td><code>|</code></td><td></td><td></td></tr><tr><td><strong>11</strong></td><td><code>&amp;&amp;</code></td><td></td><td></td></tr><tr><td><strong>12</strong></td><td><code>||</code></td><td></td><td></td></tr><tr><td><strong>13</strong></td><td><code>?:</code></td><td></td><td></td></tr><tr><td><strong>14</strong></td><td><code>=</code></td><td></td><td></td></tr><tr><td></td><td><code>/=</code></td><td></td><td></td></tr><tr><td></td><td><code>*=</code></td><td></td><td></td></tr><tr><td></td><td><code>%=</code></td><td></td><td></td></tr><tr><td></td><td><code>+=</code></td><td></td><td></td></tr><tr><td></td><td><code>-=</code></td><td></td><td></td></tr><tr><td></td><td><code>&lt;&lt;=</code></td><td></td><td></td></tr><tr><td></td><td><code>&gt;&gt;=</code></td><td></td><td></td></tr><tr><td></td><td><code>&amp;=</code></td><td></td><td></td></tr><tr><td></td><td><code>^=</code></td><td></td><td></td></tr><tr><td></td><td><code>|=</code></td><td></td><td></td></tr><tr><td><strong>15</strong></td><td><code>,</code></td><td></td><td></td></tr></tbody></table><div class="warning custom-block github-alert"><p class="custom-block-title">WARNING</p><p></p><ul><li> <code>使</code></li><li> <code></code></li><li> &gt; &gt; &gt; &gt; &gt; </li></ul></div><h1 id="-" tabindex="-1"> <a class="header-anchor" href="#-" aria-label="Permalink to &quot;&quot;"></a></h1><h2 id="_3-1-" tabindex="-1">3.1 <a class="header-anchor" href="#_3-1-" aria-label="Permalink to &quot;3.1 &quot;"></a></h2><h3 id="_3-3-1-" tabindex="-1">3.3.1 <a class="header-anchor" href="#_3-3-1-" aria-label="Permalink to &quot;3.3.1 &quot;"></a></h3><ul><li></li><li>Character Set<code></code><code></code></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>ASCII 128 0 127 </p></div><ul><li>Character Encoding<code></code></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>ASCII ASCII 7 <code>&#39;A&#39;</code> ASCII <code>1000001</code> <code>65</code> </p></div><ul><li><code></code><code></code></li></ul><p><img src="`+N+'" alt="" loading="lazy"></p><ul><li>Linux </li></ul><p><img src="'+M+'" alt="" loading="lazy"></p><h3 id="_3-3-2-ascii-" tabindex="-1">3.3.2 ASCII <a class="header-anchor" href="#_3-3-2-ascii-" aria-label="Permalink to &quot;3.3.2 ASCII &quot;"></a></h3><ul><li><code>·</code><code></code><code></code><code></code></li></ul><p><img src="'+S+'" alt="" loading="lazy"></p><ul><li> 60 ASCII American Standard Code for Information Interchange <ul><li>ASCII 128 0 - 127</li><li>ASCII 使 7 1 B = 8 0 </li></ul></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li> </li><li> <code>a-zA-Z0-9</code><code></code> <code>128</code> ASCII 使 7 2^7 = 128 </li></ul></div><ul><li>Linux 使</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">man</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ascii</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+V+'" alt="" loading="lazy"></p><ul><li> ASCII </li></ul><p><img src="'+O+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+Z+'" alt="" loading="lazy"></p><ul><li> ASCII ISO8859-1 <ul><li>ISO8859-1 西 <code>è</code> <code>ü</code> </li><li>ISO 8859-1 8 256 2^8 0 255</li><li>ISO 8859-1 128 ASCII 使 ASCII ISO 8859-1 </li></ul></li></ul><p><img src="'+R+'" alt="" loading="lazy"></p><p><img src="'+G+'" alt="" loading="lazy"></p><ul><li> <ul><li> Shift-JIS <ul><li> ASCII 0 - 127</li><li> <ul><li>129 - 159 224 - 239 </li><li>64 - 126 128 - 252 </li></ul></li></ul></li><li> EUC-KR <ul><li> ASCII 0 - 127</li><li> 41281 - 65278</li></ul></li><li> GBK <ul><li> ASCII 0 - 127</li><li>33088 - 65278 </li></ul></li></ul></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li> </li><li> GBK </li></ul></div><h3 id="_3-3-3-unicode-" tabindex="-1">3.3.3 Unicode <a class="header-anchor" href="#_3-3-3-unicode-" aria-label="Permalink to &quot;3.3.3 Unicode &quot;"></a></h3><ul><li><p> Unicode ASCIIISO 8859 GBKShift-JISEUC-KR </p><ul><li><code></code></li><li><code></code></li><li><code></code></li><li></li></ul></li><li><p>Unicode Unicode 使使使使</p><ul><li><code> (UCS)</code>Unicode <code></code> Universal Character SetUCS <code>U+</code> <code>U+0041</code> <code>A</code></li><li><code></code>Unicode Planes 6553616^4Unicode 17 0 16 BMP 0 16 Unicode 11017*65536</li></ul></li><li><p>Unicode </p></li></ul><p><img src="'+j+'" alt="" loading="lazy"></p><ul><li> Unicode UTF-8UTF-16 UTF-32 <ul><li><strong>UTF-8</strong>使 1 - 4 Unicode ASCII</li><li><strong>UTF-16</strong>使 2 - 4 Unicode </li><li><strong>UTF-32</strong>使 4 Unicode </li></ul></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li> UTF-8 ASCIIUTF-32 UTF-16 ASCII <ul><li>UTF-8 使163 UTF-8 UTF-8 UTF-8 10 UTF-8 10 UTF-8 </li><li>UTF-32 UTF-8 UTF-32 UTF-32 UTF-32 10 37 UTF-32 使 UTF-32 UTF-8 UTF-16 广</li><li>UTF-16 UTF-8 UTF-32 UTF-16 </li></ul></li><li> <strong>UTF-8</strong> <strong>UTF-16</strong> <strong>UTF-32</strong></li><li> UTF-8 </li><li> Windows .NET FrameworkJava String <code>UTF-16</code> </li><li> UNIX LinuxMac OSiOS <code>UTF-8</code> UTF-8 ASCII Unicode ASCII</li></ul></div><ul><li><code>Unicode </code><code>UTF-8 </code></li></ul><p><img src="'+J+'" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p><code></code><code></code></p><ul><li> <code></code>使8 ASCII <code></code>ASCII西</li><li> <code></code>使 ASCII 广 Unicode <code></code>UTF-32UTF-16 </li></ul><p><code></code> <code>UTF-8</code> <code>UTF-8</code> <code>ASCII</code> <code></code><code></code> <code>UTF-16</code> <code>UTF-32</code>使</p></div><h2 id="_3-2-wsl2-" tabindex="-1">3.2 WSL2 <a class="header-anchor" href="#_3-2-wsl2-" aria-label="Permalink to &quot;3.2 WSL2 &quot;"></a></h2><h3 id="_3-2-1-" tabindex="-1">3.2.1 <a class="header-anchor" href="#_3-2-1-" aria-label="Permalink to &quot;3.2.1 &quot;"></a></h3><ul><li> WSL2 Linux </li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $LANG</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+X+'" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p><code>C.UTF-8</code> <code>C</code> <code>UTF-8</code> </p><ul><li> <strong>C </strong><code>C</code> ASCII <code>C</code> </li><li> <strong>UTF-8 </strong>UTF-8 Unicode 广使 UTF-8 14使 ASCII ASCII UTF-8 使</li></ul><p><code>C.UTF-8</code> <code>C</code> UTF-8 使 <code>C.UTF-8</code> 广</p></div><h3 id="_3-2-2-almalinux9-" tabindex="-1">3.2.2 AlmaLinux9 <a class="header-anchor" href="#_3-2-2-almalinux9-" aria-label="Permalink to &quot;3.2.2 AlmaLinux9 &quot;"></a></h3><ul><li> </li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">dnf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> search</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> locale</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> zh</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+W+'" alt="" loading="lazy"></p><ul><li> </li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">dnf</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> glibc-langpack-zh</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+K+'" alt="" loading="lazy"></p><ul><li> </li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">localectl</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> set-locale</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> LANG=zh_CN.UTF-8</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+$+'" alt="" loading="lazy"></p><ul><li> 使</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">source</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /etc/locale.conf</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+Y+'" alt="" loading="lazy"></p><h3 id="_3-2-3-ubuntu-22-04-" tabindex="-1">3.2.3 Ubuntu 22.04 <a class="header-anchor" href="#_3-2-3-ubuntu-22-04-" aria-label="Permalink to &quot;3.2.3 Ubuntu 22.04 &quot;"></a></h3><ul><li> </li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">apt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> update</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &amp;&amp; </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">apt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> language-pack-zh-hans</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+ss+'" alt="" loading="lazy"></p><ul><li> </li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">update-locale</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> LANG=zh_CN.UTF-8</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> LANGUAGE=zh_CN:zh</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+is+'" alt="" loading="lazy"></p><ul><li> 使</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">source</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /etc/default/locale</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+as+'" alt="" loading="lazy"></p>',324);function ys(us,bs,ms,Cs,As,Bs){return l(),n("div",null,[ls,s("p",null,[s("mjx-container",ps,[(l(),n("svg",ts,es)),ks])]),s("ul",null,[s("li",null,[s("p",null,[i(""),s("mjx-container",ds,[(l(),n("svg",rs,Es)),gs])])]),os]),Fs])}const Ts=p(ns,[["render",ys]]);export{vs as __pageData,Ts as default};

View File

@ -1 +1 @@
import{_ as p,c as n,j as s,a as i,a6 as a,o as l}from"./chunks/framework.hMCIpNYY.js";const t="/c/assets/1.L8V3GBrc.png",h="/c/assets/2.nqdAY_P3.png",e="/c/assets/3.D7eNbwzQ.jpg",k="/c/assets/4.DElD8M7P.svg",d="/c/assets/5.BE2mwvAQ.svg",r="/c/assets/6.aMDLQtj3.svg",c="/c/assets/7.eAeDlr0I.svg",E="/c/assets/8.CiYoL9Pa.svg",g="/c/assets/9.f3_OgcWU.svg",o="/c/assets/10.Dx5GM3xz.svg",F="/c/assets/11.DNH2vSdC.svg",y="/c/assets/12.NlBmD7pA.png",u="/c/assets/13.ZiBq6Pno.png",b="/c/assets/14.DAgmsf-w.png",m="/c/assets/15.B2iC37fw.png",C="/c/assets/16.BlE3ZFud.png",B="/c/assets/17.CBpay1zM.svg",A="/c/assets/18.g66usGgc.svg",D="/c/assets/19.BW4hoq9o.svg",v="/c/assets/20.DBXyt0gx.svg",T="/c/assets/21.QOjKI_7K.svg",Q="/c/assets/22.BPFvANo_.svg",f="/c/assets/23.BSJo8a0j.svg",q="/c/assets/24.r8ZG8Rvh.svg",_="/c/assets/25.rY0SPMAM.svg",x="/c/assets/26.CX-aIacs.svg",w="/c/assets/27.B6oI9aDx.svg",L="/c/assets/28.BK--PMbQ.svg",z="/c/assets/29.CJ87msb8.svg",H="/c/assets/30.CjsU-QJv.svg",P="/c/assets/31.s4BF2CMv.svg",M="/c/assets/32.DCGI6iJG.svg",N="/c/assets/33.C1jQxCuu.svg",I="/c/assets/35.CGTVELeO.png",V="/c/assets/36.Bz4_lEH0.gif",S="/c/assets/37.CcDWE4nn.png",U="/c/assets/38.B7y2_JVX.gif",O="/c/assets/39.Btcc3rs2.gif",Z="/c/assets/40.CR4ARW8y.png",R="/c/assets/39.Btcc3rs2.gif",G="/c/assets/42.DOX3ymYP.gif",j="/c/assets/43.Cie9_tkP.gif",J="/c/assets/44.DLjH9Ges.png",X="/c/assets/45.DhSh546m.gif",W="/c/assets/46.CCFwxiA0.gif",K="/c/assets/47.DCdP5ufU.gif",$="/c/assets/48.CjdgNuy4.gif",Y="/c/assets/49.Bg9sWT0a.gif",ss="/c/assets/50.Ma73wRvf.gif",is="/c/assets/51.rJLsU7Sw.gif",as="/c/assets/52.3DsEIiSv.gif",vs=JSON.parse('{"title":"第一章:数据类型(⭐)","description":"","frontmatter":{},"headers":[],"relativePath":"notes/01_c-basic/03_xdx/index.md","filePath":"notes/01_c-basic/03_xdx/index.md","lastUpdated":1724661257000}'),ns={name:"notes/01_c-basic/03_xdx/index.md"},ls=a("",105),ps={class:"MathJax",jax:"SVG",style:{direction:"ltr",position:"relative"}},ts={style:{overflow:"visible","min-height":"1px","min-width":"1px","vertical-align":"-0.912ex"},xmlns:"http://www.w3.org/2000/svg",width:"15.075ex",height:"2.893ex",role:"img",focusable:"false",viewBox:"0 -875.7 6663.1 1278.6","aria-hidden":"true"},hs=a("",1),es=[hs],ks=s("mjx-assistive-mml",{unselectable:"on",display:"inline",style:{top:"0px",left:"0px",clip:"rect(1px, 1px, 1px, 1px)","-webkit-touch-callout":"none","-webkit-user-select":"none","-khtml-user-select":"none","-moz-user-select":"none","-ms-user-select":"none","user-select":"none",position:"absolute",padding:"1px 0px 0px 0px",border:"0px",display:"block",width:"auto",overflow:"hidden"}},[s("math",{xmlns:"http://www.w3.org/1998/Math/MathML"},[s("msub",null,[s("mi",null,"S"),s("mi",null,"n")]),s("mo",null,"="),s("msub",null,[s("mi",null,"a"),s("mn",null,"1")]),s("mo",null,"×"),s("mfrac",null,[s("mrow",null,[s("mn",null,"1"),s("mo",null,""),s("msup",null,[s("mi",null,"r"),s("mi",null,"n")])]),s("mrow",null,[s("mn",null,"1"),s("mo",null,""),s("mi",null,"r")])])])],-1),ds={class:"MathJax",jax:"SVG",style:{direction:"ltr",position:"relative"}},rs={style:{overflow:"visible","min-height":"1px","min-width":"1px","vertical-align":"-0.912ex"},xmlns:"http://www.w3.org/2000/svg",width:"28.694ex",height:"3.146ex",role:"img",focusable:"false",viewBox:"0 -987.7 12682.9 1390.6","aria-hidden":"true"},cs=a("",1),Es=[cs],gs=s("mjx-assistive-mml",{unselectable:"on",display:"inline",style:{top:"0px",left:"0px",clip:"rect(1px, 1px, 1px, 1px)","-webkit-touch-callout":"none","-webkit-user-select":"none","-khtml-user-select":"none","-moz-user-select":"none","-ms-user-select":"none","user-select":"none",position:"absolute",padding:"1px 0px 0px 0px",border:"0px",display:"block",width:"auto",overflow:"hidden"}},[s("math",{xmlns:"http://www.w3.org/1998/Math/MathML"},[s("msub",null,[s("mi",null,"S"),s("mn",null,"8")]),s("mo",null,"="),s("mn",null,"1"),s("mo",null,"×"),s("mfrac",null,[s("mrow",null,[s("mn",null,"1"),s("mo",null,""),s("msup",null,[s("mn",null,"2"),s("mn",null,"8")])]),s("mrow",null,[s("mn",null,"1"),s("mo",null,""),s("mn",null,"2")])]),s("mo",null,"="),s("mfrac",null,[s("mrow",null,[s("mn",null,"1"),s("mo",null,""),s("mn",null,"256")]),s("mrow",null,[s("mo",null,""),s("mn",null,"1")])]),s("mo",null,"="),s("mn",null,"255")])],-1),os=s("li",null,[s("p",null,[i("但是,貌似还是很复杂,我们可以换个思路,就是让 "),s("code",null,"1111 1111"),i(" 先 "),s("code",null,"+1"),i(" ,然后再 "),s("code",null,"-1"),i(",这样一增一减正好抵消掉,并且不会影响最终的结果,如下所示:")])],-1),Fs=a("",309);function ys(us,bs,ms,Cs,Bs,As){return l(),n("div",null,[ls,s("p",null,[s("mjx-container",ps,[(l(),n("svg",ts,es)),ks])]),s("ul",null,[s("li",null,[s("p",null,[i("那么,结果就是:"),s("mjx-container",ds,[(l(),n("svg",rs,Es)),gs])])]),os]),Fs])}const Ts=p(ns,[["render",ys]]);export{vs as __pageData,Ts as default};
import{_ as p,c as n,j as s,a as i,a6 as a,o as l}from"./chunks/framework.hMCIpNYY.js";const t="/c/assets/1.L8V3GBrc.png",h="/c/assets/2.nqdAY_P3.png",e="/c/assets/3.D7eNbwzQ.jpg",k="/c/assets/4.DElD8M7P.svg",d="/c/assets/5.BE2mwvAQ.svg",r="/c/assets/6.aMDLQtj3.svg",c="/c/assets/7.eAeDlr0I.svg",E="/c/assets/8.CiYoL9Pa.svg",g="/c/assets/9.f3_OgcWU.svg",o="/c/assets/10.Dx5GM3xz.svg",F="/c/assets/11.DNH2vSdC.svg",y="/c/assets/12.NlBmD7pA.png",u="/c/assets/13.ZiBq6Pno.png",b="/c/assets/14.DAgmsf-w.png",m="/c/assets/15.B2iC37fw.png",C="/c/assets/16.BlE3ZFud.png",A="/c/assets/17.CBpay1zM.svg",B="/c/assets/18.g66usGgc.svg",D="/c/assets/19.BW4hoq9o.svg",v="/c/assets/20.DBXyt0gx.svg",T="/c/assets/21.QOjKI_7K.svg",Q="/c/assets/22.BPFvANo_.svg",q="/c/assets/23.BSJo8a0j.svg",f="/c/assets/24.r8ZG8Rvh.svg",_="/c/assets/25.rY0SPMAM.svg",x="/c/assets/26.CX-aIacs.svg",w="/c/assets/27.B6oI9aDx.svg",L="/c/assets/28.BK--PMbQ.svg",z="/c/assets/29.CJ87msb8.svg",H="/c/assets/30.CjsU-QJv.svg",I="/c/assets/31.s4BF2CMv.svg",U="/c/assets/32.DCGI6iJG.svg",P="/c/assets/33.C1jQxCuu.svg",N="/c/assets/35.CGTVELeO.png",M="/c/assets/36.Bz4_lEH0.gif",S="/c/assets/37.CcDWE4nn.png",V="/c/assets/38.B7y2_JVX.gif",O="/c/assets/39.Btcc3rs2.gif",Z="/c/assets/40.CR4ARW8y.png",R="/c/assets/39.Btcc3rs2.gif",G="/c/assets/42.DOX3ymYP.gif",j="/c/assets/43.Cie9_tkP.gif",J="/c/assets/44.DLjH9Ges.png",X="/c/assets/45.DhSh546m.gif",W="/c/assets/46.CCFwxiA0.gif",K="/c/assets/47.DCdP5ufU.gif",$="/c/assets/48.CjdgNuy4.gif",Y="/c/assets/49.Bg9sWT0a.gif",ss="/c/assets/50.Ma73wRvf.gif",is="/c/assets/51.rJLsU7Sw.gif",as="/c/assets/52.3DsEIiSv.gif",vs=JSON.parse('{"title":"第一章:数据类型(⭐)","description":"","frontmatter":{},"headers":[],"relativePath":"notes/01_c-basic/03_xdx/index.md","filePath":"notes/01_c-basic/03_xdx/index.md","lastUpdated":1724728274000}'),ns={name:"notes/01_c-basic/03_xdx/index.md"},ls=a("",105),ps={class:"MathJax",jax:"SVG",style:{direction:"ltr",position:"relative"}},ts={style:{overflow:"visible","min-height":"1px","min-width":"1px","vertical-align":"-0.912ex"},xmlns:"http://www.w3.org/2000/svg",width:"15.075ex",height:"2.893ex",role:"img",focusable:"false",viewBox:"0 -875.7 6663.1 1278.6","aria-hidden":"true"},hs=a("",1),es=[hs],ks=s("mjx-assistive-mml",{unselectable:"on",display:"inline",style:{top:"0px",left:"0px",clip:"rect(1px, 1px, 1px, 1px)","-webkit-touch-callout":"none","-webkit-user-select":"none","-khtml-user-select":"none","-moz-user-select":"none","-ms-user-select":"none","user-select":"none",position:"absolute",padding:"1px 0px 0px 0px",border:"0px",display:"block",width:"auto",overflow:"hidden"}},[s("math",{xmlns:"http://www.w3.org/1998/Math/MathML"},[s("msub",null,[s("mi",null,"S"),s("mi",null,"n")]),s("mo",null,"="),s("msub",null,[s("mi",null,"a"),s("mn",null,"1")]),s("mo",null,"×"),s("mfrac",null,[s("mrow",null,[s("mn",null,"1"),s("mo",null,""),s("msup",null,[s("mi",null,"r"),s("mi",null,"n")])]),s("mrow",null,[s("mn",null,"1"),s("mo",null,""),s("mi",null,"r")])])])],-1),ds={class:"MathJax",jax:"SVG",style:{direction:"ltr",position:"relative"}},rs={style:{overflow:"visible","min-height":"1px","min-width":"1px","vertical-align":"-0.912ex"},xmlns:"http://www.w3.org/2000/svg",width:"28.694ex",height:"3.146ex",role:"img",focusable:"false",viewBox:"0 -987.7 12682.9 1390.6","aria-hidden":"true"},cs=a("",1),Es=[cs],gs=s("mjx-assistive-mml",{unselectable:"on",display:"inline",style:{top:"0px",left:"0px",clip:"rect(1px, 1px, 1px, 1px)","-webkit-touch-callout":"none","-webkit-user-select":"none","-khtml-user-select":"none","-moz-user-select":"none","-ms-user-select":"none","user-select":"none",position:"absolute",padding:"1px 0px 0px 0px",border:"0px",display:"block",width:"auto",overflow:"hidden"}},[s("math",{xmlns:"http://www.w3.org/1998/Math/MathML"},[s("msub",null,[s("mi",null,"S"),s("mn",null,"8")]),s("mo",null,"="),s("mn",null,"1"),s("mo",null,"×"),s("mfrac",null,[s("mrow",null,[s("mn",null,"1"),s("mo",null,""),s("msup",null,[s("mn",null,"2"),s("mn",null,"8")])]),s("mrow",null,[s("mn",null,"1"),s("mo",null,""),s("mn",null,"2")])]),s("mo",null,"="),s("mfrac",null,[s("mrow",null,[s("mn",null,"1"),s("mo",null,""),s("mn",null,"256")]),s("mrow",null,[s("mo",null,""),s("mn",null,"1")])]),s("mo",null,"="),s("mn",null,"255")])],-1),os=s("li",null,[s("p",null,[i("但是,貌似还是很复杂,我们可以换个思路,就是让 "),s("code",null,"1111 1111"),i(" 先 "),s("code",null,"+1"),i(" ,然后再 "),s("code",null,"-1"),i(",这样一增一减正好抵消掉,并且不会影响最终的结果,如下所示:")])],-1),Fs=a("",324);function ys(us,bs,ms,Cs,As,Bs){return l(),n("div",null,[ls,s("p",null,[s("mjx-container",ps,[(l(),n("svg",ts,es)),ks])]),s("ul",null,[s("li",null,[s("p",null,[i("那么,结果就是:"),s("mjx-container",ds,[(l(),n("svg",rs,Es)),gs])])]),os]),Fs])}const Ts=p(ns,[["render",ys]]);export{vs as __pageData,Ts as default};

View File

@ -0,0 +1 @@
import{_ as e,c as t,o as a}from"./chunks/framework.hMCIpNYY.js";const p=JSON.parse('{"title":"","description":"","frontmatter":{},"headers":[],"relativePath":"notes/01_c-basic/04_xdx/index.md","filePath":"notes/01_c-basic/04_xdx/index.md","lastUpdated":1724728274000}'),s={name:"notes/01_c-basic/04_xdx/index.md"};function n(c,o,d,r,i,_){return a(),t("div")}const m=e(s,[["render",n]]);export{p as __pageData,m as default};

View File

@ -0,0 +1 @@
import{_ as e,c as t,o as a}from"./chunks/framework.hMCIpNYY.js";const p=JSON.parse('{"title":"","description":"","frontmatter":{},"headers":[],"relativePath":"notes/01_c-basic/04_xdx/index.md","filePath":"notes/01_c-basic/04_xdx/index.md","lastUpdated":1724728274000}'),s={name:"notes/01_c-basic/04_xdx/index.md"};function n(c,o,d,r,i,_){return a(),t("div")}const m=e(s,[["render",n]]);export{p as __pageData,m as default};

View File

@ -1,4 +1,4 @@
import{_ as l,c as a,j as s,a6 as i,o as n}from"./chunks/framework.hMCIpNYY.js";const p="/c/assets/1.CTMA-Poz.jpg",h="/c/assets/2.B2g4y1OY.png",k="/c/assets/3.DEoM0p3m.png",t="/c/assets/4.DxEoA7Ht.png",e="/c/assets/5.DtY5Pf6u.png",r="/c/assets/6.CButBugT.png",E="/c/assets/7.DG_I9X5w.png",d="/c/assets/8.Cw8LCRHN.png",g="/c/assets/9.TqkSPw2X.png",c="/c/assets/10.DJkVOkw7.png",y="/c/assets/11.Bkdbe2NL.png",F="/c/assets/12.D2yeCvfw.png",H=JSON.parse('{"title":"第一章:概述","description":"","frontmatter":{},"headers":[],"relativePath":"notes/01_c-basic/04_xdx/index.md","filePath":"notes/01_c-basic/04_xdx/index.md","lastUpdated":1722933158000}'),b={name:"notes/01_c-basic/04_xdx/index.md"},u=i('<h1 id="第一章-概述" tabindex="-1">第一章:概述 <a class="header-anchor" href="#第一章-概述" aria-label="Permalink to &quot;第一章:概述&quot;"></a></h1><ul><li><p><code>流程控制结构</code>是用来控制程序中<code>各语句执行顺序</code>的语句,并且可以将语句组合成能<code>完成一定功能</code>的<code>小逻辑模块</code>。</p></li><li><p>在程序设计中规定了<code>三种</code>流程结构,如下所示:</p><ul><li><code>顺序结构</code>:程序从上到下逐行执行,中间没有任何判断和跳转。</li><li><code>分支结构</code>:根据条件,有选择的执行某段代码。在 C 语言中,有 <code>if...else</code> 和 <code>switch...case</code> 两种分支语句。</li><li><code>循环结构</code>:根据循环条件,重复性的执行某段代码。在 C 语言中,有 <code>for</code>、<code>while</code>、<code>do...while</code> 三种循环结构。</li></ul></li><li><p>在生活中的<code>洗衣工厂</code>,就包含了上述的三种流程结构,如下所示:</p></li></ul><p><img src="'+p+'" alt="" loading="lazy"></p><h1 id="第二章-顺序结构" tabindex="-1">第二章:顺序结构 <a class="header-anchor" href="#第二章-顺序结构" aria-label="Permalink to &quot;第二章:顺序结构&quot;"></a></h1><h2 id="_2-1-概述" tabindex="-1">2.1 概述 <a class="header-anchor" href="#_2-1-概述" aria-label="Permalink to &quot;2.1 概述&quot;"></a></h2><ul><li>程序从上到下逐行地执行,表达式语句都是顺序执行的,并且上一行对某个变量的修改对下一行会产生影响。</li></ul><p><img src="'+h+`" alt="" loading="lazy"></p><h2 id="_2-2-应用示例" tabindex="-1">2.2 应用示例 <a class="header-anchor" href="#_2-2-应用示例" aria-label="Permalink to &quot;2.2 应用示例&quot;"></a></h2><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
import{_ as l,c as a,j as s,a6 as i,o as n}from"./chunks/framework.hMCIpNYY.js";const p="/c/assets/1.CTMA-Poz.jpg",h="/c/assets/2.B2g4y1OY.png",k="/c/assets/3.DEoM0p3m.png",t="/c/assets/4.DxEoA7Ht.png",e="/c/assets/5.DtY5Pf6u.png",r="/c/assets/6.CButBugT.png",E="/c/assets/7.DG_I9X5w.png",d="/c/assets/8.Cw8LCRHN.png",g="/c/assets/9.TqkSPw2X.png",c="/c/assets/10.DJkVOkw7.png",y="/c/assets/11.Bkdbe2NL.png",F="/c/assets/12.D2yeCvfw.png",H=JSON.parse('{"title":"第一章:概述","description":"","frontmatter":{},"headers":[],"relativePath":"notes/01_c-basic/05_xdx/index.md","filePath":"notes/01_c-basic/05_xdx/index.md","lastUpdated":1724728274000}'),b={name:"notes/01_c-basic/05_xdx/index.md"},u=i('<h1 id="第一章-概述" tabindex="-1">第一章:概述 <a class="header-anchor" href="#第一章-概述" aria-label="Permalink to &quot;第一章:概述&quot;"></a></h1><ul><li><p><code>流程控制结构</code>是用来控制程序中<code>各语句执行顺序</code>的语句,并且可以将语句组合成能<code>完成一定功能</code>的<code>小逻辑模块</code>。</p></li><li><p>在程序设计中规定了<code>三种</code>流程结构,如下所示:</p><ul><li><code>顺序结构</code>:程序从上到下逐行执行,中间没有任何判断和跳转。</li><li><code>分支结构</code>:根据条件,有选择的执行某段代码。在 C 语言中,有 <code>if...else</code> 和 <code>switch...case</code> 两种分支语句。</li><li><code>循环结构</code>:根据循环条件,重复性的执行某段代码。在 C 语言中,有 <code>for</code>、<code>while</code>、<code>do...while</code> 三种循环结构。</li></ul></li><li><p>在生活中的<code>洗衣工厂</code>,就包含了上述的三种流程结构,如下所示:</p></li></ul><p><img src="'+p+'" alt="" loading="lazy"></p><h1 id="第二章-顺序结构" tabindex="-1">第二章:顺序结构 <a class="header-anchor" href="#第二章-顺序结构" aria-label="Permalink to &quot;第二章:顺序结构&quot;"></a></h1><h2 id="_2-1-概述" tabindex="-1">2.1 概述 <a class="header-anchor" href="#_2-1-概述" aria-label="Permalink to &quot;2.1 概述&quot;"></a></h2><ul><li>程序从上到下逐行地执行,表达式语句都是顺序执行的,并且上一行对某个变量的修改对下一行会产生影响。</li></ul><p><img src="'+h+`" alt="" loading="lazy"></p><h2 id="_2-2-应用示例" tabindex="-1">2.2 应用示例 <a class="header-anchor" href="#_2-2-应用示例" aria-label="Permalink to &quot;2.2 应用示例&quot;"></a></h2><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>

View File

@ -1 +1 @@
import{_ as l,c as a,j as s,a6 as i,o as n}from"./chunks/framework.hMCIpNYY.js";const p="/c/assets/1.CTMA-Poz.jpg",h="/c/assets/2.B2g4y1OY.png",k="/c/assets/3.DEoM0p3m.png",t="/c/assets/4.DxEoA7Ht.png",e="/c/assets/5.DtY5Pf6u.png",r="/c/assets/6.CButBugT.png",E="/c/assets/7.DG_I9X5w.png",d="/c/assets/8.Cw8LCRHN.png",g="/c/assets/9.TqkSPw2X.png",c="/c/assets/10.DJkVOkw7.png",y="/c/assets/11.Bkdbe2NL.png",F="/c/assets/12.D2yeCvfw.png",H=JSON.parse('{"title":"第一章:概述","description":"","frontmatter":{},"headers":[],"relativePath":"notes/01_c-basic/04_xdx/index.md","filePath":"notes/01_c-basic/04_xdx/index.md","lastUpdated":1722933158000}'),b={name:"notes/01_c-basic/04_xdx/index.md"},u=i("",84),o={class:"MathJax",jax:"SVG",style:{direction:"ltr",position:"relative"}},m={style:{overflow:"visible","min-height":"1px","min-width":"1px","vertical-align":"-0.566ex"},xmlns:"http://www.w3.org/2000/svg",width:"28.71ex",height:"2.262ex",role:"img",focusable:"false",viewBox:"0 -750 12690 1000","aria-hidden":"true"},C=i("",1),B=[C],A=s("mjx-assistive-mml",{unselectable:"on",display:"inline",style:{top:"0px",left:"0px",clip:"rect(1px, 1px, 1px, 1px)","-webkit-touch-callout":"none","-webkit-user-select":"none","-khtml-user-select":"none","-moz-user-select":"none","-ms-user-select":"none","user-select":"none",position:"absolute",padding:"1px 0px 0px 0px",border:"0px",display:"block",width:"auto",overflow:"hidden"}},[s("math",{xmlns:"http://www.w3.org/1998/Math/MathML"},[s("msub",null,[s("mi",null,"X"),s("mrow",{"data-mjx-texclass":"ORD"},[s("mi",null,"n"),s("mo",null,"+"),s("mn",null,"1")])]),s("mo",null,"="),s("mo",{stretchy:"false"},"("),s("mi",null,"a"),s("mo",null,"⋅"),s("msub",null,[s("mi",null,"X"),s("mi",null,"n")]),s("mo",null,"+"),s("mi",null,"b"),s("mo",{stretchy:"false"},")"),s("mspace",{width:"0.667em"}),s("mi",null,"mod"),s("mstyle",{scriptlevel:"0"},[s("mspace",{width:"0.167em"})]),s("mstyle",{scriptlevel:"0"},[s("mspace",{width:"0.167em"})]),s("mi",null,"m")])],-1),D=i("",133);function v(q,f,Q,T,_,x){return n(),a("div",null,[u,s("p",null,[s("mjx-container",o,[(n(),a("svg",m,B)),A])]),D])}const P=l(b,[["render",v]]);export{H as __pageData,P as default};
import{_ as l,c as a,j as s,a6 as i,o as n}from"./chunks/framework.hMCIpNYY.js";const p="/c/assets/1.CTMA-Poz.jpg",h="/c/assets/2.B2g4y1OY.png",k="/c/assets/3.DEoM0p3m.png",t="/c/assets/4.DxEoA7Ht.png",e="/c/assets/5.DtY5Pf6u.png",r="/c/assets/6.CButBugT.png",E="/c/assets/7.DG_I9X5w.png",d="/c/assets/8.Cw8LCRHN.png",g="/c/assets/9.TqkSPw2X.png",c="/c/assets/10.DJkVOkw7.png",y="/c/assets/11.Bkdbe2NL.png",F="/c/assets/12.D2yeCvfw.png",H=JSON.parse('{"title":"第一章:概述","description":"","frontmatter":{},"headers":[],"relativePath":"notes/01_c-basic/05_xdx/index.md","filePath":"notes/01_c-basic/05_xdx/index.md","lastUpdated":1724728274000}'),b={name:"notes/01_c-basic/05_xdx/index.md"},u=i("",84),o={class:"MathJax",jax:"SVG",style:{direction:"ltr",position:"relative"}},m={style:{overflow:"visible","min-height":"1px","min-width":"1px","vertical-align":"-0.566ex"},xmlns:"http://www.w3.org/2000/svg",width:"28.71ex",height:"2.262ex",role:"img",focusable:"false",viewBox:"0 -750 12690 1000","aria-hidden":"true"},C=i("",1),B=[C],A=s("mjx-assistive-mml",{unselectable:"on",display:"inline",style:{top:"0px",left:"0px",clip:"rect(1px, 1px, 1px, 1px)","-webkit-touch-callout":"none","-webkit-user-select":"none","-khtml-user-select":"none","-moz-user-select":"none","-ms-user-select":"none","user-select":"none",position:"absolute",padding:"1px 0px 0px 0px",border:"0px",display:"block",width:"auto",overflow:"hidden"}},[s("math",{xmlns:"http://www.w3.org/1998/Math/MathML"},[s("msub",null,[s("mi",null,"X"),s("mrow",{"data-mjx-texclass":"ORD"},[s("mi",null,"n"),s("mo",null,"+"),s("mn",null,"1")])]),s("mo",null,"="),s("mo",{stretchy:"false"},"("),s("mi",null,"a"),s("mo",null,"⋅"),s("msub",null,[s("mi",null,"X"),s("mi",null,"n")]),s("mo",null,"+"),s("mi",null,"b"),s("mo",{stretchy:"false"},")"),s("mspace",{width:"0.667em"}),s("mi",null,"mod"),s("mstyle",{scriptlevel:"0"},[s("mspace",{width:"0.167em"})]),s("mstyle",{scriptlevel:"0"},[s("mspace",{width:"0.167em"})]),s("mi",null,"m")])],-1),D=i("",133);function v(q,f,Q,T,_,x){return n(),a("div",null,[u,s("p",null,[s("mjx-container",o,[(n(),a("svg",m,B)),A])]),D])}const P=l(b,[["render",v]]);export{H as __pageData,P as default};

View File

@ -1,4 +1,4 @@
import{_ as s,c as i,o as a,a6 as n}from"./chunks/framework.hMCIpNYY.js";const l="/c/assets/1.CvTjP5jN.png",p="/c/assets/2.BR4TvWzU.png",h="/c/assets/3.hr3pCY5b.png",k="/c/assets/4.CgvWfxq4.png",t="/c/assets/5.DSekQATc.png",e="/c/assets/6.DjtEKfCa.png",r="/c/assets/7.BTWPdsCm.png",E="/c/assets/8.EoNXwZXz.png",d="/c/assets/9.iU-LaFqX.png",g="/c/assets/10.DYoXU9E6.jpg",y="/c/assets/11.DWDH3yqc.png",F="/c/assets/12.BvBjpbbE.png",c="/c/assets/13.CmPe90qp.png",b="/c/assets/14.MepLJvOt.jpg",u="/c/assets/15.CZUo3kuI.png",C="/c/assets/16.t7xuKRuB.png",o="/c/assets/17.Bkm40EoU.png",m="/c/assets/18.D0Mtsawg.png",B="/c/assets/19.C-mmUOKp.png",A="/c/assets/20.BvSSXPdI.png",D="/c/assets/21.uaya_nVR.png",v="/c/assets/22.CA2ak30R.png",q="/c/assets/12.NlBmD7pA.png",f="/c/assets/24.QdyrLkbx.jpeg",_="/c/assets/25.wg7a3XFP.gif",x="/c/assets/26.M8jrrq2u.gif",z="/c/assets/27.BdWdvezm.png",P="/c/assets/28.C_QI84u9.svg",w="/c/assets/29.BB6sjxx5.svg",T="/c/assets/30.CHyA9Yy8.svg",N="/c/assets/4.DqDR6Thp.svg",O="/c/assets/32.3t5rXZRH.gif",j="/c/assets/33.BRUArxJK.jpg",S="/c/assets/34.DIXK93xX.jpg",I="/c/assets/35.Bvu6CpUv.gif",H="/c/assets/36.DHPPX3_T.gif",W="/c/assets/37.EU7nYUIS.svg",U="/c/assets/38.BMoE_Ep0.svg",Q=JSON.parse('{"title":"第一章:数组的概念","description":"","frontmatter":{},"headers":[],"relativePath":"notes/01_c-basic/05_xdx/index.md","filePath":"notes/01_c-basic/05_xdx/index.md","lastUpdated":1723430837000}'),Z={name:"notes/01_c-basic/05_xdx/index.md"},L=n(`<h1 id="第一章-数组的概念" tabindex="-1">第一章:数组的概念 <a class="header-anchor" href="#第一章-数组的概念" aria-label="Permalink to &quot;第一章:数组的概念&quot;"></a></h1><h2 id="_1-1-为什么需要数组" tabindex="-1">1.1 为什么需要数组? <a class="header-anchor" href="#_1-1-为什么需要数组" aria-label="Permalink to &quot;1.1 为什么需要数组?&quot;"></a></h2><h3 id="_1-1-1-需求分析-1" tabindex="-1">1.1.1 需求分析 1 <a class="header-anchor" href="#_1-1-1-需求分析-1" aria-label="Permalink to &quot;1.1.1 需求分析 1&quot;"></a></h3><ul><li>需要统计某公司 50 个员工的工资情况,例如:计算平均工资、最高工资等。如果使用之前的知识,我们需要声明 50 个变量来分别记录每位员工的工资,即:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
import{_ as s,c as i,o as a,a6 as n}from"./chunks/framework.hMCIpNYY.js";const l="/c/assets/1.CvTjP5jN.png",p="/c/assets/2.BR4TvWzU.png",h="/c/assets/3.hr3pCY5b.png",k="/c/assets/4.CgvWfxq4.png",t="/c/assets/5.DSekQATc.png",e="/c/assets/6.DjtEKfCa.png",r="/c/assets/7.BTWPdsCm.png",E="/c/assets/8.EoNXwZXz.png",d="/c/assets/9.iU-LaFqX.png",g="/c/assets/10.DYoXU9E6.jpg",y="/c/assets/11.DWDH3yqc.png",F="/c/assets/12.BvBjpbbE.png",c="/c/assets/13.CmPe90qp.png",b="/c/assets/14.MepLJvOt.jpg",u="/c/assets/15.CZUo3kuI.png",C="/c/assets/16.t7xuKRuB.png",o="/c/assets/17.Bkm40EoU.png",m="/c/assets/18.D0Mtsawg.png",B="/c/assets/19.C-mmUOKp.png",A="/c/assets/20.BvSSXPdI.png",D="/c/assets/21.uaya_nVR.png",v="/c/assets/22.CA2ak30R.png",q="/c/assets/12.NlBmD7pA.png",f="/c/assets/24.QdyrLkbx.jpeg",_="/c/assets/25.wg7a3XFP.gif",x="/c/assets/26.M8jrrq2u.gif",z="/c/assets/27.BdWdvezm.png",P="/c/assets/28.C_QI84u9.svg",w="/c/assets/29.BB6sjxx5.svg",T="/c/assets/30.CHyA9Yy8.svg",N="/c/assets/4.DqDR6Thp.svg",O="/c/assets/32.3t5rXZRH.gif",j="/c/assets/33.BRUArxJK.jpg",S="/c/assets/34.DIXK93xX.jpg",I="/c/assets/35.Bvu6CpUv.gif",H="/c/assets/36.DHPPX3_T.gif",W="/c/assets/37.EU7nYUIS.svg",U="/c/assets/38.BMoE_Ep0.svg",Q=JSON.parse('{"title":"第一章:数组的概念","description":"","frontmatter":{},"headers":[],"relativePath":"notes/01_c-basic/06_xdx/index.md","filePath":"notes/01_c-basic/06_xdx/index.md","lastUpdated":1724728274000}'),Z={name:"notes/01_c-basic/06_xdx/index.md"},L=n(`<h1 id="第一章-数组的概念" tabindex="-1">第一章:数组的概念 <a class="header-anchor" href="#第一章-数组的概念" aria-label="Permalink to &quot;第一章:数组的概念&quot;"></a></h1><h2 id="_1-1-为什么需要数组" tabindex="-1">1.1 为什么需要数组? <a class="header-anchor" href="#_1-1-为什么需要数组" aria-label="Permalink to &quot;1.1 为什么需要数组?&quot;"></a></h2><h3 id="_1-1-1-需求分析-1" tabindex="-1">1.1.1 需求分析 1 <a class="header-anchor" href="#_1-1-1-需求分析-1" aria-label="Permalink to &quot;1.1.1 需求分析 1&quot;"></a></h3><ul><li>需要统计某公司 50 个员工的工资情况,例如:计算平均工资、最高工资等。如果使用之前的知识,我们需要声明 50 个变量来分别记录每位员工的工资,即:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(){</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>

View File

@ -1 +1 @@
import{_ as s,c as i,o as a,a6 as n}from"./chunks/framework.hMCIpNYY.js";const l="/c/assets/1.CvTjP5jN.png",p="/c/assets/2.BR4TvWzU.png",h="/c/assets/3.hr3pCY5b.png",k="/c/assets/4.CgvWfxq4.png",t="/c/assets/5.DSekQATc.png",e="/c/assets/6.DjtEKfCa.png",r="/c/assets/7.BTWPdsCm.png",E="/c/assets/8.EoNXwZXz.png",d="/c/assets/9.iU-LaFqX.png",g="/c/assets/10.DYoXU9E6.jpg",y="/c/assets/11.DWDH3yqc.png",F="/c/assets/12.BvBjpbbE.png",c="/c/assets/13.CmPe90qp.png",b="/c/assets/14.MepLJvOt.jpg",u="/c/assets/15.CZUo3kuI.png",C="/c/assets/16.t7xuKRuB.png",o="/c/assets/17.Bkm40EoU.png",m="/c/assets/18.D0Mtsawg.png",B="/c/assets/19.C-mmUOKp.png",A="/c/assets/20.BvSSXPdI.png",D="/c/assets/21.uaya_nVR.png",v="/c/assets/22.CA2ak30R.png",q="/c/assets/12.NlBmD7pA.png",f="/c/assets/24.QdyrLkbx.jpeg",_="/c/assets/25.wg7a3XFP.gif",x="/c/assets/26.M8jrrq2u.gif",z="/c/assets/27.BdWdvezm.png",P="/c/assets/28.C_QI84u9.svg",w="/c/assets/29.BB6sjxx5.svg",T="/c/assets/30.CHyA9Yy8.svg",N="/c/assets/4.DqDR6Thp.svg",O="/c/assets/32.3t5rXZRH.gif",j="/c/assets/33.BRUArxJK.jpg",S="/c/assets/34.DIXK93xX.jpg",I="/c/assets/35.Bvu6CpUv.gif",H="/c/assets/36.DHPPX3_T.gif",W="/c/assets/37.EU7nYUIS.svg",U="/c/assets/38.BMoE_Ep0.svg",Q=JSON.parse('{"title":"第一章:数组的概念","description":"","frontmatter":{},"headers":[],"relativePath":"notes/01_c-basic/05_xdx/index.md","filePath":"notes/01_c-basic/05_xdx/index.md","lastUpdated":1723430837000}'),Z={name:"notes/01_c-basic/05_xdx/index.md"},L=n("",251),R=[L];function J(M,G,X,K,V,Y){return a(),i("div",null,R)}const ss=s(Z,[["render",J]]);export{Q as __pageData,ss as default};
import{_ as s,c as i,o as a,a6 as n}from"./chunks/framework.hMCIpNYY.js";const l="/c/assets/1.CvTjP5jN.png",p="/c/assets/2.BR4TvWzU.png",h="/c/assets/3.hr3pCY5b.png",k="/c/assets/4.CgvWfxq4.png",t="/c/assets/5.DSekQATc.png",e="/c/assets/6.DjtEKfCa.png",r="/c/assets/7.BTWPdsCm.png",E="/c/assets/8.EoNXwZXz.png",d="/c/assets/9.iU-LaFqX.png",g="/c/assets/10.DYoXU9E6.jpg",y="/c/assets/11.DWDH3yqc.png",F="/c/assets/12.BvBjpbbE.png",c="/c/assets/13.CmPe90qp.png",b="/c/assets/14.MepLJvOt.jpg",u="/c/assets/15.CZUo3kuI.png",C="/c/assets/16.t7xuKRuB.png",o="/c/assets/17.Bkm40EoU.png",m="/c/assets/18.D0Mtsawg.png",B="/c/assets/19.C-mmUOKp.png",A="/c/assets/20.BvSSXPdI.png",D="/c/assets/21.uaya_nVR.png",v="/c/assets/22.CA2ak30R.png",q="/c/assets/12.NlBmD7pA.png",f="/c/assets/24.QdyrLkbx.jpeg",_="/c/assets/25.wg7a3XFP.gif",x="/c/assets/26.M8jrrq2u.gif",z="/c/assets/27.BdWdvezm.png",P="/c/assets/28.C_QI84u9.svg",w="/c/assets/29.BB6sjxx5.svg",T="/c/assets/30.CHyA9Yy8.svg",N="/c/assets/4.DqDR6Thp.svg",O="/c/assets/32.3t5rXZRH.gif",j="/c/assets/33.BRUArxJK.jpg",S="/c/assets/34.DIXK93xX.jpg",I="/c/assets/35.Bvu6CpUv.gif",H="/c/assets/36.DHPPX3_T.gif",W="/c/assets/37.EU7nYUIS.svg",U="/c/assets/38.BMoE_Ep0.svg",Q=JSON.parse('{"title":"第一章:数组的概念","description":"","frontmatter":{},"headers":[],"relativePath":"notes/01_c-basic/06_xdx/index.md","filePath":"notes/01_c-basic/06_xdx/index.md","lastUpdated":1724728274000}'),Z={name:"notes/01_c-basic/06_xdx/index.md"},L=n("",251),R=[L];function J(M,G,X,K,V,Y){return a(),i("div",null,R)}const ss=s(Z,[["render",J]]);export{Q as __pageData,ss as default};

View File

@ -1,4 +1,4 @@
import{_ as s,c as i,o as a,a6 as n}from"./chunks/framework.hMCIpNYY.js";const t="/c/assets/1.L8V3GBrc.png",l="/c/assets/2.CdvhiwcU.png",e="/c/assets/3.D74t3-Xt.png",d="/c/assets/4.DqDR6Thp.svg",p="/c/assets/5.BzSkS-4w.svg",h="/c/assets/6.BPY9ZGed.svg",C=JSON.parse('{"title":"第一章:颇具争议的指针","description":"","frontmatter":{},"headers":[],"relativePath":"notes/01_c-basic/06_xdx/index.md","filePath":"notes/01_c-basic/06_xdx/index.md","lastUpdated":1723516792000}'),k={name:"notes/01_c-basic/06_xdx/index.md"},r=n('<div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li>① <code>指针</code>是 C 语言中<code>最重要</code>的概念之一,也是<code>最难以理解</code>的概念之一。</li><li>② <code>指针</code>是 C 语言的<code>精髓</code>,要想掌握 C 语言就需要深入地了解指针。</li></ul></div><h1 id="第一章-颇具争议的指针" tabindex="-1">第一章:颇具争议的指针 <a class="header-anchor" href="#第一章-颇具争议的指针" aria-label="Permalink to &quot;第一章:颇具争议的指针&quot;"></a></h1><h2 id="_1-1-概述" tabindex="-1">1.1 概述 <a class="header-anchor" href="#_1-1-概述" aria-label="Permalink to &quot;1.1 概述&quot;"></a></h2><ul><li>目前而言,操作系统几乎都是通过 C 语言来编写和维护的;而 C 语言提供了指针的用法,其能直接操作内存地址,是个非常<code>强大</code>和<code>灵活</code>的工具;但是,需要开发者<code>小心谨慎的使用</code>,以确保程序的稳定性和安全性。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>之所以指针在 C 语言中颇具争议,是因为一方面其功能强大,直接操作内存地址;另一方面,又很危险,不正确的使用指针的方式,非常容易导致程序崩溃。</p></div><ul><li><p>如果没有能很好的使用指针,就会带来一系列的问题,如:</p><ul><li>① <code>空指针引用</code>Null Pointer Dereference当一个指针没有正确初始化或者被赋予了空NULL值时如果程序尝试访问该指针所指向的内存会导致运行时错误甚至导致程序崩溃。</li><li>② <code>野指针</code>Dangling Pointers指针指向的内存地址曾经分配给某个变量或对象但后来该变量或对象被释放或者移动导致指针仍指向已经无效的内存位置。对野指针进行操作可能会导致未定义的行为或程序崩溃。</li><li>③ <code>指针算术错误</code>:在进行指针运算时,如果没有正确管理指针的偏移量或者超出了数组的边界,可能会导致指针指向错误的内存位置,从而影响程序的正确性和安全性。</li><li>④ <code>内存泄漏</code>:如果动态分配的内存通过指针分配,但在不再需要时没有正确释放,会导致内存泄漏,长时间运行的程序可能会耗尽系统资源。</li></ul></li><li><p>为了减少指针带来的风险,开发人员可以采取以下的措施:</p><ul><li>① <code>良好的编程实践</code>:确保指针的初始化和使用是安全的,避免空指针引用和野指针问题。</li><li>② <code>边界检查</code>:在进行指针运算时,始终确保不会超出数组或内存分配的边界。</li><li>③ <code>使用指针和引用的适当性</code>:在可能的情况下,可以考虑使用更安全的语言特性,如:引用(在 C++ 等编程语言中)或者更高级别的数据结构来代替裸指针,从而减少指针使用时的潜在风险。</li></ul></li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li>① 既然指针很危险那么通过一系列的手段将指针包装或屏蔽以达到程序安全的目的这是现代化的高级编程语言解决的思路Java、Go、Rust 等)。</li><li>② 之所以指针还需要学习是因为在嵌入式等领域其机器的资源CPU、内存等非常有限而现代化的高级编程语言虽然安全但是需要的系统资源也庞大。</li><li>③ 我们知道编译型的程序不管编译过程如何复杂至少需要两步编译和运行。通常我们也将这两步称为编译期和运行期。C 语言中的指针之所以危险就在于程序要在运行的时候才会发现问题(后知后觉);而现代化的高级编程语言中的编译器在程序编译的时候就会发现问题(提前发现问题)。</li><li>④ C 语言的编译器之所以这么设计的原因,就在于当时的内存和 CPU 是非常有限PDP-7 早期小型计算机CPU18 bit 的电子管逻辑内存4kb 和昂贵72,000 $),如果加入安全限制的功能,会远远超过整个系统的资源。</li></ul></div><h2 id="_1-2-现代化高级编程语言是如何解决指针危险的" tabindex="-1">1.2 现代化高级编程语言是如何解决指针危险的? <a class="header-anchor" href="#_1-2-现代化高级编程语言是如何解决指针危险的" aria-label="Permalink to &quot;1.2 现代化高级编程语言是如何解决指针危险的?&quot;"></a></h2><ul><li><p><code>C++</code>采用了如下的策略和机制,来解决指针危险操作的:</p><ul><li>① <code>智能指针</code> C++ 引入了智能指针(如<code>std::shared_ptr</code>、<code>std::unique_ptr</code>),这些指针提供了自动资源管理和所有权的语义。<code>std::unique_ptr</code>确保只有一个指针可以访问给定的资源,从而避免了传统指针的悬空引用和内存泄漏问题。<code>std::shared_ptr</code>允许多个指针共享一个资源,并在所有引用释放后自动释放。</li><li>② <code>引用</code> C++ 中的引用(如:<code>&amp;</code>符号)提供了更安全的间接访问方法,与指针相比,引用不能重新绑定到不同的对象,从而减少了意外的指针错误。</li></ul></li><li><p><code>Go</code>采用了如下的策略和机制,来解决指针危险操作的:</p><ul><li>① <code>内存管理和垃圾回收</code> Go 语言通过自动垃圾回收器管理内存减少了手动内存管理所带来的指针操作错误。Go 的垃圾回收器定期扫描并释放不再使用的内存,避免了内存泄漏和悬空指针问题。</li><li>② <code>指针的安全性</code> Go 语言的指针是受限的,不支持指针运算,从而减少了指针操作可能带来的风险。</li></ul></li><li><p><code>Rust</code>采用了如下的策略和机制,来解决指针危险操作的:</p><ul><li>① <code>所有权和借用</code> Rust 引入了所有权和借用的概念,编译器在编译时静态分析所有权转移和引用的生命周期。这种机制避免了数据竞争和空指针解引用等运行时错误,使得在编译时就能够保证内存安全。</li><li>② <code>生命周期</code> Rust 的生命周期系统确保引用的有效性和安全性,防止了悬空引用和指针乱用。</li></ul></li><li><p><code>Java</code>采用了如下的策略和机制,来解决指针危险操作的:</p><ul><li>① <code>引用类型和自动内存管理</code> Java 中所有的对象引用都是通过引用来访问的而不是直接的指针。Java 的自动垃圾回收器负责管理内存,从而避免了手动内存管理可能导致的指针错误,如:内存泄漏和悬空指针。</li><li>② <code>强类型系统和异常处理</code> Java 的强类型系统和异常处理机制减少了指针操作带来的风险空指针解引用异常NullPointerException。编译器在编译时能够捕获许多潜在的类型错误进一步增强了程序的安全性和可靠性。</li></ul></li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p>总而言之,各种编程语言通过引入不同的策略和机制,如:智能指针、垃圾回收器、所有权和借用,以及强类型系统,有效地减少了指针操作所带来的各种安全性和可靠性问题,提升了程序的稳定性和开发效率。</p></div><h1 id="第二章-回顾知识" tabindex="-1">第二章:回顾知识 <a class="header-anchor" href="#第二章-回顾知识" aria-label="Permalink to &quot;第二章:回顾知识&quot;"></a></h1><h2 id="_2-1-变量" tabindex="-1">2.1 变量 <a class="header-anchor" href="#_2-1-变量" aria-label="Permalink to &quot;2.1 变量&quot;"></a></h2><ul><li>变量就是保存程序运行过程中临时产生的值,其语法如下:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">数据类型 变量名 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 值 ;</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p>变量名(标识符)需要符合命名规则和命名规范!!!</p><ul><li>强制规范: <ul><li>① 只能由<code>小写</code>或<code>大写英文字母</code><code>0-9</code> 或 <code>_</code> 组成。</li><li>② 不能以<code>数字</code>开头。</li><li>③ 不可以是<code>关键字</code>。</li><li>④ 标识符具有<code>长度</code>限制,不同编译器和平台会有所不同,一般限制在 63 个字符内。</li><li>⑤ 严格<code>区分大小写字母</code>Hello、hello 是不同的标识符。</li></ul></li><li>建议规范: <ul><li>① 为了提高阅读性使用有意义的单词见名知意sumnamemaxyear 等。</li><li>② 使用下划线连接多个单词组成的标识符max_classes_per_student 等。</li><li>③ 多个单词组成的标识符,除了使用下划线连接,也可以使用小驼峰命名法,除第一个单词外,后续单词的首字母大写,如: studentId、student_name 等。</li><li>④ 不要出现仅靠大小写区分不同的标识符name、Name 容易混淆。</li><li>⑤ 系统内部使用了一些下划线开头的标识符C99 标准添加的类型 <code>_Bool</code>,为防止冲突,建议开发者尽量避免使用下划线开头的标识符。</li></ul></li></ul></div><ul><li><code>变量名</code>的<code>作用</code>,如下所示: <ul><li>① 当我们<code>编写</code>代码的时候,使用<code>变量名</code>来<code>关联</code>某块内存的<code>地址</code>。</li><li>② 当 CPU <code>执行</code>的时候,会将变量名<code>替换</code>为具体的地址,再进行具体的操作。</li></ul></li></ul><h2 id="_2-2-普通变量和指针变量的区别" tabindex="-1">2.2 普通变量和指针变量的区别 <a class="header-anchor" href="#_2-2-普通变量和指针变量的区别" aria-label="Permalink to &quot;2.2 普通变量和指针变量的区别&quot;"></a></h2><ul><li>根据<code>变量</code>中<code>存储</code>的<code>值</code>的<code>不同</code>,我们可以将<code>变量</code>分为两类: <ul><li><code>普通变量</code>:变量所对应的内存中存储的是<code>普通值</code>。</li><li><code>指针变量</code>:变量所对应的内存中存储的是<code>另一个变量的地址</code>。</li></ul></li><li>如下图所示:</li></ul><p><img src="'+t+'" alt="img" loading="lazy"></p><ul><li>普通变量和指针变量的相同点,如下所示: <ul><li>① 普通变量有内存空间,指针变量也有内存空间。</li><li>② 普通变量有内存地址,指针变量也有内存地址。</li><li>③ 普通变量所对应的内存空间中有值,指针变量所对应的内存空间中也有值。</li></ul></li><li>普通变量和指针变量的不同点: <ul><li>① <code>普通变量</code>所对应的内存空间<code>存储</code>的是<code>普通的值</code>,如:整数、小数、字符等;<code>指针变量</code>所对应的内存空间<code>存储</code>的是另外一个变量的<code>地址</code>。</li><li>② <code>普通变量有普通变量的运算方式</code>,而<code>指针变量有指针变量的运算方式</code>(后续讲解)。</li></ul></li></ul><h2 id="_2-3-运算符" tabindex="-1">2.3 运算符 <a class="header-anchor" href="#_2-3-运算符" aria-label="Permalink to &quot;2.3 运算符&quot;"></a></h2><h3 id="_2-3-1-概述" tabindex="-1">2.3.1 概述 <a class="header-anchor" href="#_2-3-1-概述" aria-label="Permalink to &quot;2.3.1 概述&quot;"></a></h3><ul><li>运算符是一种特殊的符号,用于数据的运算、赋值和比较等。</li><li><code>表达式</code>指的是一组运算数、运算符的组合,表达式<code>一定具有值</code>,一个变量或一个常量可以是表达式,变量、常量和运算符也可以组成表达式,如:</li></ul><p><img src="'+l+'" alt="img" loading="lazy"></p><ul><li><code>操作数</code>指的是<code>参与运算</code>的<code>值</code>或者<code>对象</code>,如:</li></ul><p><img src="'+e+`" alt="" loading="lazy"></p><ul><li>根据<code>操作数</code>的<code>个数</code>,可以将运算符分为: <ul><li>一元运算符(一目运算符)。</li><li>二元运算符(二目运算符)。</li><li>三元运算符(三目运算符)。</li></ul></li><li>根据<code>功能</code>,可以将运算符分为: <ul><li>算术运算符。</li><li>关系运算符(比较运算符)。</li><li>逻辑运算符。</li><li>赋值运算符。</li><li>逻辑运算符。</li><li>位运算符。</li><li>三元运算符。</li></ul></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>掌握一个运算符,需要关注以下几个方面:</p><ul><li>① 运算符的含义。</li><li>② 运算符操作数的个数。</li><li>③ 运算符所组成的表达式。</li><li>④ 运算符有无副作用,即:运算后是否会修改操作数的值。</li></ul></div><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p>普通变量支持上述的所有运算符;而指针变量并非支持上述的所有运算符,且支持运算符的含义和普通变量相差较大!!!</p></div><h3 id="_2-3-2-运算符的优先级" tabindex="-1">2.3.2 运算符的优先级 <a class="header-anchor" href="#_2-3-2-运算符的优先级" aria-label="Permalink to &quot;2.3.2 运算符的优先级&quot;"></a></h3><ul><li>C 语言中运算符的优先级,如下所示:</li></ul><table tabindex="0"><thead><tr><th><strong>优先级</strong></th><th><strong>运算符</strong></th><th><strong>名称或含义</strong></th><th><strong>结合方向</strong></th></tr></thead><tbody><tr><td><strong>1</strong></td><td><code>[]</code></td><td>数组下标</td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>()</code></td><td>圆括号</td><td></td></tr><tr><td></td><td><code>.</code></td><td>成员选择(对象)</td><td></td></tr><tr><td></td><td><code>-&gt;</code></td><td>成员选择(指针)</td><td></td></tr><tr><td><strong>2</strong></td><td><code>-</code></td><td>负号运算符</td><td>⬅️(从右到左)</td></tr><tr><td></td><td><code>(类型)</code></td><td>强制类型转换</td><td></td></tr><tr><td></td><td><code>++</code></td><td>自增运算符</td><td></td></tr><tr><td></td><td><code>--</code></td><td>自减运算符</td><td></td></tr><tr><td></td><td><code>*</code></td><td>取值运算符</td><td></td></tr><tr><td></td><td><code>&amp;</code></td><td>取地址运算符</td><td></td></tr><tr><td></td><td><code>!</code></td><td>逻辑非运算符</td><td></td></tr><tr><td></td><td><code>~</code></td><td>按位取反运算符</td><td></td></tr><tr><td></td><td><code>sizeof</code></td><td>长度运算符</td><td></td></tr><tr><td><strong>3</strong></td><td><code>/</code></td><td>除</td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>*</code></td><td>乘</td><td></td></tr><tr><td></td><td><code>%</code></td><td>余数(取模)</td><td></td></tr><tr><td><strong>4</strong></td><td><code>+</code></td><td>加</td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>-</code></td><td>减</td><td></td></tr><tr><td><strong>5</strong></td><td><code>&lt;&lt;</code></td><td>左移</td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>&gt;&gt;</code></td><td>右移</td><td></td></tr><tr><td><strong>6</strong></td><td><code>&gt;</code></td><td>大于</td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>&gt;=</code></td><td>大于等于</td><td></td></tr><tr><td></td><td><code>&lt;</code></td><td>小于</td><td></td></tr><tr><td></td><td><code>&lt;=</code></td><td>小于等于</td><td></td></tr><tr><td><strong>7</strong></td><td><code>==</code></td><td>等于</td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>!=</code></td><td>不等于</td><td></td></tr><tr><td><strong>8</strong></td><td><code>&amp;</code></td><td>按位与</td><td>➡️(从左到右)</td></tr><tr><td><strong>9</strong></td><td><code>^</code></td><td>按位异或</td><td>➡️(从左到右)</td></tr><tr><td><strong>10</strong></td><td><code>|</code></td><td>按位或</td><td>➡️(从左到右)</td></tr><tr><td><strong>11</strong></td><td><code>&amp;&amp;</code></td><td>逻辑与</td><td>➡️(从左到右)</td></tr><tr><td><strong>12</strong></td><td><code>||</code></td><td>逻辑或</td><td>➡️(从左到右)</td></tr><tr><td><strong>13</strong></td><td><code>?:</code></td><td>条件运算符</td><td>⬅️(从右到左)</td></tr><tr><td><strong>14</strong></td><td><code>=</code></td><td>赋值运算符</td><td>⬅️(从右到左)</td></tr><tr><td></td><td><code>/=</code></td><td>除后赋值</td><td></td></tr><tr><td></td><td><code>*=</code></td><td>乘后赋值</td><td></td></tr><tr><td></td><td><code>%=</code></td><td>取模后赋值</td><td></td></tr><tr><td></td><td><code>+=</code></td><td>加后赋值</td><td></td></tr><tr><td></td><td><code>-=</code></td><td>减后赋值</td><td></td></tr><tr><td></td><td><code>&lt;&lt;=</code></td><td>左移后赋值</td><td></td></tr><tr><td></td><td><code>&gt;&gt;=</code></td><td>右移后赋值</td><td></td></tr><tr><td></td><td><code>&amp;=</code></td><td>按位与后赋值</td><td></td></tr><tr><td></td><td><code>^=</code></td><td>按位异或后赋值</td><td></td></tr><tr><td></td><td><code>|=</code></td><td>按位或后赋值</td><td></td></tr><tr><td><strong>15</strong></td><td><code>,</code></td><td>逗号运算符</td><td>➡️(从左到右)</td></tr></tbody></table><div class="warning custom-block github-alert"><p class="custom-block-title">WARNING</p><p></p><ul><li>① 不要过多的依赖运算符的优先级来控制表达式的执行顺序,这样可读性太差,尽量<code>使用小括号来控制</code>表达式的执行顺序。</li><li>② 不要把一个表达式写得过于复杂,如果一个表达式过于复杂,则把它<code>分成几步</code>来完成。</li><li>③ 运算符优先级不用刻意地去记忆,总体上:一元运算符 &gt; 算术运算符 &gt; 关系运算符 &gt; 逻辑运算符 &gt; 三元运算符 &gt; 赋值运算符。</li></ul></div><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li>① 取值运算符 <code>*</code> 和取地址运算符 <code>&amp;</code> 的优先级相同,并且运算方向都是从右向左!!!</li><li>② 逗号运算符 <code>,</code> 的优先级最低,并且运算方向是从左向右!!!</li></ul></div><h1 id="第三章-指针的理解和定义-⭐" tabindex="-1">第三章:指针的理解和定义(⭐) <a class="header-anchor" href="#第三章-指针的理解和定义-⭐" aria-label="Permalink to &quot;第三章:指针的理解和定义(⭐)&quot;"></a></h1><h2 id="_3-1-变量的访问方式" tabindex="-1">3.1 变量的访问方式 <a class="header-anchor" href="#_3-1-变量的访问方式" aria-label="Permalink to &quot;3.1 变量的访问方式&quot;"></a></h2><ul><li>计算机中程序的运行都是在内存中进行的变量也是内存中分配的空间且不同类型的变量占据的内存空间大小不同char 类型的变量是 1 个字节short 类型的变量是 2 个字节int 类型的变量是 4 个字节...</li><li>之前我们都是通过<code>变量名(普通变量)</code>访问内存中存储的数据,如下所示:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
import{_ as s,c as i,o as a,a6 as n}from"./chunks/framework.hMCIpNYY.js";const t="/c/assets/1.L8V3GBrc.png",l="/c/assets/2.CdvhiwcU.png",e="/c/assets/3.D74t3-Xt.png",d="/c/assets/4.DqDR6Thp.svg",p="/c/assets/5.BzSkS-4w.svg",h="/c/assets/6.BPY9ZGed.svg",C=JSON.parse('{"title":"第一章:颇具争议的指针","description":"","frontmatter":{},"headers":[],"relativePath":"notes/01_c-basic/07_xdx/index.md","filePath":"notes/01_c-basic/07_xdx/index.md","lastUpdated":1724728274000}'),k={name:"notes/01_c-basic/07_xdx/index.md"},r=n('<div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li>① <code>指针</code>是 C 语言中<code>最重要</code>的概念之一,也是<code>最难以理解</code>的概念之一。</li><li>② <code>指针</code>是 C 语言的<code>精髓</code>,要想掌握 C 语言就需要深入地了解指针。</li></ul></div><h1 id="第一章-颇具争议的指针" tabindex="-1">第一章:颇具争议的指针 <a class="header-anchor" href="#第一章-颇具争议的指针" aria-label="Permalink to &quot;第一章:颇具争议的指针&quot;"></a></h1><h2 id="_1-1-概述" tabindex="-1">1.1 概述 <a class="header-anchor" href="#_1-1-概述" aria-label="Permalink to &quot;1.1 概述&quot;"></a></h2><ul><li>目前而言,操作系统几乎都是通过 C 语言来编写和维护的;而 C 语言提供了指针的用法,其能直接操作内存地址,是个非常<code>强大</code>和<code>灵活</code>的工具;但是,需要开发者<code>小心谨慎的使用</code>,以确保程序的稳定性和安全性。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>之所以指针在 C 语言中颇具争议,是因为一方面其功能强大,直接操作内存地址;另一方面,又很危险,不正确的使用指针的方式,非常容易导致程序崩溃。</p></div><ul><li><p>如果没有能很好的使用指针,就会带来一系列的问题,如:</p><ul><li>① <code>空指针引用</code>Null Pointer Dereference当一个指针没有正确初始化或者被赋予了空NULL值时如果程序尝试访问该指针所指向的内存会导致运行时错误甚至导致程序崩溃。</li><li>② <code>野指针</code>Dangling Pointers指针指向的内存地址曾经分配给某个变量或对象但后来该变量或对象被释放或者移动导致指针仍指向已经无效的内存位置。对野指针进行操作可能会导致未定义的行为或程序崩溃。</li><li>③ <code>指针算术错误</code>:在进行指针运算时,如果没有正确管理指针的偏移量或者超出了数组的边界,可能会导致指针指向错误的内存位置,从而影响程序的正确性和安全性。</li><li>④ <code>内存泄漏</code>:如果动态分配的内存通过指针分配,但在不再需要时没有正确释放,会导致内存泄漏,长时间运行的程序可能会耗尽系统资源。</li></ul></li><li><p>为了减少指针带来的风险,开发人员可以采取以下的措施:</p><ul><li>① <code>良好的编程实践</code>:确保指针的初始化和使用是安全的,避免空指针引用和野指针问题。</li><li>② <code>边界检查</code>:在进行指针运算时,始终确保不会超出数组或内存分配的边界。</li><li>③ <code>使用指针和引用的适当性</code>:在可能的情况下,可以考虑使用更安全的语言特性,如:引用(在 C++ 等编程语言中)或者更高级别的数据结构来代替裸指针,从而减少指针使用时的潜在风险。</li></ul></li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li>① 既然指针很危险那么通过一系列的手段将指针包装或屏蔽以达到程序安全的目的这是现代化的高级编程语言解决的思路Java、Go、Rust 等)。</li><li>② 之所以指针还需要学习是因为在嵌入式等领域其机器的资源CPU、内存等非常有限而现代化的高级编程语言虽然安全但是需要的系统资源也庞大。</li><li>③ 我们知道编译型的程序不管编译过程如何复杂至少需要两步编译和运行。通常我们也将这两步称为编译期和运行期。C 语言中的指针之所以危险就在于程序要在运行的时候才会发现问题(后知后觉);而现代化的高级编程语言中的编译器在程序编译的时候就会发现问题(提前发现问题)。</li><li>④ C 语言的编译器之所以这么设计的原因,就在于当时的内存和 CPU 是非常有限PDP-7 早期小型计算机CPU18 bit 的电子管逻辑内存4kb 和昂贵72,000 $),如果加入安全限制的功能,会远远超过整个系统的资源。</li></ul></div><h2 id="_1-2-现代化高级编程语言是如何解决指针危险的" tabindex="-1">1.2 现代化高级编程语言是如何解决指针危险的? <a class="header-anchor" href="#_1-2-现代化高级编程语言是如何解决指针危险的" aria-label="Permalink to &quot;1.2 现代化高级编程语言是如何解决指针危险的?&quot;"></a></h2><ul><li><p><code>C++</code>采用了如下的策略和机制,来解决指针危险操作的:</p><ul><li>① <code>智能指针</code> C++ 引入了智能指针(如<code>std::shared_ptr</code>、<code>std::unique_ptr</code>),这些指针提供了自动资源管理和所有权的语义。<code>std::unique_ptr</code>确保只有一个指针可以访问给定的资源,从而避免了传统指针的悬空引用和内存泄漏问题。<code>std::shared_ptr</code>允许多个指针共享一个资源,并在所有引用释放后自动释放。</li><li>② <code>引用</code> C++ 中的引用(如:<code>&amp;</code>符号)提供了更安全的间接访问方法,与指针相比,引用不能重新绑定到不同的对象,从而减少了意外的指针错误。</li></ul></li><li><p><code>Go</code>采用了如下的策略和机制,来解决指针危险操作的:</p><ul><li>① <code>内存管理和垃圾回收</code> Go 语言通过自动垃圾回收器管理内存减少了手动内存管理所带来的指针操作错误。Go 的垃圾回收器定期扫描并释放不再使用的内存,避免了内存泄漏和悬空指针问题。</li><li>② <code>指针的安全性</code> Go 语言的指针是受限的,不支持指针运算,从而减少了指针操作可能带来的风险。</li></ul></li><li><p><code>Rust</code>采用了如下的策略和机制,来解决指针危险操作的:</p><ul><li>① <code>所有权和借用</code> Rust 引入了所有权和借用的概念,编译器在编译时静态分析所有权转移和引用的生命周期。这种机制避免了数据竞争和空指针解引用等运行时错误,使得在编译时就能够保证内存安全。</li><li>② <code>生命周期</code> Rust 的生命周期系统确保引用的有效性和安全性,防止了悬空引用和指针乱用。</li></ul></li><li><p><code>Java</code>采用了如下的策略和机制,来解决指针危险操作的:</p><ul><li>① <code>引用类型和自动内存管理</code> Java 中所有的对象引用都是通过引用来访问的而不是直接的指针。Java 的自动垃圾回收器负责管理内存,从而避免了手动内存管理可能导致的指针错误,如:内存泄漏和悬空指针。</li><li>② <code>强类型系统和异常处理</code> Java 的强类型系统和异常处理机制减少了指针操作带来的风险空指针解引用异常NullPointerException。编译器在编译时能够捕获许多潜在的类型错误进一步增强了程序的安全性和可靠性。</li></ul></li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p>总而言之,各种编程语言通过引入不同的策略和机制,如:智能指针、垃圾回收器、所有权和借用,以及强类型系统,有效地减少了指针操作所带来的各种安全性和可靠性问题,提升了程序的稳定性和开发效率。</p></div><h1 id="第二章-回顾知识" tabindex="-1">第二章:回顾知识 <a class="header-anchor" href="#第二章-回顾知识" aria-label="Permalink to &quot;第二章:回顾知识&quot;"></a></h1><h2 id="_2-1-变量" tabindex="-1">2.1 变量 <a class="header-anchor" href="#_2-1-变量" aria-label="Permalink to &quot;2.1 变量&quot;"></a></h2><ul><li>变量就是保存程序运行过程中临时产生的值,其语法如下:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">数据类型 变量名 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 值 ;</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p>变量名(标识符)需要符合命名规则和命名规范!!!</p><ul><li>强制规范: <ul><li>① 只能由<code>小写</code>或<code>大写英文字母</code><code>0-9</code> 或 <code>_</code> 组成。</li><li>② 不能以<code>数字</code>开头。</li><li>③ 不可以是<code>关键字</code>。</li><li>④ 标识符具有<code>长度</code>限制,不同编译器和平台会有所不同,一般限制在 63 个字符内。</li><li>⑤ 严格<code>区分大小写字母</code>Hello、hello 是不同的标识符。</li></ul></li><li>建议规范: <ul><li>① 为了提高阅读性使用有意义的单词见名知意sumnamemaxyear 等。</li><li>② 使用下划线连接多个单词组成的标识符max_classes_per_student 等。</li><li>③ 多个单词组成的标识符,除了使用下划线连接,也可以使用小驼峰命名法,除第一个单词外,后续单词的首字母大写,如: studentId、student_name 等。</li><li>④ 不要出现仅靠大小写区分不同的标识符name、Name 容易混淆。</li><li>⑤ 系统内部使用了一些下划线开头的标识符C99 标准添加的类型 <code>_Bool</code>,为防止冲突,建议开发者尽量避免使用下划线开头的标识符。</li></ul></li></ul></div><ul><li><code>变量名</code>的<code>作用</code>,如下所示: <ul><li>① 当我们<code>编写</code>代码的时候,使用<code>变量名</code>来<code>关联</code>某块内存的<code>地址</code>。</li><li>② 当 CPU <code>执行</code>的时候,会将变量名<code>替换</code>为具体的地址,再进行具体的操作。</li></ul></li></ul><h2 id="_2-2-普通变量和指针变量的区别" tabindex="-1">2.2 普通变量和指针变量的区别 <a class="header-anchor" href="#_2-2-普通变量和指针变量的区别" aria-label="Permalink to &quot;2.2 普通变量和指针变量的区别&quot;"></a></h2><ul><li>根据<code>变量</code>中<code>存储</code>的<code>值</code>的<code>不同</code>,我们可以将<code>变量</code>分为两类: <ul><li><code>普通变量</code>:变量所对应的内存中存储的是<code>普通值</code>。</li><li><code>指针变量</code>:变量所对应的内存中存储的是<code>另一个变量的地址</code>。</li></ul></li><li>如下图所示:</li></ul><p><img src="'+t+'" alt="img" loading="lazy"></p><ul><li>普通变量和指针变量的相同点,如下所示: <ul><li>① 普通变量有内存空间,指针变量也有内存空间。</li><li>② 普通变量有内存地址,指针变量也有内存地址。</li><li>③ 普通变量所对应的内存空间中有值,指针变量所对应的内存空间中也有值。</li></ul></li><li>普通变量和指针变量的不同点: <ul><li>① <code>普通变量</code>所对应的内存空间<code>存储</code>的是<code>普通的值</code>,如:整数、小数、字符等;<code>指针变量</code>所对应的内存空间<code>存储</code>的是另外一个变量的<code>地址</code>。</li><li>② <code>普通变量有普通变量的运算方式</code>,而<code>指针变量有指针变量的运算方式</code>(后续讲解)。</li></ul></li></ul><h2 id="_2-3-运算符" tabindex="-1">2.3 运算符 <a class="header-anchor" href="#_2-3-运算符" aria-label="Permalink to &quot;2.3 运算符&quot;"></a></h2><h3 id="_2-3-1-概述" tabindex="-1">2.3.1 概述 <a class="header-anchor" href="#_2-3-1-概述" aria-label="Permalink to &quot;2.3.1 概述&quot;"></a></h3><ul><li>运算符是一种特殊的符号,用于数据的运算、赋值和比较等。</li><li><code>表达式</code>指的是一组运算数、运算符的组合,表达式<code>一定具有值</code>,一个变量或一个常量可以是表达式,变量、常量和运算符也可以组成表达式,如:</li></ul><p><img src="'+l+'" alt="img" loading="lazy"></p><ul><li><code>操作数</code>指的是<code>参与运算</code>的<code>值</code>或者<code>对象</code>,如:</li></ul><p><img src="'+e+`" alt="" loading="lazy"></p><ul><li>根据<code>操作数</code>的<code>个数</code>,可以将运算符分为: <ul><li>一元运算符(一目运算符)。</li><li>二元运算符(二目运算符)。</li><li>三元运算符(三目运算符)。</li></ul></li><li>根据<code>功能</code>,可以将运算符分为: <ul><li>算术运算符。</li><li>关系运算符(比较运算符)。</li><li>逻辑运算符。</li><li>赋值运算符。</li><li>逻辑运算符。</li><li>位运算符。</li><li>三元运算符。</li></ul></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>掌握一个运算符,需要关注以下几个方面:</p><ul><li>① 运算符的含义。</li><li>② 运算符操作数的个数。</li><li>③ 运算符所组成的表达式。</li><li>④ 运算符有无副作用,即:运算后是否会修改操作数的值。</li></ul></div><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p>普通变量支持上述的所有运算符;而指针变量并非支持上述的所有运算符,且支持运算符的含义和普通变量相差较大!!!</p></div><h3 id="_2-3-2-运算符的优先级" tabindex="-1">2.3.2 运算符的优先级 <a class="header-anchor" href="#_2-3-2-运算符的优先级" aria-label="Permalink to &quot;2.3.2 运算符的优先级&quot;"></a></h3><ul><li>C 语言中运算符的优先级,如下所示:</li></ul><table tabindex="0"><thead><tr><th><strong>优先级</strong></th><th><strong>运算符</strong></th><th><strong>名称或含义</strong></th><th><strong>结合方向</strong></th></tr></thead><tbody><tr><td><strong>1</strong></td><td><code>[]</code></td><td>数组下标</td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>()</code></td><td>圆括号</td><td></td></tr><tr><td></td><td><code>.</code></td><td>成员选择(对象)</td><td></td></tr><tr><td></td><td><code>-&gt;</code></td><td>成员选择(指针)</td><td></td></tr><tr><td><strong>2</strong></td><td><code>-</code></td><td>负号运算符</td><td>⬅️(从右到左)</td></tr><tr><td></td><td><code>(类型)</code></td><td>强制类型转换</td><td></td></tr><tr><td></td><td><code>++</code></td><td>自增运算符</td><td></td></tr><tr><td></td><td><code>--</code></td><td>自减运算符</td><td></td></tr><tr><td></td><td><code>*</code></td><td>取值运算符</td><td></td></tr><tr><td></td><td><code>&amp;</code></td><td>取地址运算符</td><td></td></tr><tr><td></td><td><code>!</code></td><td>逻辑非运算符</td><td></td></tr><tr><td></td><td><code>~</code></td><td>按位取反运算符</td><td></td></tr><tr><td></td><td><code>sizeof</code></td><td>长度运算符</td><td></td></tr><tr><td><strong>3</strong></td><td><code>/</code></td><td>除</td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>*</code></td><td>乘</td><td></td></tr><tr><td></td><td><code>%</code></td><td>余数(取模)</td><td></td></tr><tr><td><strong>4</strong></td><td><code>+</code></td><td>加</td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>-</code></td><td>减</td><td></td></tr><tr><td><strong>5</strong></td><td><code>&lt;&lt;</code></td><td>左移</td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>&gt;&gt;</code></td><td>右移</td><td></td></tr><tr><td><strong>6</strong></td><td><code>&gt;</code></td><td>大于</td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>&gt;=</code></td><td>大于等于</td><td></td></tr><tr><td></td><td><code>&lt;</code></td><td>小于</td><td></td></tr><tr><td></td><td><code>&lt;=</code></td><td>小于等于</td><td></td></tr><tr><td><strong>7</strong></td><td><code>==</code></td><td>等于</td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>!=</code></td><td>不等于</td><td></td></tr><tr><td><strong>8</strong></td><td><code>&amp;</code></td><td>按位与</td><td>➡️(从左到右)</td></tr><tr><td><strong>9</strong></td><td><code>^</code></td><td>按位异或</td><td>➡️(从左到右)</td></tr><tr><td><strong>10</strong></td><td><code>|</code></td><td>按位或</td><td>➡️(从左到右)</td></tr><tr><td><strong>11</strong></td><td><code>&amp;&amp;</code></td><td>逻辑与</td><td>➡️(从左到右)</td></tr><tr><td><strong>12</strong></td><td><code>||</code></td><td>逻辑或</td><td>➡️(从左到右)</td></tr><tr><td><strong>13</strong></td><td><code>?:</code></td><td>条件运算符</td><td>⬅️(从右到左)</td></tr><tr><td><strong>14</strong></td><td><code>=</code></td><td>赋值运算符</td><td>⬅️(从右到左)</td></tr><tr><td></td><td><code>/=</code></td><td>除后赋值</td><td></td></tr><tr><td></td><td><code>*=</code></td><td>乘后赋值</td><td></td></tr><tr><td></td><td><code>%=</code></td><td>取模后赋值</td><td></td></tr><tr><td></td><td><code>+=</code></td><td>加后赋值</td><td></td></tr><tr><td></td><td><code>-=</code></td><td>减后赋值</td><td></td></tr><tr><td></td><td><code>&lt;&lt;=</code></td><td>左移后赋值</td><td></td></tr><tr><td></td><td><code>&gt;&gt;=</code></td><td>右移后赋值</td><td></td></tr><tr><td></td><td><code>&amp;=</code></td><td>按位与后赋值</td><td></td></tr><tr><td></td><td><code>^=</code></td><td>按位异或后赋值</td><td></td></tr><tr><td></td><td><code>|=</code></td><td>按位或后赋值</td><td></td></tr><tr><td><strong>15</strong></td><td><code>,</code></td><td>逗号运算符</td><td>➡️(从左到右)</td></tr></tbody></table><div class="warning custom-block github-alert"><p class="custom-block-title">WARNING</p><p></p><ul><li>① 不要过多的依赖运算符的优先级来控制表达式的执行顺序,这样可读性太差,尽量<code>使用小括号来控制</code>表达式的执行顺序。</li><li>② 不要把一个表达式写得过于复杂,如果一个表达式过于复杂,则把它<code>分成几步</code>来完成。</li><li>③ 运算符优先级不用刻意地去记忆,总体上:一元运算符 &gt; 算术运算符 &gt; 关系运算符 &gt; 逻辑运算符 &gt; 三元运算符 &gt; 赋值运算符。</li></ul></div><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li>① 取值运算符 <code>*</code> 和取地址运算符 <code>&amp;</code> 的优先级相同,并且运算方向都是从右向左!!!</li><li>② 逗号运算符 <code>,</code> 的优先级最低,并且运算方向是从左向右!!!</li></ul></div><h1 id="第三章-指针的理解和定义-⭐" tabindex="-1">第三章:指针的理解和定义(⭐) <a class="header-anchor" href="#第三章-指针的理解和定义-⭐" aria-label="Permalink to &quot;第三章:指针的理解和定义(⭐)&quot;"></a></h1><h2 id="_3-1-变量的访问方式" tabindex="-1">3.1 变量的访问方式 <a class="header-anchor" href="#_3-1-变量的访问方式" aria-label="Permalink to &quot;3.1 变量的访问方式&quot;"></a></h2><ul><li>计算机中程序的运行都是在内存中进行的变量也是内存中分配的空间且不同类型的变量占据的内存空间大小不同char 类型的变量是 1 个字节short 类型的变量是 2 个字节int 类型的变量是 4 个字节...</li><li>之前我们都是通过<code>变量名(普通变量)</code>访问内存中存储的数据,如下所示:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>

View File

@ -1 +1 @@
import{_ as s,c as i,o as a,a6 as n}from"./chunks/framework.hMCIpNYY.js";const t="/c/assets/1.L8V3GBrc.png",l="/c/assets/2.CdvhiwcU.png",e="/c/assets/3.D74t3-Xt.png",d="/c/assets/4.DqDR6Thp.svg",p="/c/assets/5.BzSkS-4w.svg",h="/c/assets/6.BPY9ZGed.svg",C=JSON.parse('{"title":"第一章:颇具争议的指针","description":"","frontmatter":{},"headers":[],"relativePath":"notes/01_c-basic/06_xdx/index.md","filePath":"notes/01_c-basic/06_xdx/index.md","lastUpdated":1723516792000}'),k={name:"notes/01_c-basic/06_xdx/index.md"},r=n("",87),c=[r];function o(g,E,u,b,y,F){return a(),i("div",null,c)}const A=s(k,[["render",o]]);export{C as __pageData,A as default};
import{_ as s,c as i,o as a,a6 as n}from"./chunks/framework.hMCIpNYY.js";const t="/c/assets/1.L8V3GBrc.png",l="/c/assets/2.CdvhiwcU.png",e="/c/assets/3.D74t3-Xt.png",d="/c/assets/4.DqDR6Thp.svg",p="/c/assets/5.BzSkS-4w.svg",h="/c/assets/6.BPY9ZGed.svg",C=JSON.parse('{"title":"第一章:颇具争议的指针","description":"","frontmatter":{},"headers":[],"relativePath":"notes/01_c-basic/07_xdx/index.md","filePath":"notes/01_c-basic/07_xdx/index.md","lastUpdated":1724728274000}'),k={name:"notes/01_c-basic/07_xdx/index.md"},r=n("",87),c=[r];function o(g,E,u,b,y,F){return a(),i("div",null,c)}const A=s(k,[["render",o]]);export{C as __pageData,A as default};

View File

@ -1 +1 @@
{"index.md":"Dga0tMF5","notes_01_c-basic_00_xdx_index.md":"BRC7slaL","notes_01_c-basic_01_xdx_index.md":"DvCUr2L0","notes_01_c-basic_02_xdx_index.md":"CC2Mg9VD","notes_01_c-basic_03_xdx_index.md":"CcATnhKW","notes_01_c-basic_04_xdx_index.md":"DABEMZSO","notes_01_c-basic_05_xdx_index.md":"CGbN5wss","notes_01_c-basic_06_xdx_index.md":"CIGNaKYV","notes_04_linux_01_xdx_index.md":"C9IatKsj","notes_about_index.md":"DLuQgC_8","notes_index.md":"CeV-uJ5V"}
{"index.md":"Dga0tMF5","notes_01_c-basic_00_xdx_index.md":"BRC7slaL","notes_01_c-basic_01_xdx_index.md":"Fg4OXydV","notes_01_c-basic_02_xdx_index.md":"CC2Mg9VD","notes_01_c-basic_03_xdx_index.md":"Cw3Z19MO","notes_01_c-basic_04_xdx_index.md":"ySxH8sG-","notes_01_c-basic_05_xdx_index.md":"DUbOwEts","notes_01_c-basic_06_xdx_index.md":"CV_r2WNu","notes_01_c-basic_07_xdx_index.md":"CE9q5cmu","notes_04_linux_01_xdx_index.md":"C9IatKsj","notes_about_index.md":"DLuQgC_8","notes_index.md":"CeV-uJ5V"}

View File

@ -8,9 +8,9 @@
<meta name="generator" content="VitePress v1.3.3">
<link rel="preload stylesheet" href="/c/assets/style.zDJ0OJGU.css" as="style">
<script type="module" src="/c/assets/app.Ca2FOFw4.js"></script>
<script type="module" src="/c/assets/app.1a4d5P-6.js"></script>
<link rel="preload" href="/c/assets/inter-roman-latin.Di8DUHzh.woff2" as="font" type="font/woff2" crossorigin="">
<link rel="modulepreload" href="/c/assets/chunks/theme.C6fZfLtk.js">
<link rel="modulepreload" href="/c/assets/chunks/theme.Ddh-lpYV.js">
<link rel="modulepreload" href="/c/assets/chunks/framework.hMCIpNYY.js">
<link rel="modulepreload" href="/c/assets/index.md.Dga0tMF5.lean.js">
<link rel="shortcut icon" href="/c//logo.svg">
@ -23,7 +23,7 @@
</head>
<body>
<div id="app"><div class="Layout" data-v-5d98c3a5><!--[--><!--]--><!--[--><span tabindex="-1" data-v-0f60ec36></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-0f60ec36> Skip to content </a><!--]--><!----><header class="VPNav" data-v-5d98c3a5 data-v-ae24b3ad><div class="VPNavBar home top" data-v-ae24b3ad data-v-6aa21345><div class="wrapper" data-v-6aa21345><div class="container" data-v-6aa21345><div class="title" data-v-6aa21345><div class="VPNavBarTitle" data-v-6aa21345 data-v-ab179fa1><a class="title" href="/c/" data-v-ab179fa1><!--[--><!--]--><!--[--><img class="VPImage logo" src="/c/logo.svg" alt data-v-8426fc1a><!--]--><span data-v-ab179fa1>许大仙</span><!--[--><!--]--></a></div></div><div class="content" data-v-6aa21345><div class="content-body" data-v-6aa21345><!--[--><!--]--><div class="VPNavBarSearch search" data-v-6aa21345><!--[--><!----><div id="local-search"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><span class="vp-icon DocSearch-Search-Icon"></span><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key">K</kbd></span></button></div><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-6aa21345 data-v-dc692963><span id="main-nav-aria-label" class="visually-hidden" data-v-dc692963> Main Navigation </span><!--[--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>首页</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/coa6/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>计组6件套</span><!--]--></a><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-dc692963 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-b6c34ac9><span class="text" data-v-b6c34ac9><!----><span data-v-b6c34ac9>编程语言</span><span class="vpi-chevron-down text-icon" data-v-b6c34ac9></span></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><div class="items" data-v-b98bc113><!--[--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link" href="/c/notes/" data-v-43f1e123><!--[-->c/c++<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/web-design/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->前端<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/java/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Java<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/big-data/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->大数据<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/linux/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->云原生<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/go/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Go<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/python/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Python<!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/db/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>数据库</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/open-software/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>开源软件</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/c/notes/about/" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>关于我</span><!--]--></a><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-6aa21345 data-v-6c893767><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-6c893767 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-6aa21345 data-v-0394ad82 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-6aa21345 data-v-bb2aa2f0 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-b6c34ac9><span class="vpi-more-horizontal icon" data-v-b6c34ac9></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><!----><!--[--><!--[--><!----><div class="group" data-v-bb2aa2f0><div class="item appearance" data-v-bb2aa2f0><p class="label" data-v-bb2aa2f0>深浅模式</p><div class="appearance-action" data-v-bb2aa2f0><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-bb2aa2f0 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div></div></div><div class="group" data-v-bb2aa2f0><div class="item social-links" data-v-bb2aa2f0><div class="VPSocialLinks social-links-list" data-v-bb2aa2f0 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div></div></div><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-6aa21345 data-v-e5dd9c1c><span class="container" data-v-e5dd9c1c><span class="top" data-v-e5dd9c1c></span><span class="middle" data-v-e5dd9c1c></span><span class="bottom" data-v-e5dd9c1c></span></span></button></div></div></div></div><div class="divider" data-v-6aa21345><div class="divider-line" data-v-6aa21345></div></div></div><!----></header><!----><!----><div class="VPContent is-home" id="VPContent" data-v-5d98c3a5 data-v-1428d186><div class="VPHome" data-v-1428d186 data-v-686f80a6><!--[--><!--]--><div class="VPHero has-image VPHomeHero" data-v-686f80a6 data-v-303bb580><div class="container" data-v-303bb580><div class="main" data-v-303bb580><!--[--><!--]--><!--[--><h1 class="name" data-v-303bb580><span class="clip" data-v-303bb580>许大仙同学</span></h1><!----><p class="tagline" data-v-303bb580>『这个世纪疯狂,没人性,腐败;你却一直清醒,温柔,一尘不染。』</p><!--]--><!--[--><!--]--><div class="actions" data-v-303bb580><!--[--><div class="action" data-v-303bb580><a class="VPButton medium brand" href="https://aexiar.github.io" target="_blank" rel="noreferrer" data-v-303bb580 data-v-cad61b99>首页</a></div><div class="action" data-v-303bb580><a class="VPButton medium alt" href="https://aexiar.github.io/coa6/notes/" target="_blank" rel="noreferrer" data-v-303bb580 data-v-cad61b99>计组6件套</a></div><div class="action" data-v-303bb580><a class="VPButton medium alt" href="/c/notes/" data-v-303bb580 data-v-cad61b99>c/c++</a></div><div class="action" data-v-303bb580><a class="VPButton medium alt" href="https://aexiar.github.io/web-design/notes/" target="_blank" rel="noreferrer" data-v-303bb580 data-v-cad61b99>前端</a></div><div class="action" data-v-303bb580><a class="VPButton medium alt" href="https://aexiar.github.io/java/notes/" target="_blank" rel="noreferrer" data-v-303bb580 data-v-cad61b99>Java</a></div><div class="action" data-v-303bb580><a class="VPButton medium alt" href="https://aexiar.github.io/big-data/notes/" target="_blank" rel="noreferrer" data-v-303bb580 data-v-cad61b99>大数据</a></div><div class="action" data-v-303bb580><a class="VPButton medium alt" href="https://aexiar.github.io/linux/notes/" target="_blank" rel="noreferrer" data-v-303bb580 data-v-cad61b99>云原生</a></div><div class="action" data-v-303bb580><a class="VPButton medium alt" href="https://aexiar.github.io/go/notes/" target="_blank" rel="noreferrer" data-v-303bb580 data-v-cad61b99>Go</a></div><div class="action" data-v-303bb580><a class="VPButton medium alt" href="https://aexiar.github.io/python/notes/" target="_blank" rel="noreferrer" data-v-303bb580 data-v-cad61b99>Python</a></div><div class="action" data-v-303bb580><a class="VPButton medium alt" href="https://aexiar.github.io/db/notes/" target="_blank" rel="noreferrer" data-v-303bb580 data-v-cad61b99>数据库</a></div><div class="action" data-v-303bb580><a class="VPButton medium alt" href="https://aexiar.github.io/open-software/notes/" target="_blank" rel="noreferrer" data-v-303bb580 data-v-cad61b99>开源软件</a></div><!--]--></div><!--[--><!--]--></div><div class="image" data-v-303bb580><div class="image-container" data-v-303bb580><div class="image-bg" data-v-303bb580></div><!--[--><!--[--><img class="VPImage image-src" src="/c/logo.svg" alt="许大仙" data-v-8426fc1a><!--]--><!--]--></div></div></div></div><!--[--><!--]--><!--[--><!--]--><div class="VPFeatures VPHomeFeatures" data-v-686f80a6 data-v-a6181336><div class="container" data-v-a6181336><div class="items" data-v-a6181336><!--[--><div class="grid-3 item" data-v-a6181336><div class="VPLink no-icon VPFeature" data-v-a6181336 data-v-a3976bdc><!--[--><article class="box" data-v-a3976bdc><div class="icon" data-v-a3976bdc>🧠</div><h2 class="title" data-v-a3976bdc>学习思路</h2><p class="details" data-v-a3976bdc>学习思路就这么几条:模仿、遍历、分治、动态规划、……</p><!----></article><!--]--></div></div><div class="grid-3 item" data-v-a6181336><div class="VPLink no-icon VPFeature" data-v-a6181336 data-v-a3976bdc><!--[--><article class="box" data-v-a3976bdc><div class="icon" data-v-a3976bdc>✍️</div><h2 class="title" data-v-a3976bdc>学习手法</h2><p class="details" data-v-a3976bdc>学习手法就这么几种:缓存、索引、信号/事件、回调/消息循环/dispatcher、……</p><!----></article><!--]--></div></div><div class="grid-3 item" data-v-a6181336><div class="VPLink no-icon VPFeature" data-v-a6181336 data-v-a3976bdc><!--[--><article class="box" data-v-a3976bdc><div class="icon" data-v-a3976bdc>🚨</div><h2 class="title" data-v-a3976bdc>注意事项</h2><p class="details" data-v-a3976bdc>注意事项就这么几点:边界值、等价类、数据完整性原子性、死锁、空转、……</p><!----></article><!--]--></div></div><!--]--></div></div></div><!--[--><!--]--><div class="vp-doc container" style="" data-v-686f80a6 data-v-8e2d4988><!--[--><div style="position:relative;" data-v-686f80a6><div></div></div><!--]--></div></div></div><footer class="VPFooter" data-v-5d98c3a5 data-v-e315a0ad><div class="container" data-v-e315a0ad><p class="message" data-v-e315a0ad>Released under the MIT License.</p><p class="copyright" data-v-e315a0ad>Copyright © 2024 许大仙</p></div></footer><!--[--><!--]--></div></div>
<script>window.__VP_HASH_MAP__=JSON.parse("{\"index.md\":\"Dga0tMF5\",\"notes_01_c-basic_00_xdx_index.md\":\"BRC7slaL\",\"notes_01_c-basic_01_xdx_index.md\":\"DvCUr2L0\",\"notes_01_c-basic_02_xdx_index.md\":\"CC2Mg9VD\",\"notes_01_c-basic_03_xdx_index.md\":\"CcATnhKW\",\"notes_01_c-basic_04_xdx_index.md\":\"DABEMZSO\",\"notes_01_c-basic_05_xdx_index.md\":\"CGbN5wss\",\"notes_01_c-basic_06_xdx_index.md\":\"CIGNaKYV\",\"notes_04_linux_01_xdx_index.md\":\"C9IatKsj\",\"notes_about_index.md\":\"DLuQgC_8\",\"notes_index.md\":\"CeV-uJ5V\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"zh-CN\",\"dir\":\"ltr\",\"title\":\"许大仙\",\"titleTemplate\":\"Hi终于等到你\",\"description\":\"许大仙前端、Java、大数据、云原生\",\"base\":\"/c/\",\"head\":[],\"router\":{\"prefetchLinks\":true},\"appearance\":true,\"themeConfig\":{\"lastUpdatedText\":\"上次更新\",\"returnToTopLabel\":\"返回顶部\",\"search\":{\"provider\":\"local\"},\"logo\":\"/logo.svg\",\"nav\":[{\"text\":\"首页\",\"link\":\"https://aexiar.github.io/\"},{\"text\":\"计组6件套\",\"link\":\"https://aexiar.github.io/coa6/notes/\"},{\"text\":\"编程语言\",\"items\":[{\"text\":\"c/c++\",\"link\":\"/notes/\"},{\"text\":\"前端\",\"link\":\"https://aexiar.github.io/web-design/notes/\"},{\"text\":\"Java\",\"link\":\"https://aexiar.github.io/java/notes/\"},{\"text\":\"大数据\",\"link\":\"https://aexiar.github.io/big-data/notes/\"},{\"text\":\"云原生\",\"link\":\"https://aexiar.github.io/linux/notes/\"},{\"text\":\"Go\",\"link\":\"https://aexiar.github.io/go/notes/\"},{\"text\":\"Python\",\"link\":\"https://aexiar.github.io/python/notes/\"}]},{\"text\":\"数据库\",\"link\":\"https://aexiar.github.io/db/notes/\"},{\"text\":\"开源软件\",\"link\":\"https://aexiar.github.io/open-software/notes/\"},{\"text\":\"关于我\",\"link\":\"/notes/about/\"}],\"sidebar\":{\"/notes/\":[{\"text\":\"C 语言基础\",\"collapsed\":true,\"items\":[{\"text\":\"编程基础\",\"link\":\"/notes/01_c-basic/00_xdx/\"},{\"text\":\"C 语言入门\",\"link\":\"/notes/01_c-basic/01_xdx/\"},{\"text\":\"变量和进制\",\"link\":\"/notes/01_c-basic/02_xdx/\"},{\"text\":\"数据类型和运算符\",\"link\":\"/notes/01_c-basic/03_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/01_c-basic/04_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/01_c-basic/05_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/01_c-basic/06_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/01_c-basic/07_xdx/\"},{\"text\":\"预处理器\",\"link\":\"/notes/01_c-basic/08_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/01_c-basic/09_xdx/\"},{\"text\":\"内存管理\",\"link\":\"/notes/01_c-basic/10_xdx/\"},{\"text\":\"文件操作\",\"link\":\"/notes/01_c-basic/11_xdx/\"},{\"text\":\"调试工具和调试技巧gdb和make\",\"link\":\"/notes/02_c-basic/13_xdx/\"},{\"text\":\"常用库函数\",\"link\":\"/notes/01_c-basic/13_xdx/\"}]},{\"text\":\"C 语言高级\",\"collapsed\":true,\"items\":[{\"text\":\"变量和内存分布\",\"link\":\"/notes/02_c-advance/01_xdx/\"},{\"text\":\"指针强化\",\"link\":\"/notes/02_c-advance/02_xdx/\"},{\"text\":\"结构体和文件的高级用法\",\"link\":\"/notes/02_c-advance/03_xdx/\"},{\"text\":\"链表和回调函数\",\"link\":\"/notes/02_c-advance/04_xdx/\"},{\"text\":\"编译过程和面向接口\",\"link\":\"/notes/02_c-advance/05_xdx/\"}]},{\"text\":\"项目构建工具\",\"collapsed\":true,\"items\":[{\"text\":\"meson\",\"collapsed\":true,\"items\":[{\"text\":\"meson 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Cmake\",\"collapsed\":true,\"items\":[{\"text\":\"Cmake 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Conan \",\"link\":\"/notes/03_build/01_${commonDirectoryName}/\"},{\"text\":\"Gradle\",\"collapsed\":true,\"items\":[{\"text\":\"Gradle 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]}]},{\"text\":\"Linux\",\"collapsed\":true,\"items\":[{\"text\":\"Linux 初识和安装\",\"link\":\"/notes/04_linux/01_xdx/\"}]},{\"text\":\"C++ 基础\",\"collapsed\":true,\"items\":[{\"text\":\"C++ 入门\",\"link\":\"/notes/05_cpp/01_xdx/\"},{\"text\":\"变量、数据类型、运算符\",\"link\":\"/notes/05_cpp/02_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/05_cpp/03_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/05_cpp/04_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/05_cpp/05_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/05_cpp/06_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/05_cpp/07_xdx/\"},{\"text\":\"类和对象\",\"link\":\"/notes/05_cpp/08_xdx/\"},{\"text\":\"C++ 引用\",\"link\":\"/notes/05_cpp/09_xdx/\"},{\"text\":\"继承和派生\",\"link\":\"/notes/05_cpp/10_xdx/\"},{\"text\":\"C++ 多态和虚函数\",\"link\":\"/notes/05_cpp/11_xdx/\"},{\"text\":\"运算符重载\",\"link\":\"/notes/05_cpp/12_xdx/\"},{\"text\":\"模板\",\"link\":\"/notes/05_cpp/13_xdx/\"},{\"text\":\"C++ 异常\",\"link\":\"/notes/05_cpp/14_xdx/\"},{\"text\":\"面向对象进阶\",\"link\":\"/notes/05_cpp/15_xdx/\"},{\"text\":\"文件操作和 IO 流\",\"link\":\"/notes/05_cpp/16_xdx/\"},{\"text\":\"STL标准模板库\",\"link\":\"/notes/05_cpp/17_xdx/\"}]},{\"text\":\"C++ 高级\",\"collapsed\":true,\"items\":[]},{\"text\":\"QT 桌面开发\",\"collapsed\":true,\"items\":[]},{\"text\":\"Linux 高并发服务器开发\",\"collapsed\":true,\"items\":[]}]},\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/Aurorxa\"}],\"docFooter\":{\"prev\":\"上一篇\",\"next\":\"下一篇\"},\"darkModeSwitchLabel\":\"深浅模式\",\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2024 许大仙\"},\"outline\":{\"level\":[1,6],\"label\":\"目录\"},\"outlineTitle\":\"当前页大纲\"},\"locales\":{},\"scrollOffset\":134,\"cleanUrls\":false}");</script>
<script>window.__VP_HASH_MAP__=JSON.parse("{\"index.md\":\"Dga0tMF5\",\"notes_01_c-basic_00_xdx_index.md\":\"BRC7slaL\",\"notes_01_c-basic_01_xdx_index.md\":\"Fg4OXydV\",\"notes_01_c-basic_02_xdx_index.md\":\"CC2Mg9VD\",\"notes_01_c-basic_03_xdx_index.md\":\"Cw3Z19MO\",\"notes_01_c-basic_04_xdx_index.md\":\"ySxH8sG-\",\"notes_01_c-basic_05_xdx_index.md\":\"DUbOwEts\",\"notes_01_c-basic_06_xdx_index.md\":\"CV_r2WNu\",\"notes_01_c-basic_07_xdx_index.md\":\"CE9q5cmu\",\"notes_04_linux_01_xdx_index.md\":\"C9IatKsj\",\"notes_about_index.md\":\"DLuQgC_8\",\"notes_index.md\":\"CeV-uJ5V\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"zh-CN\",\"dir\":\"ltr\",\"title\":\"许大仙\",\"titleTemplate\":\"Hi终于等到你\",\"description\":\"许大仙前端、Java、大数据、云原生\",\"base\":\"/c/\",\"head\":[],\"router\":{\"prefetchLinks\":true},\"appearance\":true,\"themeConfig\":{\"lastUpdatedText\":\"上次更新\",\"returnToTopLabel\":\"返回顶部\",\"search\":{\"provider\":\"local\"},\"logo\":\"/logo.svg\",\"nav\":[{\"text\":\"首页\",\"link\":\"https://aexiar.github.io/\"},{\"text\":\"计组6件套\",\"link\":\"https://aexiar.github.io/coa6/notes/\"},{\"text\":\"编程语言\",\"items\":[{\"text\":\"c/c++\",\"link\":\"/notes/\"},{\"text\":\"前端\",\"link\":\"https://aexiar.github.io/web-design/notes/\"},{\"text\":\"Java\",\"link\":\"https://aexiar.github.io/java/notes/\"},{\"text\":\"大数据\",\"link\":\"https://aexiar.github.io/big-data/notes/\"},{\"text\":\"云原生\",\"link\":\"https://aexiar.github.io/linux/notes/\"},{\"text\":\"Go\",\"link\":\"https://aexiar.github.io/go/notes/\"},{\"text\":\"Python\",\"link\":\"https://aexiar.github.io/python/notes/\"}]},{\"text\":\"数据库\",\"link\":\"https://aexiar.github.io/db/notes/\"},{\"text\":\"开源软件\",\"link\":\"https://aexiar.github.io/open-software/notes/\"},{\"text\":\"关于我\",\"link\":\"/notes/about/\"}],\"sidebar\":{\"/notes/\":[{\"text\":\"C 语言基础\",\"collapsed\":true,\"items\":[{\"text\":\"编程基础\",\"link\":\"/notes/01_c-basic/00_xdx/\"},{\"text\":\"C 语言入门\",\"link\":\"/notes/01_c-basic/01_xdx/\"},{\"text\":\"变量和进制\",\"link\":\"/notes/01_c-basic/02_xdx/\"},{\"text\":\"数据类型和运算符\",\"link\":\"/notes/01_c-basic/03_xdx/\"},{\"text\":\"大话小数\",\"link\":\"/notes/01_c-basic/04_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/01_c-basic/05_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/01_c-basic/06_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/01_c-basic/07_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/01_c-basic/08_xdx/\"},{\"text\":\"预处理器\",\"link\":\"/notes/01_c-basic/09_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/01_c-basic/10_xdx/\"},{\"text\":\"内存管理\",\"link\":\"/notes/01_c-basic/11_xdx/\"},{\"text\":\"文件操作\",\"link\":\"/notes/01_c-basic/12_xdx/\"},{\"text\":\"调试工具和调试技巧gdb和make\",\"link\":\"/notes/02_c-basic/13_xdx/\"},{\"text\":\"常用库函数\",\"link\":\"/notes/01_c-basic/14_xdx/\"}]},{\"text\":\"C 语言高级\",\"collapsed\":true,\"items\":[{\"text\":\"变量和内存分布\",\"link\":\"/notes/02_c-advance/01_xdx/\"},{\"text\":\"指针强化\",\"link\":\"/notes/02_c-advance/02_xdx/\"},{\"text\":\"结构体和文件的高级用法\",\"link\":\"/notes/02_c-advance/03_xdx/\"},{\"text\":\"链表和回调函数\",\"link\":\"/notes/02_c-advance/04_xdx/\"},{\"text\":\"编译过程和面向接口\",\"link\":\"/notes/02_c-advance/05_xdx/\"}]},{\"text\":\"项目构建工具\",\"collapsed\":true,\"items\":[{\"text\":\"meson\",\"collapsed\":true,\"items\":[{\"text\":\"meson 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Cmake\",\"collapsed\":true,\"items\":[{\"text\":\"Cmake 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Conan \",\"link\":\"/notes/03_build/01_${commonDirectoryName}/\"},{\"text\":\"Gradle\",\"collapsed\":true,\"items\":[{\"text\":\"Gradle 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]}]},{\"text\":\"Linux\",\"collapsed\":true,\"items\":[{\"text\":\"Linux 初识和安装\",\"link\":\"/notes/04_linux/01_xdx/\"}]},{\"text\":\"C++ 基础\",\"collapsed\":true,\"items\":[{\"text\":\"C++ 入门\",\"link\":\"/notes/05_cpp/01_xdx/\"},{\"text\":\"变量、数据类型、运算符\",\"link\":\"/notes/05_cpp/02_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/05_cpp/03_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/05_cpp/04_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/05_cpp/05_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/05_cpp/06_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/05_cpp/07_xdx/\"},{\"text\":\"类和对象\",\"link\":\"/notes/05_cpp/08_xdx/\"},{\"text\":\"C++ 引用\",\"link\":\"/notes/05_cpp/09_xdx/\"},{\"text\":\"继承和派生\",\"link\":\"/notes/05_cpp/10_xdx/\"},{\"text\":\"C++ 多态和虚函数\",\"link\":\"/notes/05_cpp/11_xdx/\"},{\"text\":\"运算符重载\",\"link\":\"/notes/05_cpp/12_xdx/\"},{\"text\":\"模板\",\"link\":\"/notes/05_cpp/13_xdx/\"},{\"text\":\"C++ 异常\",\"link\":\"/notes/05_cpp/14_xdx/\"},{\"text\":\"面向对象进阶\",\"link\":\"/notes/05_cpp/15_xdx/\"},{\"text\":\"文件操作和 IO 流\",\"link\":\"/notes/05_cpp/16_xdx/\"},{\"text\":\"STL标准模板库\",\"link\":\"/notes/05_cpp/17_xdx/\"}]},{\"text\":\"C++ 高级\",\"collapsed\":true,\"items\":[]},{\"text\":\"QT 桌面开发\",\"collapsed\":true,\"items\":[]},{\"text\":\"Linux 高并发服务器开发\",\"collapsed\":true,\"items\":[]}]},\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/Aurorxa\"}],\"docFooter\":{\"prev\":\"上一篇\",\"next\":\"下一篇\"},\"darkModeSwitchLabel\":\"深浅模式\",\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2024 许大仙\"},\"outline\":{\"level\":[1,6],\"label\":\"目录\"},\"outlineTitle\":\"当前页大纲\"},\"locales\":{},\"scrollOffset\":134,\"cleanUrls\":false}");</script>
</body>
</html>

File diff suppressed because one or more lines are too long

View File

@ -8,11 +8,11 @@
<meta name="generator" content="VitePress v1.3.3">
<link rel="preload stylesheet" href="/c/assets/style.zDJ0OJGU.css" as="style">
<script type="module" src="/c/assets/app.Ca2FOFw4.js"></script>
<script type="module" src="/c/assets/app.1a4d5P-6.js"></script>
<link rel="preload" href="/c/assets/inter-roman-latin.Di8DUHzh.woff2" as="font" type="font/woff2" crossorigin="">
<link rel="modulepreload" href="/c/assets/chunks/theme.C6fZfLtk.js">
<link rel="modulepreload" href="/c/assets/chunks/theme.Ddh-lpYV.js">
<link rel="modulepreload" href="/c/assets/chunks/framework.hMCIpNYY.js">
<link rel="modulepreload" href="/c/assets/notes_01_c-basic_01_xdx_index.md.DvCUr2L0.lean.js">
<link rel="modulepreload" href="/c/assets/notes_01_c-basic_01_xdx_index.md.Fg4OXydV.lean.js">
<link rel="shortcut icon" href="/c//logo.svg">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="">
<script id="register-sw">"serviceWorker"in navigator&&navigator.serviceWorker.register("/sw.js");</script>
@ -22,7 +22,7 @@
<script id="check-mac-os">document.documentElement.classList.toggle("mac",/Mac|iPhone|iPod|iPad/i.test(navigator.platform));</script>
</head>
<body>
<div id="app"><div class="Layout" data-v-5d98c3a5><!--[--><!--]--><!--[--><span tabindex="-1" data-v-0f60ec36></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-0f60ec36> Skip to content </a><!--]--><!----><header class="VPNav" data-v-5d98c3a5 data-v-ae24b3ad><div class="VPNavBar has-sidebar top" data-v-ae24b3ad data-v-6aa21345><div class="wrapper" data-v-6aa21345><div class="container" data-v-6aa21345><div class="title" data-v-6aa21345><div class="VPNavBarTitle has-sidebar" data-v-6aa21345 data-v-ab179fa1><a class="title" href="/c/" data-v-ab179fa1><!--[--><!--]--><!--[--><img class="VPImage logo" src="/c/logo.svg" alt data-v-8426fc1a><!--]--><span data-v-ab179fa1>许大仙</span><!--[--><!--]--></a></div></div><div class="content" data-v-6aa21345><div class="content-body" data-v-6aa21345><!--[--><!--]--><div class="VPNavBarSearch search" data-v-6aa21345><!--[--><!----><div id="local-search"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><span class="vp-icon DocSearch-Search-Icon"></span><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key">K</kbd></span></button></div><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-6aa21345 data-v-dc692963><span id="main-nav-aria-label" class="visually-hidden" data-v-dc692963> Main Navigation </span><!--[--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>首页</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/coa6/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>计组6件套</span><!--]--></a><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-dc692963 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-b6c34ac9><span class="text" data-v-b6c34ac9><!----><span data-v-b6c34ac9>编程语言</span><span class="vpi-chevron-down text-icon" data-v-b6c34ac9></span></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><div class="items" data-v-b98bc113><!--[--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link" href="/c/notes/" data-v-43f1e123><!--[-->c/c++<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/web-design/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->前端<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/java/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Java<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/big-data/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->大数据<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/linux/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->云原生<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/go/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Go<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/python/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Python<!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/db/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>数据库</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/open-software/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>开源软件</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/c/notes/about/" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>关于我</span><!--]--></a><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-6aa21345 data-v-6c893767><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-6c893767 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-6aa21345 data-v-0394ad82 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-6aa21345 data-v-bb2aa2f0 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-b6c34ac9><span class="vpi-more-horizontal icon" data-v-b6c34ac9></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><!----><!--[--><!--[--><!----><div class="group" data-v-bb2aa2f0><div class="item appearance" data-v-bb2aa2f0><p class="label" data-v-bb2aa2f0>深浅模式</p><div class="appearance-action" data-v-bb2aa2f0><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-bb2aa2f0 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div></div></div><div class="group" data-v-bb2aa2f0><div class="item social-links" data-v-bb2aa2f0><div class="VPSocialLinks social-links-list" data-v-bb2aa2f0 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div></div></div><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-6aa21345 data-v-e5dd9c1c><span class="container" data-v-e5dd9c1c><span class="top" data-v-e5dd9c1c></span><span class="middle" data-v-e5dd9c1c></span><span class="bottom" data-v-e5dd9c1c></span></span></button></div></div></div></div><div class="divider" data-v-6aa21345><div class="divider-line" data-v-6aa21345></div></div></div><!----></header><div class="VPLocalNav has-sidebar empty" data-v-5d98c3a5 data-v-a6f0e41e><div class="container" data-v-a6f0e41e><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-a6f0e41e><span class="vpi-align-left menu-icon" data-v-a6f0e41e></span><span class="menu-text" data-v-a6f0e41e>Menu</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-a6f0e41e data-v-17a5e62e><button data-v-17a5e62e>返回顶部</button><!----></div></div></div><aside class="VPSidebar" data-v-5d98c3a5 data-v-319d5ca6><div class="curtain" data-v-319d5ca6></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-319d5ca6><span class="visually-hidden" id="sidebar-aria-label" data-v-319d5ca6> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible has-active" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/00_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编程基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C 语言入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和进制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数据类型和运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>预处理器</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>内存管理</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-basic/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>调试工具和调试技巧gdb和make</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>常用库函数</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言高级</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和内存分布</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针强化</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>结构体和文件的高级用法</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>链表和回调函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编译过程和面向接口</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>项目构建工具</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>meson</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>meson 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Cmake</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Cmake 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_${commonDirectoryName}/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Conan </p><!--]--></a><!----></div><!----></div><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Gradle</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Gradle 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>Linux</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/04_linux/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Linux 初识和安装</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C++ 基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量、数据类型、运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>类和对象</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 引用</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>继承和派生</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 多态和虚函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/12_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>运算符重载</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>模板</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/14_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 异常</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/15_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>面向对象进阶</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/16_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作和 IO 流</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/17_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>STL标准模板库</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>C++ 高级</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>QT 桌面开发</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>Linux 高并发服务器开发</p><!----></div><!----></div></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-5d98c3a5 data-v-1428d186><div class="VPDoc has-sidebar has-aside" data-v-1428d186 data-v-39a288b8><!--[--><!--]--><div class="container" data-v-39a288b8><div class="aside" data-v-39a288b8><div class="aside-curtain" data-v-39a288b8></div><div class="aside-container" data-v-39a288b8><div class="aside-content" data-v-39a288b8><div class="VPDocAside" data-v-39a288b8 data-v-3f215769><!--[--><!--]--><!--[--><!--]--><nav aria-labelledby="doc-outline-aria-label" class="VPDocAsideOutline" data-v-3f215769 data-v-a5bbad30><div class="content" data-v-a5bbad30><div class="outline-marker" data-v-a5bbad30></div><div aria-level="2" class="outline-title" id="doc-outline-aria-label" role="heading" data-v-a5bbad30>目录</div><ul class="VPDocOutlineItem root" data-v-a5bbad30 data-v-b933a997><!--[--><!--]--></ul></div></nav><!--[--><!--]--><div class="spacer" data-v-3f215769></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-39a288b8><div class="content-container" data-v-39a288b8><!--[--><!--]--><main class="main" data-v-39a288b8><div style="position:relative;" class="vp-doc _c_notes_01_c-basic_01_xdx_" data-v-39a288b8><div><h1 id="第一章-开发环境的安装和配置-⭐" tabindex="-1">第一章:开发环境的安装和配置(⭐) <a class="header-anchor" href="#第一章-开发环境的安装和配置-⭐" aria-label="Permalink to &quot;第一章:开发环境的安装和配置(⭐)&quot;"></a></h1><h2 id="_1-1-什么是编译器" tabindex="-1">1.1 什么是编译器? <a class="header-anchor" href="#_1-1-什么是编译器" aria-label="Permalink to &quot;1.1 什么是编译器?&quot;"></a></h2><ul><li>要开发 C/C++ 程序,需要安装 C/C++ 编译器,目前有两种主流实现,即: <ul><li>GCCGNU Compiler Collection全平台实现即支持 Windows、MacOS、Linux 等。</li><li>MSVCMicrosoft Visual C++):只支持 Windows 系统。</li></ul></li><li>GCC 在 Windows 上的版本有很多,如:<a href="https://www.mingw-w64.org/" target="_blank" rel="noreferrer">MinGW-w64</a><a href="https://cygwin.com/" target="_blank" rel="noreferrer">Gygwin</a><a href="https://www.msys2.org/" target="_blank" rel="noreferrer">MSYS2</a>。它们之间的区别,如下所示:</li></ul><table tabindex="0"><thead><tr><th>特性</th><th>MinGW-w64</th><th>Cygwin</th><th>MSYS2</th></tr></thead><tbody><tr><td><strong>简介</strong></td><td>Minimalist GNU for Windows</td><td>POSIX 兼容环境和工具集</td><td>结合了 MinGW 和 Cygwin 的工具集</td></tr><tr><td><strong>编译器</strong></td><td>提供 GCC 编译器</td><td>提供 POSIX 兼容环境,包含大量工具</td><td>提供 MinGW-w64 工具链和 Cygwin 环境</td></tr><tr><td><strong>生成文件</strong></td><td>Windows 原生可执行文件</td><td>POSIX 兼容的可执行文件</td><td>可以生成 Windows 原生可执行文件或 POSIX 文件</td></tr><tr><td><strong>依赖</strong></td><td>无需额外依赖</td><td>依赖 Cygwin DLL</td><td>根据使用工具链决定MinGW-w64 无依赖Cygwin 有依赖)</td></tr><tr><td><strong>工具和库</strong></td><td>基本的编译工具</td><td>丰富的 Unix 工具和库</td><td>丰富的工具和库,强大的包管理系统</td></tr><tr><td><strong>性能</strong></td><td>性能较好</td><td>可能较低,因为通过兼容层调用系统</td><td>取决于使用的工具链MinGW-w64 性能较好)</td></tr><tr><td><strong>复杂度</strong></td><td>简单易用</td><td>设置和使用相对复杂</td><td>较为灵活,复杂度介于 MinGW-w64 和 Cygwin 之间</td></tr><tr><td><strong>适用场景</strong></td><td>开发 Windows 原生应用</td><td>运行和开发 Unix 程序</td><td>混合使用 Unix 工具和开发 Windows 原生应用</td></tr><tr><td><strong>优点</strong></td><td>轻量级,直接生成 Windows 应用</td><td>完整的 POSIX 兼容环境,丰富的工具</td><td>灵活的环境,强大的包管理系统</td></tr><tr><td><strong>缺点</strong></td><td>工具和库较少</td><td>生成文件依赖 Cygwin DLL性能可能较低</td><td>环境较大,占用更多空间,复杂性比 MinGW-w64 高</td></tr></tbody></table><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① MinGW-w64 、Cygwin 以及 MSYS2 任选其一安装即可。</li><li>② 目前的 Win10 和 Win11 版本支持 WSL2 Windows Sub Linux 2 ,即 Windows 的子系统 Linux可以实现在 Windows 系统上安装一个 Linux ,然后再运行 Linux 中的 GCC 工具链。</li><li>③ 本人的操作系统是 Win11 ,安装和配置都将以该系统为基础作为演示,后续不再赘述!!!</li></ul></div><h2 id="_1-2-编译器的安装和配置" tabindex="-1">1.2 编译器的安装和配置 <a class="header-anchor" href="#_1-2-编译器的安装和配置" aria-label="Permalink to &quot;1.2 编译器的安装和配置&quot;"></a></h2><h3 id="_1-2-2-mingw-w64-的安装和配置" tabindex="-1">1.2.2 MinGW-w64 的安装和配置 <a class="header-anchor" href="#_1-2-2-mingw-w64-的安装和配置" aria-label="Permalink to &quot;1.2.2 MinGW-w64 的安装和配置&quot;"></a></h3><h4 id="_1-2-2-1-安装" tabindex="-1">1.2.2.1 安装 <a class="header-anchor" href="#_1-2-2-1-安装" aria-label="Permalink to &quot;1.2.2.1 安装&quot;"></a></h4><ul><li>下载到本地:略。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>下载地址在<a href="https://github.com/niXman/mingw-builds-binaries/releases/download/13.2.0-rt_v11-rev1/x86_64-13.2.0-release-posix-seh-ucrt-rt_v11-rev1.7z" target="_blank" rel="noreferrer">这里</a></p></div><p><img src="/c/assets/1.D60Zf6_d.png" alt="" loading="lazy"></p><ul><li>解压到指定的目录,即:</li></ul><p><img src="/c/assets/2.D2-G6nV2.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>本人的解压目录是:<code>D:\develop\mingw64</code></p></div><h4 id="_1-2-2-2-配置-path-环境变量" tabindex="-1">1.2.2.2 配置 path 环境变量 <a class="header-anchor" href="#_1-2-2-2-配置-path-环境变量" aria-label="Permalink to &quot;1.2.2.2 配置 path 环境变量&quot;"></a></h4><ul><li>配置环境变量,以便任意目录都可以执行 gcc 命令,即:</li></ul><p><img src="/c/assets/3.DpzkVk5V.png" alt="" loading="lazy"></p><p><img src="/c/assets/4.BXk95GIP.png" alt="" loading="lazy"></p><p><img src="/c/assets/5.CbWTB08W.png" alt="" loading="lazy"></p><p><img src="/c/assets/6.twO9TCIg.png" alt="" loading="lazy"></p><p><img src="/c/assets/7.CKOjeIvS.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>因为,本人安装 MinGW-w64 的目录是 <code>D:\develop\mingw64</code>,所以本人需要配置的 path 环境变量就是<code>D:\develop\mingw64\bin</code></p></div><p><img src="/c/assets/8.DKmR0CxE.png" alt="" loading="lazy"></p><ul><li>测试是否安装成功:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">gcc</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --version</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/9.Cudf77_s.gif" alt="" loading="lazy"></p><h3 id="_1-2-3-cygwin-的安装和配置" tabindex="-1">1.2.3 Cygwin 的安装和配置 <a class="header-anchor" href="#_1-2-3-cygwin-的安装和配置" aria-label="Permalink to &quot;1.2.3 Cygwin 的安装和配置&quot;"></a></h3><h4 id="_1-2-3-1-安装" tabindex="-1">1.2.3.1 安装 <a class="header-anchor" href="#_1-2-3-1-安装" aria-label="Permalink to &quot;1.2.3.1 安装&quot;"></a></h4><ul><li>下载到本地:略。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>下载地址在<a href="https://www.cygwin.com/install.html" target="_blank" rel="noreferrer">这里</a></p></div><p><img src="/c/assets/10.BBUUlhRC.png" alt="" loading="lazy"></p><ul><li>点击安装:</li></ul><p><img src="/c/assets/11.iLABkB7O.png" alt="" loading="lazy"></p><p><img src="/c/assets/12.BQuYWOU9.png" alt="" loading="lazy"></p><p><img src="/c/assets/13.CslpH6j0.png" alt="" loading="lazy"></p><p><img src="/c/assets/14.BAyvZdKq.png" alt="" loading="lazy"></p><p><img src="/c/assets/15.C3oC1iUd.png" alt="" loading="lazy"></p><p><img src="/c/assets/16.Ds-jsEZn.png" alt="" loading="lazy"></p><p><img src="/c/assets/17.Cd37gMYs.png" alt="" loading="lazy"></p><p><img src="/c/assets/18.CAw2z3gc.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>默认是最小化安装,没有 GCC需要选择 gcc-core、gcc-g++、make、gdb、binutils 。</p></div><p><img src="/c/assets/19.DdPThnr-.png" alt="" loading="lazy"></p><p><img src="/c/assets/20.q_rvlDnY.png" alt="" loading="lazy"></p><p><img src="/c/assets/21.JRHg9RZA.png" alt="" loading="lazy"></p><p><img src="/c/assets/22.Baq-Hb06.png" alt="" loading="lazy"></p><p><img src="/c/assets/23.c1ht53mu.png" alt="" loading="lazy"></p><p><img src="/c/assets/24.CAZmH5Py.png" alt="" loading="lazy"></p><p><img src="/c/assets/25.DWeCYBe9.png" alt="" loading="lazy"></p><p><img src="/c/assets/26.2XM8pYni.png" alt="" loading="lazy"></p><p><img src="/c/assets/27.CN0t-fuo.png" alt="" loading="lazy"></p><h4 id="_1-2-3-2-配置-path-环境变量" tabindex="-1">1.2.3.2 配置 path 环境变量 <a class="header-anchor" href="#_1-2-3-2-配置-path-环境变量" aria-label="Permalink to &quot;1.2.3.2 配置 path 环境变量&quot;"></a></h4><ul><li><code>1.2.2.2 配置 path 环境变量</code> 步骤相同:略。</li></ul><h3 id="_1-2-4-msys2-推荐" tabindex="-1">1.2.4 MSYS2推荐 <a class="header-anchor" href="#_1-2-4-msys2-推荐" aria-label="Permalink to &quot;1.2.4 MSYS2推荐&quot;"></a></h3><h4 id="_1-2-4-1-安装" tabindex="-1">1.2.4.1 安装 <a class="header-anchor" href="#_1-2-4-1-安装" aria-label="Permalink to &quot;1.2.4.1 安装&quot;"></a></h4><ul><li>下载到本地:略。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>下载地址在<a href="https://www.msys2.org/" target="_blank" rel="noreferrer">这里</a></p></div><p><img src="/c/assets/28.AcDh3LXQ.png" alt="" loading="lazy"></p><ul><li>点击安装:</li></ul><p><img src="/c/assets/29.CUkDFAc6.png" alt="" loading="lazy"></p><p><img src="/c/assets/30.picNTNaJ.png" alt="" loading="lazy"></p><p><img src="/c/assets/31.DKX92RgJ.png" alt="" loading="lazy"></p><p><img src="/c/assets/32.Bxr7QKI3.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>可能很多人,会遇到安装到 <code>50%</code> 就一直卡死在那边,不用慌,关闭它,再次重新安装即可。</p></div><p><img src="/c/assets/33.DuFWsOgW.png" alt="" loading="lazy"></p><ul><li>出现命令终端:</li></ul><p><img src="/c/assets/34.Da9qUcfr.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>如果没有出现命令终端,也不要慌,去 Win11 操作系统的<code>开始</code>菜单,那边找一下,就能找到。</p></div><ul><li>替换清华镜像源(可选):</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sed</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -i</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \</span></span>
<div id="app"><div class="Layout" data-v-5d98c3a5><!--[--><!--]--><!--[--><span tabindex="-1" data-v-0f60ec36></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-0f60ec36> Skip to content </a><!--]--><!----><header class="VPNav" data-v-5d98c3a5 data-v-ae24b3ad><div class="VPNavBar has-sidebar top" data-v-ae24b3ad data-v-6aa21345><div class="wrapper" data-v-6aa21345><div class="container" data-v-6aa21345><div class="title" data-v-6aa21345><div class="VPNavBarTitle has-sidebar" data-v-6aa21345 data-v-ab179fa1><a class="title" href="/c/" data-v-ab179fa1><!--[--><!--]--><!--[--><img class="VPImage logo" src="/c/logo.svg" alt data-v-8426fc1a><!--]--><span data-v-ab179fa1>许大仙</span><!--[--><!--]--></a></div></div><div class="content" data-v-6aa21345><div class="content-body" data-v-6aa21345><!--[--><!--]--><div class="VPNavBarSearch search" data-v-6aa21345><!--[--><!----><div id="local-search"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><span class="vp-icon DocSearch-Search-Icon"></span><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key">K</kbd></span></button></div><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-6aa21345 data-v-dc692963><span id="main-nav-aria-label" class="visually-hidden" data-v-dc692963> Main Navigation </span><!--[--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>首页</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/coa6/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>计组6件套</span><!--]--></a><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-dc692963 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-b6c34ac9><span class="text" data-v-b6c34ac9><!----><span data-v-b6c34ac9>编程语言</span><span class="vpi-chevron-down text-icon" data-v-b6c34ac9></span></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><div class="items" data-v-b98bc113><!--[--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link" href="/c/notes/" data-v-43f1e123><!--[-->c/c++<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/web-design/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->前端<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/java/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Java<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/big-data/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->大数据<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/linux/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->云原生<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/go/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Go<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/python/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Python<!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/db/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>数据库</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/open-software/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>开源软件</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/c/notes/about/" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>关于我</span><!--]--></a><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-6aa21345 data-v-6c893767><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-6c893767 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-6aa21345 data-v-0394ad82 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-6aa21345 data-v-bb2aa2f0 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-b6c34ac9><span class="vpi-more-horizontal icon" data-v-b6c34ac9></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><!----><!--[--><!--[--><!----><div class="group" data-v-bb2aa2f0><div class="item appearance" data-v-bb2aa2f0><p class="label" data-v-bb2aa2f0>深浅模式</p><div class="appearance-action" data-v-bb2aa2f0><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-bb2aa2f0 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div></div></div><div class="group" data-v-bb2aa2f0><div class="item social-links" data-v-bb2aa2f0><div class="VPSocialLinks social-links-list" data-v-bb2aa2f0 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div></div></div><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-6aa21345 data-v-e5dd9c1c><span class="container" data-v-e5dd9c1c><span class="top" data-v-e5dd9c1c></span><span class="middle" data-v-e5dd9c1c></span><span class="bottom" data-v-e5dd9c1c></span></span></button></div></div></div></div><div class="divider" data-v-6aa21345><div class="divider-line" data-v-6aa21345></div></div></div><!----></header><div class="VPLocalNav has-sidebar empty" data-v-5d98c3a5 data-v-a6f0e41e><div class="container" data-v-a6f0e41e><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-a6f0e41e><span class="vpi-align-left menu-icon" data-v-a6f0e41e></span><span class="menu-text" data-v-a6f0e41e>Menu</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-a6f0e41e data-v-17a5e62e><button data-v-17a5e62e>返回顶部</button><!----></div></div></div><aside class="VPSidebar" data-v-5d98c3a5 data-v-319d5ca6><div class="curtain" data-v-319d5ca6></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-319d5ca6><span class="visually-hidden" id="sidebar-aria-label" data-v-319d5ca6> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible has-active" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/00_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编程基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C 语言入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和进制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数据类型和运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>大话小数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>预处理器</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>内存管理</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/12_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-basic/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>调试工具和调试技巧gdb和make</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/14_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>常用库函数</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言高级</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和内存分布</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针强化</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>结构体和文件的高级用法</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>链表和回调函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编译过程和面向接口</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>项目构建工具</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>meson</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>meson 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Cmake</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Cmake 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_${commonDirectoryName}/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Conan </p><!--]--></a><!----></div><!----></div><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Gradle</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Gradle 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>Linux</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/04_linux/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Linux 初识和安装</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C++ 基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量、数据类型、运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>类和对象</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 引用</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>继承和派生</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 多态和虚函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/12_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>运算符重载</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>模板</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/14_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 异常</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/15_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>面向对象进阶</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/16_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作和 IO 流</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/17_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>STL标准模板库</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>C++ 高级</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>QT 桌面开发</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>Linux 高并发服务器开发</p><!----></div><!----></div></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-5d98c3a5 data-v-1428d186><div class="VPDoc has-sidebar has-aside" data-v-1428d186 data-v-39a288b8><!--[--><!--]--><div class="container" data-v-39a288b8><div class="aside" data-v-39a288b8><div class="aside-curtain" data-v-39a288b8></div><div class="aside-container" data-v-39a288b8><div class="aside-content" data-v-39a288b8><div class="VPDocAside" data-v-39a288b8 data-v-3f215769><!--[--><!--]--><!--[--><!--]--><nav aria-labelledby="doc-outline-aria-label" class="VPDocAsideOutline" data-v-3f215769 data-v-a5bbad30><div class="content" data-v-a5bbad30><div class="outline-marker" data-v-a5bbad30></div><div aria-level="2" class="outline-title" id="doc-outline-aria-label" role="heading" data-v-a5bbad30>目录</div><ul class="VPDocOutlineItem root" data-v-a5bbad30 data-v-b933a997><!--[--><!--]--></ul></div></nav><!--[--><!--]--><div class="spacer" data-v-3f215769></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-39a288b8><div class="content-container" data-v-39a288b8><!--[--><!--]--><main class="main" data-v-39a288b8><div style="position:relative;" class="vp-doc _c_notes_01_c-basic_01_xdx_" data-v-39a288b8><div><h1 id="第一章-开发环境的安装和配置-⭐" tabindex="-1">第一章:开发环境的安装和配置(⭐) <a class="header-anchor" href="#第一章-开发环境的安装和配置-⭐" aria-label="Permalink to &quot;第一章:开发环境的安装和配置(⭐)&quot;"></a></h1><h2 id="_1-1-什么是编译器" tabindex="-1">1.1 什么是编译器? <a class="header-anchor" href="#_1-1-什么是编译器" aria-label="Permalink to &quot;1.1 什么是编译器?&quot;"></a></h2><ul><li>要开发 C/C++ 程序,需要安装 C/C++ 编译器,目前有两种主流实现,即: <ul><li>GCCGNU Compiler Collection全平台实现即支持 Windows、MacOS、Linux 等。</li><li>MSVCMicrosoft Visual C++):只支持 Windows 系统。</li></ul></li><li>GCC 在 Windows 上的版本有很多,如:<a href="https://www.mingw-w64.org/" target="_blank" rel="noreferrer">MinGW-w64</a><a href="https://cygwin.com/" target="_blank" rel="noreferrer">Gygwin</a><a href="https://www.msys2.org/" target="_blank" rel="noreferrer">MSYS2</a>。它们之间的区别,如下所示:</li></ul><table tabindex="0"><thead><tr><th>特性</th><th>MinGW-w64</th><th>Cygwin</th><th>MSYS2</th></tr></thead><tbody><tr><td><strong>简介</strong></td><td>Minimalist GNU for Windows</td><td>POSIX 兼容环境和工具集</td><td>结合了 MinGW 和 Cygwin 的工具集</td></tr><tr><td><strong>编译器</strong></td><td>提供 GCC 编译器</td><td>提供 POSIX 兼容环境,包含大量工具</td><td>提供 MinGW-w64 工具链和 Cygwin 环境</td></tr><tr><td><strong>生成文件</strong></td><td>Windows 原生可执行文件</td><td>POSIX 兼容的可执行文件</td><td>可以生成 Windows 原生可执行文件或 POSIX 文件</td></tr><tr><td><strong>依赖</strong></td><td>无需额外依赖</td><td>依赖 Cygwin DLL</td><td>根据使用工具链决定MinGW-w64 无依赖Cygwin 有依赖)</td></tr><tr><td><strong>工具和库</strong></td><td>基本的编译工具</td><td>丰富的 Unix 工具和库</td><td>丰富的工具和库,强大的包管理系统</td></tr><tr><td><strong>性能</strong></td><td>性能较好</td><td>可能较低,因为通过兼容层调用系统</td><td>取决于使用的工具链MinGW-w64 性能较好)</td></tr><tr><td><strong>复杂度</strong></td><td>简单易用</td><td>设置和使用相对复杂</td><td>较为灵活,复杂度介于 MinGW-w64 和 Cygwin 之间</td></tr><tr><td><strong>适用场景</strong></td><td>开发 Windows 原生应用</td><td>运行和开发 Unix 程序</td><td>混合使用 Unix 工具和开发 Windows 原生应用</td></tr><tr><td><strong>优点</strong></td><td>轻量级,直接生成 Windows 应用</td><td>完整的 POSIX 兼容环境,丰富的工具</td><td>灵活的环境,强大的包管理系统</td></tr><tr><td><strong>缺点</strong></td><td>工具和库较少</td><td>生成文件依赖 Cygwin DLL性能可能较低</td><td>环境较大,占用更多空间,复杂性比 MinGW-w64 高</td></tr></tbody></table><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① MinGW-w64 、Cygwin 以及 MSYS2 任选其一安装即可。</li><li>② 目前的 Win10 和 Win11 版本支持 WSL2 Windows Sub Linux 2 ,即 Windows 的子系统 Linux可以实现在 Windows 系统上安装一个 Linux ,然后再运行 Linux 中的 GCC 工具链。</li><li>③ 本人的操作系统是 Win11 ,安装和配置都将以该系统为基础作为演示,后续不再赘述!!!</li></ul></div><h2 id="_1-2-编译器的安装和配置" tabindex="-1">1.2 编译器的安装和配置 <a class="header-anchor" href="#_1-2-编译器的安装和配置" aria-label="Permalink to &quot;1.2 编译器的安装和配置&quot;"></a></h2><h3 id="_1-2-2-mingw-w64-的安装和配置" tabindex="-1">1.2.2 MinGW-w64 的安装和配置 <a class="header-anchor" href="#_1-2-2-mingw-w64-的安装和配置" aria-label="Permalink to &quot;1.2.2 MinGW-w64 的安装和配置&quot;"></a></h3><h4 id="_1-2-2-1-安装" tabindex="-1">1.2.2.1 安装 <a class="header-anchor" href="#_1-2-2-1-安装" aria-label="Permalink to &quot;1.2.2.1 安装&quot;"></a></h4><ul><li>下载到本地:略。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>下载地址在<a href="https://github.com/niXman/mingw-builds-binaries/releases/download/13.2.0-rt_v11-rev1/x86_64-13.2.0-release-posix-seh-ucrt-rt_v11-rev1.7z" target="_blank" rel="noreferrer">这里</a></p></div><p><img src="/c/assets/1.D60Zf6_d.png" alt="" loading="lazy"></p><ul><li>解压到指定的目录,即:</li></ul><p><img src="/c/assets/2.D2-G6nV2.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>本人的解压目录是:<code>D:\develop\mingw64</code></p></div><h4 id="_1-2-2-2-配置-path-环境变量" tabindex="-1">1.2.2.2 配置 path 环境变量 <a class="header-anchor" href="#_1-2-2-2-配置-path-环境变量" aria-label="Permalink to &quot;1.2.2.2 配置 path 环境变量&quot;"></a></h4><ul><li>配置环境变量,以便任意目录都可以执行 gcc 命令,即:</li></ul><p><img src="/c/assets/3.DpzkVk5V.png" alt="" loading="lazy"></p><p><img src="/c/assets/4.BXk95GIP.png" alt="" loading="lazy"></p><p><img src="/c/assets/5.CbWTB08W.png" alt="" loading="lazy"></p><p><img src="/c/assets/6.twO9TCIg.png" alt="" loading="lazy"></p><p><img src="/c/assets/7.CKOjeIvS.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>因为,本人安装 MinGW-w64 的目录是 <code>D:\develop\mingw64</code>,所以本人需要配置的 path 环境变量就是<code>D:\develop\mingw64\bin</code></p></div><p><img src="/c/assets/8.DKmR0CxE.png" alt="" loading="lazy"></p><ul><li>测试是否安装成功:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">gcc</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --version</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/9.Cudf77_s.gif" alt="" loading="lazy"></p><h3 id="_1-2-3-cygwin-的安装和配置" tabindex="-1">1.2.3 Cygwin 的安装和配置 <a class="header-anchor" href="#_1-2-3-cygwin-的安装和配置" aria-label="Permalink to &quot;1.2.3 Cygwin 的安装和配置&quot;"></a></h3><h4 id="_1-2-3-1-安装" tabindex="-1">1.2.3.1 安装 <a class="header-anchor" href="#_1-2-3-1-安装" aria-label="Permalink to &quot;1.2.3.1 安装&quot;"></a></h4><ul><li>下载到本地:略。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>下载地址在<a href="https://www.cygwin.com/install.html" target="_blank" rel="noreferrer">这里</a></p></div><p><img src="/c/assets/10.BBUUlhRC.png" alt="" loading="lazy"></p><ul><li>点击安装:</li></ul><p><img src="/c/assets/11.iLABkB7O.png" alt="" loading="lazy"></p><p><img src="/c/assets/12.BQuYWOU9.png" alt="" loading="lazy"></p><p><img src="/c/assets/13.CslpH6j0.png" alt="" loading="lazy"></p><p><img src="/c/assets/14.BAyvZdKq.png" alt="" loading="lazy"></p><p><img src="/c/assets/15.C3oC1iUd.png" alt="" loading="lazy"></p><p><img src="/c/assets/16.Ds-jsEZn.png" alt="" loading="lazy"></p><p><img src="/c/assets/17.Cd37gMYs.png" alt="" loading="lazy"></p><p><img src="/c/assets/18.CAw2z3gc.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>默认是最小化安装,没有 GCC需要选择 gcc-core、gcc-g++、make、gdb、binutils 。</p></div><p><img src="/c/assets/19.DdPThnr-.png" alt="" loading="lazy"></p><p><img src="/c/assets/20.q_rvlDnY.png" alt="" loading="lazy"></p><p><img src="/c/assets/21.JRHg9RZA.png" alt="" loading="lazy"></p><p><img src="/c/assets/22.Baq-Hb06.png" alt="" loading="lazy"></p><p><img src="/c/assets/23.c1ht53mu.png" alt="" loading="lazy"></p><p><img src="/c/assets/24.CAZmH5Py.png" alt="" loading="lazy"></p><p><img src="/c/assets/25.DWeCYBe9.png" alt="" loading="lazy"></p><p><img src="/c/assets/26.2XM8pYni.png" alt="" loading="lazy"></p><p><img src="/c/assets/27.CN0t-fuo.png" alt="" loading="lazy"></p><h4 id="_1-2-3-2-配置-path-环境变量" tabindex="-1">1.2.3.2 配置 path 环境变量 <a class="header-anchor" href="#_1-2-3-2-配置-path-环境变量" aria-label="Permalink to &quot;1.2.3.2 配置 path 环境变量&quot;"></a></h4><ul><li><code>1.2.2.2 配置 path 环境变量</code> 步骤相同:略。</li></ul><h3 id="_1-2-4-msys2-推荐" tabindex="-1">1.2.4 MSYS2推荐 <a class="header-anchor" href="#_1-2-4-msys2-推荐" aria-label="Permalink to &quot;1.2.4 MSYS2推荐&quot;"></a></h3><h4 id="_1-2-4-1-安装" tabindex="-1">1.2.4.1 安装 <a class="header-anchor" href="#_1-2-4-1-安装" aria-label="Permalink to &quot;1.2.4.1 安装&quot;"></a></h4><ul><li>下载到本地:略。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>下载地址在<a href="https://www.msys2.org/" target="_blank" rel="noreferrer">这里</a></p></div><p><img src="/c/assets/28.AcDh3LXQ.png" alt="" loading="lazy"></p><ul><li>点击安装:</li></ul><p><img src="/c/assets/29.CUkDFAc6.png" alt="" loading="lazy"></p><p><img src="/c/assets/30.picNTNaJ.png" alt="" loading="lazy"></p><p><img src="/c/assets/31.DKX92RgJ.png" alt="" loading="lazy"></p><p><img src="/c/assets/32.Bxr7QKI3.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>可能很多人,会遇到安装到 <code>50%</code> 就一直卡死在那边,不用慌,关闭它,再次重新安装即可。</p></div><p><img src="/c/assets/33.DuFWsOgW.png" alt="" loading="lazy"></p><ul><li>出现命令终端:</li></ul><p><img src="/c/assets/34.Da9qUcfr.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>如果没有出现命令终端,也不要慌,去 Win11 操作系统的<code>开始</code>菜单,那边找一下,就能找到。</p></div><ul><li>替换清华镜像源(可选):</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sed</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -i</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;s#https\?://mirror.msys2.org/#https://mirrors.tuna.tsinghua.edu.cn/msys2/#g&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /etc/pacman.d/mirrorlist</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">*</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p><img src="/c/assets/35.7_gEABSX.gif" alt="" loading="lazy"></p><ul><li>安装 gcc 等相关开发包:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">pacman</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -Syu</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --noconfirm</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 更新包管理器</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">pacman</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -Sy</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> base-devel</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --noconfirm</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 安装开发工具包</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">pacman</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -Sy</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> mingw-w64-ucrt-x86_64-toolchain</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --noconfirm</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 安装开发 gcc 相关工具链</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>也许,你会看到其他人的安装命令是 <code>pacman -Sy mingw-w64-x86_64-toolchain --noconfirm</code>,此处解释下两者的区别:</p><ul><li><code>mingw-w64-x86_64-toolchain</code> 使用更传统的 MSVCRT适合需要经典 MinGW 环境的项目或依赖较老 C 运行时的应用。</li><li><code>mingw-w64-ucrt-x86_64-toolchain</code> 使用 Microsoft 的 UCRT更适合现代 Windows 开发,提供更好的兼容性和性能。</li></ul></div><p><img src="/c/assets/36.C2KQYoVC.gif" alt="" loading="lazy"></p><h4 id="_1-2-4-2-配置-path-环境变量" tabindex="-1">1.2.4.2 配置 path 环境变量 <a class="header-anchor" href="#_1-2-4-2-配置-path-环境变量" aria-label="Permalink to &quot;1.2.4.2 配置 path 环境变量&quot;"></a></h4><ul><li><code>1.2.2.2 配置 path 环境变量</code> 步骤相同:略。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>本人需要配置的 path 环境变量是 <code>C:\msys64\ucrt64\bin</code></p></div><h2 id="_1-3-什么是-ide-集成开发环境" tabindex="-1">1.3 什么是 IDE集成开发环境 <a class="header-anchor" href="#_1-3-什么是-ide-集成开发环境" aria-label="Permalink to &quot;1.3 什么是 IDE集成开发环境&quot;"></a></h2><ul><li><p>在实际开发中,除了<code>编译器</code>是必须安装的工具之外,我们往往还需要很多其他的辅助软件,如下所示:</p><ul><li>编辑器:用来编写代码,并且给代码着色,以方便阅读。</li><li>代码提示器:输入部分代码,即可提示全部代码,加速代码的编写过程。</li><li>调试器:观察程序的每一个运行步骤,发现程序的逻辑错误。</li><li>项目管理工具:对程序涉及到的所有资源进行管理,包括:源文件、图片、视频、第三方库等。</li><li>漂亮的界面:各种按钮、面板、菜单、窗口等控件整齐排布,操作更方便。</li></ul></li><li><p>这些工具通常被打包在一起统一安装和发布Visual Studio、CLion 以及 VS Code 通常统称为集成开发环境IDEIntegrated Development Environment</p></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① IDE集成开发环境就是一系列开发工具的组合套装。这就好比台式机核心部件是主机。主机就相当于 IDE 的代码编辑器和编译器有了它们开发者就可以进行基本的编程工作。然而正如我们在购买台式机时通常还会附带显示器、键盘、鼠标、U盘、摄像头等外围设备IDE 也同样提供了一系列额外的工具和插件,比如:调试器、版本控制集成、代码补全、代码重构工具等。这些“外围设备”让开发过程更加高效、直观,并且能够满足更多的开发需求,使得 IDE 成为一个完整的开发环境。</li><li>② 严格来讲, VS Code 属于编辑器,而不是 IDE但是可以通过安装各种插件来完成 IDE 的功能;而 Visual Studio 和 CLion 属于 IDE。</li><li>③ 在实际开发中,使用 IDE 进行编程并不是一种非常丢人的事情。而使用编辑器,如:<code>记事本</code><code>vi/vim</code> 等,进行编程,也并不是一件非常骄傲的事情。可能有些人会在网上发布这样的言论:“学习编程,刚开始需要使用<code>记事本</code><code>vi/vim</code>等简单的编辑器软件,不要使用 IDE ”,目的可能是为了让初学者熟悉编程的基础概念和语法,并避免依赖 IDE 的辅助功能。但是,这种方法或许可以起到锻炼基础技能的功能,但这并不意味着 IDE 就不适合初学者。事实上,许多 IDE 还提供了初学者友好的界面和工具,可以帮助新手更快地入门和理解编程。</li></ul></div><h2 id="_1-4-ide-的安装和配置" tabindex="-1">1.4 IDE 的安装和配置 <a class="header-anchor" href="#_1-4-ide-的安装和配置" aria-label="Permalink to &quot;1.4 IDE 的安装和配置&quot;"></a></h2><h3 id="_1-4-1-clion" tabindex="-1">1.4.1 CLion <a class="header-anchor" href="#_1-4-1-clion" aria-label="Permalink to &quot;1.4.1 CLion&quot;"></a></h3><h4 id="_1-4-1-1-概述" tabindex="-1">1.4.1.1 概述 <a class="header-anchor" href="#_1-4-1-1-概述" aria-label="Permalink to &quot;1.4.1.1 概述&quot;"></a></h4><ul><li><a href="https://www.jetbrains.com/clion/" target="_blank" rel="noreferrer">CLion</a> 是一款由 JetBrains 推出的跨平台 C/C++ 集成开发环境IDE它具有智能编辑器、CMake 构建支持、调试器、单元测试、代码分析等功能,可以极大提高 C/C++ 开发效率。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 本次,演示的 CLion 的安装版本是 2024.1.4 ,后续版本可能会更新,但是操作几乎不会发生太多变化!!!</li><li>② CLion 作为一个 IDE本身就携带了各个平台操作系统的 C 语言编译器Windows 中就是 MinGW但是CLion 中自带的 C 语言编译器版本可能并非我们实际开发所想要的,这也是在 Windows 中,为什么推荐使用 MSYS2 的原因所在。</li></ul></div><h4 id="_1-4-1-2-安装" tabindex="-1">1.4.1.2 安装 <a class="header-anchor" href="#_1-4-1-2-安装" aria-label="Permalink to &quot;1.4.1.2 安装&quot;"></a></h4><ul><li>鼠标双击,进入安装:</li></ul><p><img src="/c/assets/37.RTUP8Vtx.png" alt="" loading="lazy"></p><ul><li>下一步:</li></ul><p><img src="/c/assets/38.Dq21DxwL.png" alt="" loading="lazy"></p><ul><li>下一步:</li></ul><p><img src="/c/assets/39.QmpUaNxU.png" alt="" loading="lazy"></p><ul><li>下一步:</li></ul><p><img src="/c/assets/40.DP0C29gZ.png" alt="" loading="lazy"></p><ul><li>安装:</li></ul><p><img src="/c/assets/41.DwzHokd4.png" alt="" loading="lazy"></p><ul><li>安装完成:</li></ul><p><img src="/c/assets/42.Bi6K26yA.png" alt="" loading="lazy"></p><h4 id="_1-4-1-3-配置" tabindex="-1">1.4.1.3 配置 <a class="header-anchor" href="#_1-4-1-3-配置" aria-label="Permalink to &quot;1.4.1.3 配置&quot;"></a></h4><ul><li>打开 CLion </li></ul><p><img src="/c/assets/43.Bw8DcEQ_.png" alt="" loading="lazy"></p><ul><li>安装中文插件(可选):</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>对于以中文、韩语和日语为母语的开发者CLion 在 2024.2 之后的版本就绑定了本地化插件,即不需要再安装本地化插件了。</p></div><p><img src="/c/assets/44.DPc8Z9rS.png" alt="" loading="lazy"></p><p><img src="/c/assets/45.S84xHMTl.png" alt="" loading="lazy"></p><ul><li>配置新 UI </li></ul><p><img src="/c/assets/46.iw3JQUkn.png" alt="" loading="lazy"></p><p><img src="/c/assets/47.ILeJt-HK.png" alt="" loading="lazy"></p><ul><li>新 UI 配置自定义字体(可选):</li></ul><p><img src="/c/assets/48.CHgm7khh.png" alt="" loading="lazy"></p><ul><li>配置<code>自动保存</code>功能:</li></ul><p><img src="/c/assets/49.N1nqJaEg.png" alt="" loading="lazy"></p><ul><li>配置<code>文件编码</code> 为 UTF-8</li></ul><p><img src="/c/assets/50.DHsnibMi.png" alt="" loading="lazy"></p><ul><li>配置<code>控制台编码</code>为 UTF-8</li></ul><p><img src="/c/assets/51.BQr6Q0uV.png" alt="" loading="lazy"></p><ul><li>配置<code>显示方法分隔符</code>功能:</li></ul><p><img src="/c/assets/52.BVemi2Lh.png" alt="" loading="lazy"></p><ul><li>配置<code>编辑器</code>的字体(可选):</li></ul><p><img src="/c/assets/53.BHR69UXx.png" alt="" loading="lazy"></p><ul><li>检测 GCC 工具链是否安装成功:</li></ul><p><img src="/c/assets/54.CPSU5SJI.png" alt="" loading="lazy"></p><h3 id="_1-4-2-vs-code" tabindex="-1">1.4.2 VS Code <a class="header-anchor" href="#_1-4-2-vs-code" aria-label="Permalink to &quot;1.4.2 VS Code&quot;"></a></h3><h4 id="_1-4-2-1-概述" tabindex="-1">1.4.2.1 概述 <a class="header-anchor" href="#_1-4-2-1-概述" aria-label="Permalink to &quot;1.4.2.1 概述&quot;"></a></h4><ul><li><a href="https://code.visualstudio.com/" target="_blank" rel="noreferrer">Visual Studio Code (VS Code)</a> 是一个免费的开源代码编辑器,适用于 Windows、MacOS 和 Linux 平台。它支持语法高亮、智能代码补全IntelliSense、内置调试工具和Git集成。用户可以通过扩展来添加更多功能支持新的编程语言、主题和调试工具。VS Code 还支持在微软 Azure 上进行部署和托管,适用于各种编程语言和框架。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① Visual Studio Code 需要安装对应的插件,才能运行 C/C++ 代码。</li><li>② Visual Studio Code 除了开源免费的优点之外,还有一个优点就是插件巨多(几乎所有主流的编程语言都提供有对应的插件),这也是很多程序员喜欢使用它的原因。</li></ul></div><h4 id="_1-4-2-2-安装" tabindex="-1">1.4.2.2 安装 <a class="header-anchor" href="#_1-4-2-2-安装" aria-label="Permalink to &quot;1.4.2.2 安装&quot;"></a></h4><ul><li>鼠标双击,进入安装:</li></ul><p><img src="/c/assets/55.CaQLoDlw.png" alt="" loading="lazy"></p><ul><li>同意协议:</li></ul><p><img src="/c/assets/56.aRGy4XbL.png" alt="" loading="lazy"></p><ul><li>下一步:</li></ul><p><img src="/c/assets/57.kNO9fmPR.png" alt="" loading="lazy"></p><ul><li>下一步:</li></ul><p><img src="/c/assets/58.D4EkoC4o.png" alt="" loading="lazy"></p><ul><li>下一步:</li></ul><p><img src="/c/assets/59.V23Lo9e_.png" alt="" loading="lazy"></p><ul><li>安装:</li></ul><p><img src="/c/assets/60.Du9LVeMB.png" alt="" loading="lazy"></p><ul><li>安装过程:</li></ul><p><img src="/c/assets/61.DdFg75U9.png" alt="" loading="lazy"></p><ul><li>安装完成:</li></ul><p><img src="/c/assets/62.C6bz6KtT.png" alt="" loading="lazy"></p><h4 id="_1-4-2-3-配置" tabindex="-1">1.4.2.3 配置 <a class="header-anchor" href="#_1-4-2-3-配置" aria-label="Permalink to &quot;1.4.2.3 配置&quot;"></a></h4><ul><li>安装<code>中文</code>插件:</li></ul><p><img src="/c/assets/63.CB6LAhB5.png" alt="" loading="lazy"></p><p><img src="/c/assets/64.Bip8bkua.png" alt="" loading="lazy"></p><ul><li>安装 <code>C/C++</code> 插件:</li></ul><p><img src="/c/assets/65.DRNHRduW.png" alt="" loading="lazy"></p><p><img src="/c/assets/66.Cth4qqEn.png" alt="" loading="lazy"></p><h3 id="_1-4-3-microsoft-visual-studio" tabindex="-1">1.4.3 Microsoft Visual Studio <a class="header-anchor" href="#_1-4-3-microsoft-visual-studio" aria-label="Permalink to &quot;1.4.3 Microsoft Visual Studio&quot;"></a></h3><h4 id="_1-4-3-1-概述" tabindex="-1">1.4.3.1 概述 <a class="header-anchor" href="#_1-4-3-1-概述" aria-label="Permalink to &quot;1.4.3.1 概述&quot;"></a></h4><ul><li><a href="https://visualstudio.microsoft.com/" target="_blank" rel="noreferrer">Visual Studio</a>(简称 VS是由微软公司发布的集成开发环境。它包括了整个软件生命周期中所需要的大部分工具UML 工具、代码管控工具、项目版本控制 Git 等。</li><li>Visual Studio 支持 C/C++、C#、F#、VB 等多种程序语言的开发和测试,可以用于生成 Web 应用程序,也可以生成桌面应用程序,功能十分强大,但下载和安装很可能耗时数小时,还可能会塞满磁盘。</li><li>Visual Studio 有三种版本:社区版(免费,不支持企业使用),专业版(收费)和企业版(收费)。企业版拥有面向架构师的功能、高级调试和测试,这些功能是另外两种版本所没有的。</li><li>Visual Studio 旨在成为世界上最好的 IDE集成开发环境号称“宇宙第一强大 IDE”。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>本次,演示的 Visual Studio 的安装版本是 Visual Studio 2022 ,后续版本可能会更新,但是操作几乎不会发生太多变化!!!</p></div><h4 id="_1-4-3-2-安装" tabindex="-1">1.4.3.2 安装 <a class="header-anchor" href="#_1-4-3-2-安装" aria-label="Permalink to &quot;1.4.3.2 安装&quot;"></a></h4><ul><li>鼠标双击,进入安装:</li></ul><p><img src="/c/assets/67.DWGWZ64P.png" alt="" loading="lazy"></p><ul><li>继续:</li></ul><p><img src="/c/assets/68.3hDIDdvx.png" alt="" loading="lazy"></p><ul><li>等待:</li></ul><p><img src="/c/assets/69.Bw_dQ4ap.png" alt="" loading="lazy"></p><ul><li>工作负荷(使用 C++ 的桌面开发):</li></ul><p><img src="/c/assets/70.Cn_ubTyA.png" alt="" loading="lazy"></p><ul><li>单个组件:</li></ul><p><img src="/c/assets/71.C84EBqwB.png" alt="" loading="lazy"></p><ul><li>语言包:</li></ul><p><img src="/c/assets/72.dZfJY4eR.png" alt="" loading="lazy"></p><ul><li>安装位置(修改默认的安装位置):</li></ul><p><img src="/c/assets/73.B0zm0Z79.png" alt="" loading="lazy"></p><ul><li>如果不是第一次安装,可能会出现<code>共享组件、工具和 SDK</code>不可以修改,即:</li></ul><p><img src="/c/assets/74.CaTcEy1Q.png" alt="" loading="lazy"></p><ul><li>此时,就需要打开<code>注册表编辑器</code>,将如下图中的除了第一个选项,全部删除,然后关闭再重新安装,即:</li></ul><p><img src="/c/assets/75.iEc8mo9g.png" alt="" loading="lazy"></p><ul><li>开始安装:</li></ul><p><img src="/c/assets/76.Co2KxM6t.png" alt="" loading="lazy"></p><ul><li>安装中:</li></ul><p><img src="/c/assets/77.CaUm8Qhc.png" alt="" loading="lazy"></p><ul><li>安装完成,然后关闭:</li></ul><p><img src="/c/assets/78.kOkqIKG6.png" alt="" loading="lazy"></p><h4 id="_1-4-3-3-配置" tabindex="-1">1.4.3.3 配置 <a class="header-anchor" href="#_1-4-3-3-配置" aria-label="Permalink to &quot;1.4.3.3 配置&quot;"></a></h4><ul><li>在开始菜单处,启动 VS </li></ul><p><img src="/c/assets/79.CyeASH-c.png" alt="" loading="lazy"></p><ul><li>登录或跳过该选项(有微软账号就注册,没有就暂时跳过):</li></ul><p><img src="/c/assets/80.CFdk60La.png" alt="" loading="lazy"></p><ul><li>继续:</li></ul><p><img src="/c/assets/81.Bhl-0uK_.png" alt="" loading="lazy"></p><ul><li>注册 VS </li></ul><p><img src="/c/assets/82.Dni9KbXV.png" alt="" loading="lazy"></p><ul><li>填写注册码:</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① Pro 版本:<code>TD244-P4NB7-YQ6XK-Y8MMM-YWV2J</code></li><li>② Enterprise 版本:<code>VHF9H-NXBBB-638P6-6JHCY-88JWH</code></li></ul></div><p><img src="/c/assets/83.BXx10MCV.png" alt="" loading="lazy"></p><p><img src="/c/assets/84.CXcIKX1T.png" alt="" loading="lazy"></p><h2 id="_1-5-什么是工程-项目" tabindex="-1">1.5 什么是工程/项目 <a class="header-anchor" href="#_1-5-什么是工程-项目" aria-label="Permalink to &quot;1.5 什么是工程/项目 &quot;"></a></h2><h3 id="_1-5-1-概述" tabindex="-1">1.5.1 概述 <a class="header-anchor" href="#_1-5-1-概述" aria-label="Permalink to &quot;1.5.1 概述&quot;"></a></h3><ul><li>一个真正的软件往往包含多项功能,每一项功能都需要几十行、几千行甚至几万行的代码,如果我们将这些代码都放到一个源文件中,不但打开的速度极慢,代码的编写和维护也会变得非常困难。</li><li>在实际开发中,随着软件规模的增加,代码的复杂性也会显著提升,为了提高代码的易读性、维护性等,程序员会将代码按照功能分别放到不同的源文件中。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>需要说明的是,一个真正的软件除了源代码之外,往往还会包括图片、视频、音频、库(框架)等其它资源,这些也是一个个的文件。</p></div><ul><li>为了有效的管理这些种类繁杂、数目众多的文件,我们会将这些文件按照功能放到不同的目录中进行统一管理,并且这个目录下只存放与当前程序有关的资源。其实,这就是工程或项目。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>总结:</p><ul><li>① 随着软件规模的增加,代码的复杂性也会显著提升。将代码分割成多个模块或文件并分别管理,可以减少每个文件的复杂度,使代码更易读、易理解、易维护。工程提供了一个结构化的环境,将这些文件组织在一个系统化的目录结构中。</li><li>② 除了代码,软件开发还涉及到各种资源的管理,如:图片、音频、视频、配置文件等。工程能够帮助开发者将这些资源合理地分类存放,并与代码一同管理,确保它们在开发、编译和运行时能被正确引用。</li></ul></div><ul><li>许多 IDE 都提供了工程或项目的概念,其目的就是为了帮助开发者合理的管理软件开发中所需要的资源,如:图片、视频、音频、库(框架)等。</li></ul><p><img src="/c/assets/85.DptbJqQo.png" alt="" loading="lazy"></p><h3 id="_1-5-2-工程类型-项目类型" tabindex="-1">1.5.2 工程类型/项目类型 <a class="header-anchor" href="#_1-5-2-工程类型-项目类型" aria-label="Permalink to &quot;1.5.2 工程类型/项目类型&quot;"></a></h3><ul><li><p>程序或软件是一个非常宽泛的概念,它可以细分为很多种类,如下所示:</p><ul><li>控制台程序Console Application控制台程序是一种不具备图形用户界面的程序它通过文本方式与用户交互通常运行在命令行窗口黑底白字的终端Unix/Linux 中的<code>ls</code>命令、Windows 中的<code>cmd.exe</code>等。</li><li>GUI 程序Graphical User Interface ProgramGUI 程序是一种具有图形用户界面的程序通过窗口、按钮、菜单等图形控件与用户交互微信、QQ 等。</li><li>静态库和动态库:不单独出现,而是作为其它程序的一个组成部分,普通用户很难接触到它们。 <ul><li>静态库指的是在编译时包含到程序中的库,程序不依赖外部文件运行,如:在 C/C++ 中,静态库通常以<code>.lib</code>Windows<code>.a</code>Unix/Linux为扩展名。</li><li>动态库指的是在运行时加载的库,允许多个程序共享,并且程序在运行时依赖这些库,如: 在Windows中动态库通常以<code>.dll</code>为扩展名;在 Unix/Linux 中,以<code>.so</code>为扩展名。</li></ul></li></ul></li><li><p>不同类型的程序控制台程序、GUI 程序、静态库、动态库等)需要不同的配置和文件结构,因此在 IDE 中创建项目时,选择正确的工程类型非常重要。不同的工程类型决定了 IDE 为我们生成的初始文件、目录结构,以及预设的一些编译和链接参数。</p></li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li>① 控制台程序适合初学者,因为它更简单,没有复杂的界面元素,开发时可以专注于逻辑和代码本身。</li><li>② 而 GUI 程序则涉及到用户界面设计和事件驱动编程,更适合有一定编程基础的人进行学习和开发。</li></ul></div><h1 id="第二章-c-语言入门-helloworld-⭐" tabindex="-1">第二章C 语言入门HelloWorld <a class="header-anchor" href="#第二章-c-语言入门-helloworld-⭐" aria-label="Permalink to &quot;第二章C 语言入门HelloWorld&quot;"></a></h1><h2 id="_2-1-手动版" tabindex="-1">2.1 手动版 <a class="header-anchor" href="#_2-1-手动版" aria-label="Permalink to &quot;2.1 手动版&quot;"></a></h2><ul><li>① 新建一个 <code>HelloWorld.c</code> 的文件:</li></ul><p><img src="/c/assets/86.CQ3_QCQT.png" alt="" loading="lazy"></p><ul><li>② 通过<code>记事本</code>等软件打开该文件,输入如下的代码,并保存:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
@ -314,12 +314,12 @@
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> libelf++0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> libbfb0-dev</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> python-dev-is-python3</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><p><img src="/c/assets/161.BPOK9irZ.gif" alt="" loading="lazy"></p><ul><li>下载源码:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">git</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> clone</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --depth</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --single-branch</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --branch=linux-msft-wsl-${</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">KERNEL_VERSION</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">}</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> https://github.com/microsoft/WSL2-Linux-Kernel.git</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p><img src="/c/assets/162.B1eB55rC.gif" alt="" loading="lazy"></p><ul><li>编译内核代码:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">cd</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> WSL2-Linux-Kernel</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">make</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -j</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">nproc</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">KCONFIG_CONFIG=Microsoft/config-wsl</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/163.VIcU-hkN.gif" alt="" loading="lazy"></p><ul><li>编译 perf 工具:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">cd</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> tools/perf</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">make</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> clean</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &amp;&amp; </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">make</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/164.BM9viRZJ.gif" alt="" loading="lazy"></p><ul><li>复制到 PATH 变量所指向的路径中:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">cp</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> perf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /usr/bin/</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/165.DpMBA1SK.gif" alt="" loading="lazy"></p><h3 id="_8-4-3-整合" tabindex="-1">8.4.3 整合 <a class="header-anchor" href="#_8-4-3-整合" aria-label="Permalink to &quot;8.4.3 整合&quot;"></a></h3><ul><li>CLion 中配置 perf 的路径:</li></ul><p><img src="/c/assets/166.DgXuU6LF.png" alt="" loading="lazy"></p><ul><li>在 CLion 中通过 perf 运行代码:</li></ul><p><img src="/c/assets/167.Dnw73s2h.gif" alt="" loading="lazy"></p><h2 id="_8-5-win-中文乱码问题" tabindex="-1">8.5 Win 中文乱码问题 <a class="header-anchor" href="#_8-5-win-中文乱码问题" aria-label="Permalink to &quot;8.5 Win 中文乱码问题&quot;"></a></h2><ul><li>前文,我们提及到,在 Win 中,如果出现<code>中文乱码</code>问题,就需要去<code>语言和区别</code>设置<code>系统区域</code>的编码为 UTF-8 但是这样可能会造成其它的软件出现中文乱码问题Xshell 等。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 之所以,修改系统的编码为 UTF-8 会出现问题,是因为早期的 Win 系统的中文默认编码是 GBK目前也是Win 并没有强制第三方软件使用 UTF-8 编码) ,而 Xshell 等也使用的这些编码,一旦我们修改为 UTF-8 之后,可能会造成这些第三方软件出现中文乱码问题(第三方软件适配问题,相信将来应该都会切换为 UTF-8 编码),体验较差!!!</li><li>② 在 Linux 或 MacOS 之所以不会出现中文乱码的问题,是因为这些系统默认的编码就是 UTF-8 。</li></ul></div><ul><li>其实,还有一种解决方案,如下所示:</li></ul><p><img src="/c/assets/168.SnFXRSaL.png" alt="" loading="lazy"></p><p><img src="/c/assets/169.DnoEqOjV.png" alt="" loading="lazy"></p><p><img src="/c/assets/170.BJBdn7pw.png" alt="" loading="lazy"></p><ul><li>测试一下,是否配置成功:</li></ul><p><img src="/c/assets/171.DXtQWYsM.gif" alt="" loading="lazy"></p><h2 id="_8-6-clion-中自动导入头文件" tabindex="-1">8.6 CLion 中自动导入头文件 <a class="header-anchor" href="#_8-6-clion-中自动导入头文件" aria-label="Permalink to &quot;8.6 CLion 中自动导入头文件&quot;"></a></h2><ul><li>在 CLion 中,最为强大的功能就是直接输入函数,然后让 IDE 帮我们自动导入头文件,包括自定义的头文件,相当实用。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① CLion 中的<code>自动导入头文件</code><code>快捷键</code><code>Alt + Enter</code></li><li>② CLion 中的<code>自动提取变量的类型</code><code>快捷键</code><code>Ctrl + Alt + V</code></li></ul></div><p><img src="/c/assets/172.hcERTQkN.gif" alt="" loading="lazy"></p><ul><li>开启自动导入头文件的步骤,如下所示:</li></ul><p><img src="/c/assets/173.CioraEUv.png" alt="" loading="lazy"></p><p><img src="/c/assets/174.kWHWwnc_.png" alt="" loading="lazy"></p><h2 id="_8-7-wsl2-启用-systemd" tabindex="-1">8.7 WSL2 启用 systemd <a class="header-anchor" href="#_8-7-wsl2-启用-systemd" aria-label="Permalink to &quot;8.7 WSL2 启用 systemd&quot;"></a></h2><h3 id="_8-7-1-概述" tabindex="-1">8.7.1 概述 <a class="header-anchor" href="#_8-7-1-概述" aria-label="Permalink to &quot;8.7.1 概述&quot;"></a></h3><ul><li>根据 <a href="https://systemd.io/" target="_blank" rel="noreferrer">systemd.io</a>“systemd 是 Linux 系统的基本构建基块套件。 它提供一个系统和服务管理器,该管理器作为 PID 1 运行并启动系统的其余部分。”</li><li>Systemd 主要是一个 init 系统和服务管理器,它包括按需启动守护程序、装载和自动装载点维护、快照支持以及使用 Linux 控制组进行跟踪等功能。</li><li>大多数主要的 Linux 发行版现在都运行 systemd因此在 WSL2 上启用它可使体验更接近于使用裸机 Linux。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 默认情况下,在 WSL2 中,只有 Ubuntu 才会将 systemd 作为 pid-1 的守护进程</li><li>但是,基于 WSL2 为内核的其余 Linux 发行版本并非将 systemd 作为 pid-1 的守护进程。</li><li> 本次以 AlmaLinux9 作为演示!!!</li></ul></div><ul><li>检查进程树,判断 systemd 是否正在运行:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">ps</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -p</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> comm=</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 如果显示 systemd ,则表示 systemd 正在运行</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/175.DhVZ6aP-.gif" alt="" loading="lazy"></p><h3 id="_8-7-2-操作步骤" tabindex="-1">8.7.2 操作步骤 <a class="header-anchor" href="#_8-7-2-操作步骤" aria-label="Permalink to &quot;8.7.2 操作步骤&quot;"></a></h3><ul><li>① 查询 WSL2 的版本,确保 WSL2 的版本为 <code>0.67.6</code> 或更高版本:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 如果未满足要求,则使用 wsl --update 更新 WSL2 版本</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> https://github.com/microsoft/WSL2-Linux-Kernel.git</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p><img src="/c/assets/162.B1eB55rC.gif" alt="" loading="lazy"></p><ul><li>编译内核代码:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">cd</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> WSL2-Linux-Kernel</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">make</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -j</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">nproc</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">KCONFIG_CONFIG=Microsoft/config-wsl</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/163.VIcU-hkN.gif" alt="" loading="lazy"></p><ul><li>编译 perf 工具:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">cd</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> tools/perf</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">make</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> clean</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &amp;&amp; </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">make</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/164.BM9viRZJ.gif" alt="" loading="lazy"></p><ul><li>复制到 PATH 变量所指向的路径中:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">cp</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> perf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /usr/bin/</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/165.DpMBA1SK.gif" alt="" loading="lazy"></p><h3 id="_8-4-3-整合" tabindex="-1">8.4.3 整合 <a class="header-anchor" href="#_8-4-3-整合" aria-label="Permalink to &quot;8.4.3 整合&quot;"></a></h3><ul><li>CLion 中配置 perf 的路径:</li></ul><p><img src="/c/assets/166.DgXuU6LF.png" alt="" loading="lazy"></p><ul><li>在 CLion 中通过 perf 运行代码:</li></ul><p><img src="/c/assets/167.Dnw73s2h.gif" alt="" loading="lazy"></p><h2 id="_8-5-win-中文乱码问题" tabindex="-1">8.5 Win 中文乱码问题 <a class="header-anchor" href="#_8-5-win-中文乱码问题" aria-label="Permalink to &quot;8.5 Win 中文乱码问题&quot;"></a></h2><ul><li>前文,我们提及到,在 Win 中,如果出现<code>中文乱码</code>问题,就需要去<code>语言和区别</code>设置<code>系统区域</code>的编码为 UTF-8 但是这样可能会造成其它的软件出现中文乱码问题Xshell 等。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 之所以,修改系统的编码为 UTF-8 会出现问题,是因为早期的 Win 系统的中文默认编码是 GBK目前也是Win 并没有强制第三方软件使用 UTF-8 编码) ,而 Xshell 等也使用的这些编码,一旦我们修改为 UTF-8 之后,可能会造成这些第三方软件出现中文乱码问题(第三方软件适配问题,相信将来应该都会切换为 UTF-8 编码),体验较差!!!</li><li>② 在 Linux 或 MacOS 之所以不会出现中文乱码的问题,是因为这些系统默认的编码就是 UTF-8 。</li></ul></div><ul><li>其实,还有一种解决方案,如下所示:</li></ul><p><img src="/c/assets/168.SnFXRSaL.png" alt="" loading="lazy"></p><p><img src="/c/assets/169.DnoEqOjV.png" alt="" loading="lazy"></p><p><img src="/c/assets/170.BJBdn7pw.png" alt="" loading="lazy"></p><ul><li>测试一下,是否配置成功:</li></ul><p><img src="/c/assets/171.DXtQWYsM.gif" alt="" loading="lazy"></p><h2 id="_8-6-clion-中自动导入头文件" tabindex="-1">8.6 CLion 中自动导入头文件 <a class="header-anchor" href="#_8-6-clion-中自动导入头文件" aria-label="Permalink to &quot;8.6 CLion 中自动导入头文件&quot;"></a></h2><ul><li>在 CLion 中,最为强大的功能就是直接输入函数,然后让 IDE 帮我们自动导入头文件,包括自定义的头文件,相当实用。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① CLion 中的<code>自动导入头文件</code><code>快捷键</code><code>Alt + Enter</code></li><li>② CLion 中的<code>自动提取变量的类型</code><code>快捷键</code><code>Ctrl + Alt + V</code></li></ul></div><p><img src="/c/assets/172.hcERTQkN.gif" alt="" loading="lazy"></p><ul><li>开启自动导入头文件的步骤,如下所示:</li></ul><p><img src="/c/assets/173.CioraEUv.png" alt="" loading="lazy"></p><p><img src="/c/assets/174.kWHWwnc_.png" alt="" loading="lazy"></p><h2 id="_8-7-wsl2-启用-systemd" tabindex="-1">8.7 WSL2 启用 systemd <a class="header-anchor" href="#_8-7-wsl2-启用-systemd" aria-label="Permalink to &quot;8.7 WSL2 启用 systemd&quot;"></a></h2><h3 id="_8-7-1-概述" tabindex="-1">8.7.1 概述 <a class="header-anchor" href="#_8-7-1-概述" aria-label="Permalink to &quot;8.7.1 概述&quot;"></a></h3><ul><li>根据 <a href="https://systemd.io/" target="_blank" rel="noreferrer">systemd.io</a>“systemd 是 Linux 系统的基本构建基块套件。 它提供一个系统和服务管理器,该管理器作为 PID 1 运行并启动系统的其余部分。”</li><li>Systemd 主要是一个 init 系统和服务管理器,它包括按需启动守护程序、装载和自动装载点维护、快照支持以及使用 Linux 控制组进行跟踪等功能。</li><li>大多数主要的 Linux 发行版现在都运行 systemd因此在 WSL2 上启用它可使体验更接近于使用裸机 Linux。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 默认情况下,在 WSL2 中,只有 Ubuntu 才会将 systemd 作为 pid-1 的守护进程(微软维护和定制的 Ubuntu 版本,在 GitHub 的 Codespace 中默认的 Linux 环境就是 Ubuntu但是,基于 WSL2 为内核的其余 Linux 发行版本并非将 systemd 作为 pid-1 的守护进程。</li><li> 本次以 AlmaLinux9 作为演示!!!</li></ul></div><ul><li>检查进程树,判断 systemd 是否正在运行:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">ps</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -p</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> comm=</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 如果显示 systemd ,则表示 systemd 正在运行</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/175.DhVZ6aP-.gif" alt="" loading="lazy"></p><h3 id="_8-7-2-操作步骤" tabindex="-1">8.7.2 操作步骤 <a class="header-anchor" href="#_8-7-2-操作步骤" aria-label="Permalink to &quot;8.7.2 操作步骤&quot;"></a></h3><ul><li>① 查询 WSL2 的版本,确保 WSL2 的版本为 <code>0.67.6</code> 或更高版本:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 如果未满足要求,则使用 wsl --update 更新 WSL2 版本</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">wsl</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --version</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 在 win 中的 cmd 或 PowerShell 执行该命令</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p><img src="/c/assets/176.CUl5g8VJ.png" alt="" loading="lazy"></p><ul><li>② 向 <code>/etc/wsl.conf</code> 配置文件中写入以下内容:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">cat</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &lt;&lt;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">EOF</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> |</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> tee</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /etc/wsl.conf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">[boot]</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">systemd=true</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">EOF</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p><img src="/c/assets/177.FJeffiE3.gif" alt="" loading="lazy"></p><ul><li>③ 重启 WSL 实例:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">wsl</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --shutdown</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 在 win 中的 cmd 或 PowerShell 执行该命令</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/178.Bee0LcNX.gif" alt="" loading="lazy"></p><ul><li>④ 查看是否启用成功:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">ps</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -p</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> comm=</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/179.BDqd1eDo.png" alt="" loading="lazy"></p></div></div></main><footer class="VPDocFooter" data-v-39a288b8 data-v-e257564d><!--[--><!--]--><div class="edit-info" data-v-e257564d><!----><div class="last-updated" data-v-e257564d><p class="VPLastUpdated" data-v-e257564d data-v-e98dd255>上次更新: <time datetime="2024-08-26T08:26:35.000Z" data-v-e98dd255></time></p></div></div><nav class="prev-next" aria-labelledby="doc-footer-aria-label" data-v-e257564d><span class="visually-hidden" id="doc-footer-aria-label" data-v-e257564d>Pager</span><div class="pager" data-v-e257564d><a class="VPLink link pager-link prev" href="/c/notes/01_c-basic/00_xdx/" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>上一篇</span><span class="title" data-v-e257564d>编程基础</span><!--]--></a></div><div class="pager" data-v-e257564d><a class="VPLink link pager-link next" href="/c/notes/01_c-basic/02_xdx/" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>下一篇</span><span class="title" data-v-e257564d>变量和进制</span><!--]--></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><footer class="VPFooter has-sidebar" data-v-5d98c3a5 data-v-e315a0ad><div class="container" data-v-e315a0ad><p class="message" data-v-e315a0ad>Released under the MIT License.</p><p class="copyright" data-v-e315a0ad>Copyright © 2024 许大仙</p></div></footer><!--[--><!--]--></div></div>
<script>window.__VP_HASH_MAP__=JSON.parse("{\"index.md\":\"Dga0tMF5\",\"notes_01_c-basic_00_xdx_index.md\":\"BRC7slaL\",\"notes_01_c-basic_01_xdx_index.md\":\"DvCUr2L0\",\"notes_01_c-basic_02_xdx_index.md\":\"CC2Mg9VD\",\"notes_01_c-basic_03_xdx_index.md\":\"CcATnhKW\",\"notes_01_c-basic_04_xdx_index.md\":\"DABEMZSO\",\"notes_01_c-basic_05_xdx_index.md\":\"CGbN5wss\",\"notes_01_c-basic_06_xdx_index.md\":\"CIGNaKYV\",\"notes_04_linux_01_xdx_index.md\":\"C9IatKsj\",\"notes_about_index.md\":\"DLuQgC_8\",\"notes_index.md\":\"CeV-uJ5V\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"zh-CN\",\"dir\":\"ltr\",\"title\":\"许大仙\",\"titleTemplate\":\"Hi终于等到你\",\"description\":\"许大仙前端、Java、大数据、云原生\",\"base\":\"/c/\",\"head\":[],\"router\":{\"prefetchLinks\":true},\"appearance\":true,\"themeConfig\":{\"lastUpdatedText\":\"上次更新\",\"returnToTopLabel\":\"返回顶部\",\"search\":{\"provider\":\"local\"},\"logo\":\"/logo.svg\",\"nav\":[{\"text\":\"首页\",\"link\":\"https://aexiar.github.io/\"},{\"text\":\"计组6件套\",\"link\":\"https://aexiar.github.io/coa6/notes/\"},{\"text\":\"编程语言\",\"items\":[{\"text\":\"c/c++\",\"link\":\"/notes/\"},{\"text\":\"前端\",\"link\":\"https://aexiar.github.io/web-design/notes/\"},{\"text\":\"Java\",\"link\":\"https://aexiar.github.io/java/notes/\"},{\"text\":\"大数据\",\"link\":\"https://aexiar.github.io/big-data/notes/\"},{\"text\":\"云原生\",\"link\":\"https://aexiar.github.io/linux/notes/\"},{\"text\":\"Go\",\"link\":\"https://aexiar.github.io/go/notes/\"},{\"text\":\"Python\",\"link\":\"https://aexiar.github.io/python/notes/\"}]},{\"text\":\"数据库\",\"link\":\"https://aexiar.github.io/db/notes/\"},{\"text\":\"开源软件\",\"link\":\"https://aexiar.github.io/open-software/notes/\"},{\"text\":\"关于我\",\"link\":\"/notes/about/\"}],\"sidebar\":{\"/notes/\":[{\"text\":\"C 语言基础\",\"collapsed\":true,\"items\":[{\"text\":\"编程基础\",\"link\":\"/notes/01_c-basic/00_xdx/\"},{\"text\":\"C 语言入门\",\"link\":\"/notes/01_c-basic/01_xdx/\"},{\"text\":\"变量和进制\",\"link\":\"/notes/01_c-basic/02_xdx/\"},{\"text\":\"数据类型和运算符\",\"link\":\"/notes/01_c-basic/03_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/01_c-basic/04_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/01_c-basic/05_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/01_c-basic/06_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/01_c-basic/07_xdx/\"},{\"text\":\"预处理器\",\"link\":\"/notes/01_c-basic/08_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/01_c-basic/09_xdx/\"},{\"text\":\"内存管理\",\"link\":\"/notes/01_c-basic/10_xdx/\"},{\"text\":\"文件操作\",\"link\":\"/notes/01_c-basic/11_xdx/\"},{\"text\":\"调试工具和调试技巧gdb和make\",\"link\":\"/notes/02_c-basic/13_xdx/\"},{\"text\":\"常用库函数\",\"link\":\"/notes/01_c-basic/13_xdx/\"}]},{\"text\":\"C 语言高级\",\"collapsed\":true,\"items\":[{\"text\":\"变量和内存分布\",\"link\":\"/notes/02_c-advance/01_xdx/\"},{\"text\":\"指针强化\",\"link\":\"/notes/02_c-advance/02_xdx/\"},{\"text\":\"结构体和文件的高级用法\",\"link\":\"/notes/02_c-advance/03_xdx/\"},{\"text\":\"链表和回调函数\",\"link\":\"/notes/02_c-advance/04_xdx/\"},{\"text\":\"编译过程和面向接口\",\"link\":\"/notes/02_c-advance/05_xdx/\"}]},{\"text\":\"项目构建工具\",\"collapsed\":true,\"items\":[{\"text\":\"meson\",\"collapsed\":true,\"items\":[{\"text\":\"meson 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Cmake\",\"collapsed\":true,\"items\":[{\"text\":\"Cmake 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Conan \",\"link\":\"/notes/03_build/01_${commonDirectoryName}/\"},{\"text\":\"Gradle\",\"collapsed\":true,\"items\":[{\"text\":\"Gradle 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]}]},{\"text\":\"Linux\",\"collapsed\":true,\"items\":[{\"text\":\"Linux 初识和安装\",\"link\":\"/notes/04_linux/01_xdx/\"}]},{\"text\":\"C++ 基础\",\"collapsed\":true,\"items\":[{\"text\":\"C++ 入门\",\"link\":\"/notes/05_cpp/01_xdx/\"},{\"text\":\"变量、数据类型、运算符\",\"link\":\"/notes/05_cpp/02_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/05_cpp/03_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/05_cpp/04_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/05_cpp/05_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/05_cpp/06_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/05_cpp/07_xdx/\"},{\"text\":\"类和对象\",\"link\":\"/notes/05_cpp/08_xdx/\"},{\"text\":\"C++ 引用\",\"link\":\"/notes/05_cpp/09_xdx/\"},{\"text\":\"继承和派生\",\"link\":\"/notes/05_cpp/10_xdx/\"},{\"text\":\"C++ 多态和虚函数\",\"link\":\"/notes/05_cpp/11_xdx/\"},{\"text\":\"运算符重载\",\"link\":\"/notes/05_cpp/12_xdx/\"},{\"text\":\"模板\",\"link\":\"/notes/05_cpp/13_xdx/\"},{\"text\":\"C++ 异常\",\"link\":\"/notes/05_cpp/14_xdx/\"},{\"text\":\"面向对象进阶\",\"link\":\"/notes/05_cpp/15_xdx/\"},{\"text\":\"文件操作和 IO 流\",\"link\":\"/notes/05_cpp/16_xdx/\"},{\"text\":\"STL标准模板库\",\"link\":\"/notes/05_cpp/17_xdx/\"}]},{\"text\":\"C++ 高级\",\"collapsed\":true,\"items\":[]},{\"text\":\"QT 桌面开发\",\"collapsed\":true,\"items\":[]},{\"text\":\"Linux 高并发服务器开发\",\"collapsed\":true,\"items\":[]}]},\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/Aurorxa\"}],\"docFooter\":{\"prev\":\"上一篇\",\"next\":\"下一篇\"},\"darkModeSwitchLabel\":\"深浅模式\",\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2024 许大仙\"},\"outline\":{\"level\":[1,6],\"label\":\"目录\"},\"outlineTitle\":\"当前页大纲\"},\"locales\":{},\"scrollOffset\":134,\"cleanUrls\":false}");</script>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">EOF</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p><img src="/c/assets/177.FJeffiE3.gif" alt="" loading="lazy"></p><ul><li>③ 重启 WSL 实例:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">wsl</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --shutdown</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 在 win 中的 cmd 或 PowerShell 执行该命令</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/178.Bee0LcNX.gif" alt="" loading="lazy"></p><ul><li>④ 查看是否启用成功:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">ps</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -p</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> comm=</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/179.BDqd1eDo.png" alt="" loading="lazy"></p></div></div></main><footer class="VPDocFooter" data-v-39a288b8 data-v-e257564d><!--[--><!--]--><div class="edit-info" data-v-e257564d><!----><div class="last-updated" data-v-e257564d><p class="VPLastUpdated" data-v-e257564d data-v-e98dd255>上次更新: <time datetime="2024-08-27T03:11:14.000Z" data-v-e98dd255></time></p></div></div><nav class="prev-next" aria-labelledby="doc-footer-aria-label" data-v-e257564d><span class="visually-hidden" id="doc-footer-aria-label" data-v-e257564d>Pager</span><div class="pager" data-v-e257564d><a class="VPLink link pager-link prev" href="/c/notes/01_c-basic/00_xdx/" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>上一篇</span><span class="title" data-v-e257564d>编程基础</span><!--]--></a></div><div class="pager" data-v-e257564d><a class="VPLink link pager-link next" href="/c/notes/01_c-basic/02_xdx/" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>下一篇</span><span class="title" data-v-e257564d>变量和进制</span><!--]--></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><footer class="VPFooter has-sidebar" data-v-5d98c3a5 data-v-e315a0ad><div class="container" data-v-e315a0ad><p class="message" data-v-e315a0ad>Released under the MIT License.</p><p class="copyright" data-v-e315a0ad>Copyright © 2024 许大仙</p></div></footer><!--[--><!--]--></div></div>
<script>window.__VP_HASH_MAP__=JSON.parse("{\"index.md\":\"Dga0tMF5\",\"notes_01_c-basic_00_xdx_index.md\":\"BRC7slaL\",\"notes_01_c-basic_01_xdx_index.md\":\"Fg4OXydV\",\"notes_01_c-basic_02_xdx_index.md\":\"CC2Mg9VD\",\"notes_01_c-basic_03_xdx_index.md\":\"Cw3Z19MO\",\"notes_01_c-basic_04_xdx_index.md\":\"ySxH8sG-\",\"notes_01_c-basic_05_xdx_index.md\":\"DUbOwEts\",\"notes_01_c-basic_06_xdx_index.md\":\"CV_r2WNu\",\"notes_01_c-basic_07_xdx_index.md\":\"CE9q5cmu\",\"notes_04_linux_01_xdx_index.md\":\"C9IatKsj\",\"notes_about_index.md\":\"DLuQgC_8\",\"notes_index.md\":\"CeV-uJ5V\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"zh-CN\",\"dir\":\"ltr\",\"title\":\"许大仙\",\"titleTemplate\":\"Hi终于等到你\",\"description\":\"许大仙前端、Java、大数据、云原生\",\"base\":\"/c/\",\"head\":[],\"router\":{\"prefetchLinks\":true},\"appearance\":true,\"themeConfig\":{\"lastUpdatedText\":\"上次更新\",\"returnToTopLabel\":\"返回顶部\",\"search\":{\"provider\":\"local\"},\"logo\":\"/logo.svg\",\"nav\":[{\"text\":\"首页\",\"link\":\"https://aexiar.github.io/\"},{\"text\":\"计组6件套\",\"link\":\"https://aexiar.github.io/coa6/notes/\"},{\"text\":\"编程语言\",\"items\":[{\"text\":\"c/c++\",\"link\":\"/notes/\"},{\"text\":\"前端\",\"link\":\"https://aexiar.github.io/web-design/notes/\"},{\"text\":\"Java\",\"link\":\"https://aexiar.github.io/java/notes/\"},{\"text\":\"大数据\",\"link\":\"https://aexiar.github.io/big-data/notes/\"},{\"text\":\"云原生\",\"link\":\"https://aexiar.github.io/linux/notes/\"},{\"text\":\"Go\",\"link\":\"https://aexiar.github.io/go/notes/\"},{\"text\":\"Python\",\"link\":\"https://aexiar.github.io/python/notes/\"}]},{\"text\":\"数据库\",\"link\":\"https://aexiar.github.io/db/notes/\"},{\"text\":\"开源软件\",\"link\":\"https://aexiar.github.io/open-software/notes/\"},{\"text\":\"关于我\",\"link\":\"/notes/about/\"}],\"sidebar\":{\"/notes/\":[{\"text\":\"C 语言基础\",\"collapsed\":true,\"items\":[{\"text\":\"编程基础\",\"link\":\"/notes/01_c-basic/00_xdx/\"},{\"text\":\"C 语言入门\",\"link\":\"/notes/01_c-basic/01_xdx/\"},{\"text\":\"变量和进制\",\"link\":\"/notes/01_c-basic/02_xdx/\"},{\"text\":\"数据类型和运算符\",\"link\":\"/notes/01_c-basic/03_xdx/\"},{\"text\":\"大话小数\",\"link\":\"/notes/01_c-basic/04_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/01_c-basic/05_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/01_c-basic/06_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/01_c-basic/07_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/01_c-basic/08_xdx/\"},{\"text\":\"预处理器\",\"link\":\"/notes/01_c-basic/09_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/01_c-basic/10_xdx/\"},{\"text\":\"内存管理\",\"link\":\"/notes/01_c-basic/11_xdx/\"},{\"text\":\"文件操作\",\"link\":\"/notes/01_c-basic/12_xdx/\"},{\"text\":\"调试工具和调试技巧gdb和make\",\"link\":\"/notes/02_c-basic/13_xdx/\"},{\"text\":\"常用库函数\",\"link\":\"/notes/01_c-basic/14_xdx/\"}]},{\"text\":\"C 语言高级\",\"collapsed\":true,\"items\":[{\"text\":\"变量和内存分布\",\"link\":\"/notes/02_c-advance/01_xdx/\"},{\"text\":\"指针强化\",\"link\":\"/notes/02_c-advance/02_xdx/\"},{\"text\":\"结构体和文件的高级用法\",\"link\":\"/notes/02_c-advance/03_xdx/\"},{\"text\":\"链表和回调函数\",\"link\":\"/notes/02_c-advance/04_xdx/\"},{\"text\":\"编译过程和面向接口\",\"link\":\"/notes/02_c-advance/05_xdx/\"}]},{\"text\":\"项目构建工具\",\"collapsed\":true,\"items\":[{\"text\":\"meson\",\"collapsed\":true,\"items\":[{\"text\":\"meson 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Cmake\",\"collapsed\":true,\"items\":[{\"text\":\"Cmake 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Conan \",\"link\":\"/notes/03_build/01_${commonDirectoryName}/\"},{\"text\":\"Gradle\",\"collapsed\":true,\"items\":[{\"text\":\"Gradle 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]}]},{\"text\":\"Linux\",\"collapsed\":true,\"items\":[{\"text\":\"Linux 初识和安装\",\"link\":\"/notes/04_linux/01_xdx/\"}]},{\"text\":\"C++ 基础\",\"collapsed\":true,\"items\":[{\"text\":\"C++ 入门\",\"link\":\"/notes/05_cpp/01_xdx/\"},{\"text\":\"变量、数据类型、运算符\",\"link\":\"/notes/05_cpp/02_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/05_cpp/03_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/05_cpp/04_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/05_cpp/05_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/05_cpp/06_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/05_cpp/07_xdx/\"},{\"text\":\"类和对象\",\"link\":\"/notes/05_cpp/08_xdx/\"},{\"text\":\"C++ 引用\",\"link\":\"/notes/05_cpp/09_xdx/\"},{\"text\":\"继承和派生\",\"link\":\"/notes/05_cpp/10_xdx/\"},{\"text\":\"C++ 多态和虚函数\",\"link\":\"/notes/05_cpp/11_xdx/\"},{\"text\":\"运算符重载\",\"link\":\"/notes/05_cpp/12_xdx/\"},{\"text\":\"模板\",\"link\":\"/notes/05_cpp/13_xdx/\"},{\"text\":\"C++ 异常\",\"link\":\"/notes/05_cpp/14_xdx/\"},{\"text\":\"面向对象进阶\",\"link\":\"/notes/05_cpp/15_xdx/\"},{\"text\":\"文件操作和 IO 流\",\"link\":\"/notes/05_cpp/16_xdx/\"},{\"text\":\"STL标准模板库\",\"link\":\"/notes/05_cpp/17_xdx/\"}]},{\"text\":\"C++ 高级\",\"collapsed\":true,\"items\":[]},{\"text\":\"QT 桌面开发\",\"collapsed\":true,\"items\":[]},{\"text\":\"Linux 高并发服务器开发\",\"collapsed\":true,\"items\":[]}]},\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/Aurorxa\"}],\"docFooter\":{\"prev\":\"上一篇\",\"next\":\"下一篇\"},\"darkModeSwitchLabel\":\"深浅模式\",\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2024 许大仙\"},\"outline\":{\"level\":[1,6],\"label\":\"目录\"},\"outlineTitle\":\"当前页大纲\"},\"locales\":{},\"scrollOffset\":134,\"cleanUrls\":false}");</script>
</body>
</html>

View File

@ -8,9 +8,9 @@
<meta name="generator" content="VitePress v1.3.3">
<link rel="preload stylesheet" href="/c/assets/style.zDJ0OJGU.css" as="style">
<script type="module" src="/c/assets/app.Ca2FOFw4.js"></script>
<script type="module" src="/c/assets/app.1a4d5P-6.js"></script>
<link rel="preload" href="/c/assets/inter-roman-latin.Di8DUHzh.woff2" as="font" type="font/woff2" crossorigin="">
<link rel="modulepreload" href="/c/assets/chunks/theme.C6fZfLtk.js">
<link rel="modulepreload" href="/c/assets/chunks/theme.Ddh-lpYV.js">
<link rel="modulepreload" href="/c/assets/chunks/framework.hMCIpNYY.js">
<link rel="modulepreload" href="/c/assets/notes_01_c-basic_02_xdx_index.md.CC2Mg9VD.lean.js">
<link rel="shortcut icon" href="/c//logo.svg">
@ -22,7 +22,7 @@
<script id="check-mac-os">document.documentElement.classList.toggle("mac",/Mac|iPhone|iPod|iPad/i.test(navigator.platform));</script>
</head>
<body>
<div id="app"><div class="Layout" data-v-5d98c3a5><!--[--><!--]--><!--[--><span tabindex="-1" data-v-0f60ec36></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-0f60ec36> Skip to content </a><!--]--><!----><header class="VPNav" data-v-5d98c3a5 data-v-ae24b3ad><div class="VPNavBar has-sidebar top" data-v-ae24b3ad data-v-6aa21345><div class="wrapper" data-v-6aa21345><div class="container" data-v-6aa21345><div class="title" data-v-6aa21345><div class="VPNavBarTitle has-sidebar" data-v-6aa21345 data-v-ab179fa1><a class="title" href="/c/" data-v-ab179fa1><!--[--><!--]--><!--[--><img class="VPImage logo" src="/c/logo.svg" alt data-v-8426fc1a><!--]--><span data-v-ab179fa1>许大仙</span><!--[--><!--]--></a></div></div><div class="content" data-v-6aa21345><div class="content-body" data-v-6aa21345><!--[--><!--]--><div class="VPNavBarSearch search" data-v-6aa21345><!--[--><!----><div id="local-search"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><span class="vp-icon DocSearch-Search-Icon"></span><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key">K</kbd></span></button></div><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-6aa21345 data-v-dc692963><span id="main-nav-aria-label" class="visually-hidden" data-v-dc692963> Main Navigation </span><!--[--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>首页</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/coa6/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>计组6件套</span><!--]--></a><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-dc692963 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-b6c34ac9><span class="text" data-v-b6c34ac9><!----><span data-v-b6c34ac9>编程语言</span><span class="vpi-chevron-down text-icon" data-v-b6c34ac9></span></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><div class="items" data-v-b98bc113><!--[--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link" href="/c/notes/" data-v-43f1e123><!--[-->c/c++<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/web-design/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->前端<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/java/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Java<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/big-data/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->大数据<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/linux/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->云原生<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/go/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Go<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/python/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Python<!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/db/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>数据库</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/open-software/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>开源软件</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/c/notes/about/" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>关于我</span><!--]--></a><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-6aa21345 data-v-6c893767><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-6c893767 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-6aa21345 data-v-0394ad82 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-6aa21345 data-v-bb2aa2f0 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-b6c34ac9><span class="vpi-more-horizontal icon" data-v-b6c34ac9></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><!----><!--[--><!--[--><!----><div class="group" data-v-bb2aa2f0><div class="item appearance" data-v-bb2aa2f0><p class="label" data-v-bb2aa2f0>深浅模式</p><div class="appearance-action" data-v-bb2aa2f0><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-bb2aa2f0 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div></div></div><div class="group" data-v-bb2aa2f0><div class="item social-links" data-v-bb2aa2f0><div class="VPSocialLinks social-links-list" data-v-bb2aa2f0 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div></div></div><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-6aa21345 data-v-e5dd9c1c><span class="container" data-v-e5dd9c1c><span class="top" data-v-e5dd9c1c></span><span class="middle" data-v-e5dd9c1c></span><span class="bottom" data-v-e5dd9c1c></span></span></button></div></div></div></div><div class="divider" data-v-6aa21345><div class="divider-line" data-v-6aa21345></div></div></div><!----></header><div class="VPLocalNav has-sidebar empty" data-v-5d98c3a5 data-v-a6f0e41e><div class="container" data-v-a6f0e41e><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-a6f0e41e><span class="vpi-align-left menu-icon" data-v-a6f0e41e></span><span class="menu-text" data-v-a6f0e41e>Menu</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-a6f0e41e data-v-17a5e62e><button data-v-17a5e62e>返回顶部</button><!----></div></div></div><aside class="VPSidebar" data-v-5d98c3a5 data-v-319d5ca6><div class="curtain" data-v-319d5ca6></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-319d5ca6><span class="visually-hidden" id="sidebar-aria-label" data-v-319d5ca6> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible has-active" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/00_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编程基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C 语言入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和进制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数据类型和运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>预处理器</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>内存管理</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-basic/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>调试工具和调试技巧gdb和make</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>常用库函数</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言高级</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和内存分布</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针强化</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>结构体和文件的高级用法</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>链表和回调函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编译过程和面向接口</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>项目构建工具</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>meson</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>meson 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Cmake</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Cmake 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_${commonDirectoryName}/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Conan </p><!--]--></a><!----></div><!----></div><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Gradle</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Gradle 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>Linux</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/04_linux/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Linux 初识和安装</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C++ 基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量、数据类型、运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>类和对象</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 引用</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>继承和派生</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 多态和虚函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/12_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>运算符重载</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>模板</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/14_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 异常</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/15_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>面向对象进阶</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/16_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作和 IO 流</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/17_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>STL标准模板库</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>C++ 高级</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>QT 桌面开发</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>Linux 高并发服务器开发</p><!----></div><!----></div></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-5d98c3a5 data-v-1428d186><div class="VPDoc has-sidebar has-aside" data-v-1428d186 data-v-39a288b8><!--[--><!--]--><div class="container" data-v-39a288b8><div class="aside" data-v-39a288b8><div class="aside-curtain" data-v-39a288b8></div><div class="aside-container" data-v-39a288b8><div class="aside-content" data-v-39a288b8><div class="VPDocAside" data-v-39a288b8 data-v-3f215769><!--[--><!--]--><!--[--><!--]--><nav aria-labelledby="doc-outline-aria-label" class="VPDocAsideOutline" data-v-3f215769 data-v-a5bbad30><div class="content" data-v-a5bbad30><div class="outline-marker" data-v-a5bbad30></div><div aria-level="2" class="outline-title" id="doc-outline-aria-label" role="heading" data-v-a5bbad30>目录</div><ul class="VPDocOutlineItem root" data-v-a5bbad30 data-v-b933a997><!--[--><!--]--></ul></div></nav><!--[--><!--]--><div class="spacer" data-v-3f215769></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-39a288b8><div class="content-container" data-v-39a288b8><!--[--><!--]--><main class="main" data-v-39a288b8><div style="position:relative;" class="vp-doc _c_notes_01_c-basic_02_xdx_" data-v-39a288b8><div><h1 id="第一章-变量-⭐" tabindex="-1">第一章:变量(⭐) <a class="header-anchor" href="#第一章-变量-⭐" aria-label="Permalink to &quot;第一章:变量(⭐)&quot;"></a></h1><h2 id="_1-1-程序中变化的数据" tabindex="-1">1.1 程序中变化的数据 <a class="header-anchor" href="#_1-1-程序中变化的数据" aria-label="Permalink to &quot;1.1 程序中变化的数据&quot;"></a></h2><ul><li>在生活中,我们使用最多的不是固定的数据,而是会变化的数据: <ul><li>① 购物车商品的<code>数量</code><code>价格</code>等。</li><li>② 一首歌<code>播放的时间</code><code>进度条</code><code>歌词的展示</code>等。</li><li>③ 微信聊天中<code>消息条数</code><code>时间</code><code>语音的长度</code><code>头像</code><code>名称</code>等。</li><li>④ 游戏中技能的<code>冷却时间</code><code>血量</code><code>蓝量</code><code>buff 时间</code><code>金币的数量</code>等。</li><li>……</li></ul></li></ul><ul><li>下图是一个<code>购物车</code><code>变化</code><code>数据</code>,即:</li></ul><p><img src="/c/assets/1.CXNJqOOc.png" alt="" loading="lazy"></p><ul><li>那么,在实际开发中,我们就会使用<code>变量</code><code>保存</code><code>操作</code>这些<code>变化</code><code>数据</code></li></ul><h2 id="_1-2-变量" tabindex="-1">1.2 变量 <a class="header-anchor" href="#_1-2-变量" aria-label="Permalink to &quot;1.2 变量&quot;"></a></h2><ul><li>变量的定义:变量是程序中不可或缺的组成单位,最基本的存储单元。其实,变量就是一个存储数据的临时空间,可以向其中存储不同类型的数据,如:整数、小数、字符、字符串等,并且变量中的数据在程序运行的时候可以动态改变。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li><code>变量</code>:用来<code>存储数据</code><code>容器</code></li><li><code>数据</code>:可以是一个用来计算的<code>数字</code>,如:上文购物车中的<code>价格</code>等;也可以是一句话中的<code>关键词</code><code>其它任意格式的数据</code></li><li>变量的<code>特别</code>之处就在于<code>它存放的数据是可以改变</code>的。</li></ul></div><ul><li>我们可以将<code>变量</code>想象为一个<code>容器</code>,盒子中<code>装的</code>就是我们想要的<code>数据</code>,并且我们需要<code></code>盒子<code></code>一个<code>特别的名称</code>;通过这个<code>特别的名称</code>,我们可以<code></code>盒子<code>添加数据</code><code>移除数据</code>,这个<code>特别的名称</code>就是<code>变量名</code></li></ul><p><img src="/c/assets/2.E0LS08Y5.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li><code>变量</code>是内存中的一个<code>存储区域</code>,该区域的数据可以在<code>同一类型</code>范围内<code>不断变化</code></li><li>② 通过<code>变量名</code>,可以<code>操作</code>这块内存区域,向其中<code>存储数据</code><code>获取数据</code>以及<code>移除数据</code></li><li>③ 变量的构成包含三个要素:<code>数据类型</code><code>变量名</code><code>需要存储的数据</code></li><li>④ 在生活中,我们会经常说:这件衣服的价格是 <code>100整型</code> 元,这双鞋子的价格是 <code>250.5(小数,浮点类型)</code> 元,<code>今天天气真好(字符串类型)</code>之类的话;在计算机科学中,这些都是数据,并且它们是有类型,即:数据类型。(数据类型用于定义变量所能存储的数据的种类以及可以对这些数据进行的操作的一种分类,每种数据类型都有特定的属性和用途,它们决定了变量在内存中如何表示和存储,以及变量可以执行哪些操作)</li></ul></div><h2 id="_1-3-变量的声明和使用" tabindex="-1">1.3 变量的声明和使用 <a class="header-anchor" href="#_1-3-变量的声明和使用" aria-label="Permalink to &quot;1.3 变量的声明和使用&quot;"></a></h2><ul><li>① 变量必须先声明,后使用。</li><li>② 可以先声明变量再赋值,也可以在声明变量的同时进行赋值。</li><li>③ 变量的值可以在同一类型范围内不断变化。</li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li>① 在实际开发中,我们通常都会在声明变量的同时,给其赋值,这被称为初始化。</li><li>② 如果不在声明变量的同时,进行初始化,默认情况下,系统会赋予的随机值,我们也称为垃圾值。</li></ul></div><ul><li>示例:先声明,再使用</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<div id="app"><div class="Layout" data-v-5d98c3a5><!--[--><!--]--><!--[--><span tabindex="-1" data-v-0f60ec36></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-0f60ec36> Skip to content </a><!--]--><!----><header class="VPNav" data-v-5d98c3a5 data-v-ae24b3ad><div class="VPNavBar has-sidebar top" data-v-ae24b3ad data-v-6aa21345><div class="wrapper" data-v-6aa21345><div class="container" data-v-6aa21345><div class="title" data-v-6aa21345><div class="VPNavBarTitle has-sidebar" data-v-6aa21345 data-v-ab179fa1><a class="title" href="/c/" data-v-ab179fa1><!--[--><!--]--><!--[--><img class="VPImage logo" src="/c/logo.svg" alt data-v-8426fc1a><!--]--><span data-v-ab179fa1>许大仙</span><!--[--><!--]--></a></div></div><div class="content" data-v-6aa21345><div class="content-body" data-v-6aa21345><!--[--><!--]--><div class="VPNavBarSearch search" data-v-6aa21345><!--[--><!----><div id="local-search"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><span class="vp-icon DocSearch-Search-Icon"></span><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key">K</kbd></span></button></div><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-6aa21345 data-v-dc692963><span id="main-nav-aria-label" class="visually-hidden" data-v-dc692963> Main Navigation </span><!--[--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>首页</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/coa6/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>计组6件套</span><!--]--></a><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-dc692963 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-b6c34ac9><span class="text" data-v-b6c34ac9><!----><span data-v-b6c34ac9>编程语言</span><span class="vpi-chevron-down text-icon" data-v-b6c34ac9></span></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><div class="items" data-v-b98bc113><!--[--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link" href="/c/notes/" data-v-43f1e123><!--[-->c/c++<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/web-design/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->前端<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/java/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Java<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/big-data/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->大数据<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/linux/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->云原生<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/go/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Go<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/python/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Python<!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/db/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>数据库</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/open-software/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>开源软件</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/c/notes/about/" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>关于我</span><!--]--></a><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-6aa21345 data-v-6c893767><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-6c893767 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-6aa21345 data-v-0394ad82 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-6aa21345 data-v-bb2aa2f0 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-b6c34ac9><span class="vpi-more-horizontal icon" data-v-b6c34ac9></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><!----><!--[--><!--[--><!----><div class="group" data-v-bb2aa2f0><div class="item appearance" data-v-bb2aa2f0><p class="label" data-v-bb2aa2f0>深浅模式</p><div class="appearance-action" data-v-bb2aa2f0><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-bb2aa2f0 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div></div></div><div class="group" data-v-bb2aa2f0><div class="item social-links" data-v-bb2aa2f0><div class="VPSocialLinks social-links-list" data-v-bb2aa2f0 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div></div></div><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-6aa21345 data-v-e5dd9c1c><span class="container" data-v-e5dd9c1c><span class="top" data-v-e5dd9c1c></span><span class="middle" data-v-e5dd9c1c></span><span class="bottom" data-v-e5dd9c1c></span></span></button></div></div></div></div><div class="divider" data-v-6aa21345><div class="divider-line" data-v-6aa21345></div></div></div><!----></header><div class="VPLocalNav has-sidebar empty" data-v-5d98c3a5 data-v-a6f0e41e><div class="container" data-v-a6f0e41e><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-a6f0e41e><span class="vpi-align-left menu-icon" data-v-a6f0e41e></span><span class="menu-text" data-v-a6f0e41e>Menu</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-a6f0e41e data-v-17a5e62e><button data-v-17a5e62e>返回顶部</button><!----></div></div></div><aside class="VPSidebar" data-v-5d98c3a5 data-v-319d5ca6><div class="curtain" data-v-319d5ca6></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-319d5ca6><span class="visually-hidden" id="sidebar-aria-label" data-v-319d5ca6> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible has-active" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/00_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编程基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C 语言入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和进制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数据类型和运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>大话小数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>预处理器</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>内存管理</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/12_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-basic/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>调试工具和调试技巧gdb和make</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/14_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>常用库函数</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言高级</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和内存分布</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针强化</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>结构体和文件的高级用法</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>链表和回调函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编译过程和面向接口</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>项目构建工具</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>meson</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>meson 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Cmake</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Cmake 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_${commonDirectoryName}/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Conan </p><!--]--></a><!----></div><!----></div><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Gradle</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Gradle 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>Linux</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/04_linux/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Linux 初识和安装</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C++ 基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量、数据类型、运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>类和对象</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 引用</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>继承和派生</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 多态和虚函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/12_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>运算符重载</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>模板</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/14_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 异常</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/15_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>面向对象进阶</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/16_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作和 IO 流</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/17_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>STL标准模板库</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>C++ 高级</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>QT 桌面开发</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>Linux 高并发服务器开发</p><!----></div><!----></div></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-5d98c3a5 data-v-1428d186><div class="VPDoc has-sidebar has-aside" data-v-1428d186 data-v-39a288b8><!--[--><!--]--><div class="container" data-v-39a288b8><div class="aside" data-v-39a288b8><div class="aside-curtain" data-v-39a288b8></div><div class="aside-container" data-v-39a288b8><div class="aside-content" data-v-39a288b8><div class="VPDocAside" data-v-39a288b8 data-v-3f215769><!--[--><!--]--><!--[--><!--]--><nav aria-labelledby="doc-outline-aria-label" class="VPDocAsideOutline" data-v-3f215769 data-v-a5bbad30><div class="content" data-v-a5bbad30><div class="outline-marker" data-v-a5bbad30></div><div aria-level="2" class="outline-title" id="doc-outline-aria-label" role="heading" data-v-a5bbad30>目录</div><ul class="VPDocOutlineItem root" data-v-a5bbad30 data-v-b933a997><!--[--><!--]--></ul></div></nav><!--[--><!--]--><div class="spacer" data-v-3f215769></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-39a288b8><div class="content-container" data-v-39a288b8><!--[--><!--]--><main class="main" data-v-39a288b8><div style="position:relative;" class="vp-doc _c_notes_01_c-basic_02_xdx_" data-v-39a288b8><div><h1 id="第一章-变量-⭐" tabindex="-1">第一章:变量(⭐) <a class="header-anchor" href="#第一章-变量-⭐" aria-label="Permalink to &quot;第一章:变量(⭐)&quot;"></a></h1><h2 id="_1-1-程序中变化的数据" tabindex="-1">1.1 程序中变化的数据 <a class="header-anchor" href="#_1-1-程序中变化的数据" aria-label="Permalink to &quot;1.1 程序中变化的数据&quot;"></a></h2><ul><li>在生活中,我们使用最多的不是固定的数据,而是会变化的数据: <ul><li>① 购物车商品的<code>数量</code><code>价格</code>等。</li><li>② 一首歌<code>播放的时间</code><code>进度条</code><code>歌词的展示</code>等。</li><li>③ 微信聊天中<code>消息条数</code><code>时间</code><code>语音的长度</code><code>头像</code><code>名称</code>等。</li><li>④ 游戏中技能的<code>冷却时间</code><code>血量</code><code>蓝量</code><code>buff 时间</code><code>金币的数量</code>等。</li><li>……</li></ul></li></ul><ul><li>下图是一个<code>购物车</code><code>变化</code><code>数据</code>,即:</li></ul><p><img src="/c/assets/1.CXNJqOOc.png" alt="" loading="lazy"></p><ul><li>那么,在实际开发中,我们就会使用<code>变量</code><code>保存</code><code>操作</code>这些<code>变化</code><code>数据</code></li></ul><h2 id="_1-2-变量" tabindex="-1">1.2 变量 <a class="header-anchor" href="#_1-2-变量" aria-label="Permalink to &quot;1.2 变量&quot;"></a></h2><ul><li>变量的定义:变量是程序中不可或缺的组成单位,最基本的存储单元。其实,变量就是一个存储数据的临时空间,可以向其中存储不同类型的数据,如:整数、小数、字符、字符串等,并且变量中的数据在程序运行的时候可以动态改变。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li><code>变量</code>:用来<code>存储数据</code><code>容器</code></li><li><code>数据</code>:可以是一个用来计算的<code>数字</code>,如:上文购物车中的<code>价格</code>等;也可以是一句话中的<code>关键词</code><code>其它任意格式的数据</code></li><li>变量的<code>特别</code>之处就在于<code>它存放的数据是可以改变</code>的。</li></ul></div><ul><li>我们可以将<code>变量</code>想象为一个<code>容器</code>,盒子中<code>装的</code>就是我们想要的<code>数据</code>,并且我们需要<code></code>盒子<code></code>一个<code>特别的名称</code>;通过这个<code>特别的名称</code>,我们可以<code></code>盒子<code>添加数据</code><code>移除数据</code>,这个<code>特别的名称</code>就是<code>变量名</code></li></ul><p><img src="/c/assets/2.E0LS08Y5.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li><code>变量</code>是内存中的一个<code>存储区域</code>,该区域的数据可以在<code>同一类型</code>范围内<code>不断变化</code></li><li>② 通过<code>变量名</code>,可以<code>操作</code>这块内存区域,向其中<code>存储数据</code><code>获取数据</code>以及<code>移除数据</code></li><li>③ 变量的构成包含三个要素:<code>数据类型</code><code>变量名</code><code>需要存储的数据</code></li><li>④ 在生活中,我们会经常说:这件衣服的价格是 <code>100整型</code> 元,这双鞋子的价格是 <code>250.5(小数,浮点类型)</code> 元,<code>今天天气真好(字符串类型)</code>之类的话;在计算机科学中,这些都是数据,并且它们是有类型,即:数据类型。(数据类型用于定义变量所能存储的数据的种类以及可以对这些数据进行的操作的一种分类,每种数据类型都有特定的属性和用途,它们决定了变量在内存中如何表示和存储,以及变量可以执行哪些操作)</li></ul></div><h2 id="_1-3-变量的声明和使用" tabindex="-1">1.3 变量的声明和使用 <a class="header-anchor" href="#_1-3-变量的声明和使用" aria-label="Permalink to &quot;1.3 变量的声明和使用&quot;"></a></h2><ul><li>① 变量必须先声明,后使用。</li><li>② 可以先声明变量再赋值,也可以在声明变量的同时进行赋值。</li><li>③ 变量的值可以在同一类型范围内不断变化。</li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li>① 在实际开发中,我们通常都会在声明变量的同时,给其赋值,这被称为初始化。</li><li>② 如果不在声明变量的同时,进行初始化,默认情况下,系统会赋予的随机值,我们也称为垃圾值。</li></ul></div><ul><li>示例:先声明,再使用</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
@ -292,7 +292,7 @@
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br></div></div><ul><li>其实C 语言的底层逻辑很简单C 语言压根不关心你定义的是有符号数还是无符号数,它只关心内存(如果定义的是有符号数,那就按照有符号数的规则来存储;如果定义的是无符号数,那就按照无符号数的规则来存储)。换言之,有符号数可以按照无符号数的规则来输出,无符号数也可以按照有符号数的规则来输出,至于输出结果对不对,那是程序员的事情,和 C 语言没有任何关系。</li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li>① 实际开发中,<code>printf</code> 函数中的常量、变量或表达式,需要和格式占位符一一对应;否则,将会出现数据错误的现象。</li><li>② 正因为上述的原因很多现代化的编程语言Java 等,直接取消了无符号的概念。但是,很多数据库是使用 C 语言开发的MySQL 等,就提供了创建数据表的字段为无符号类型的功能,即:<code>UNSIGNED</code>(正整数) ,不要感觉困惑!!!</li><li>③ 对于 <code>1000 0000 …… 0000 0000</code> 这个特殊的补码,无法按照上述的方法转换为原码,所以计算机直接规定这个补码对应的值就是 <code>-2³¹</code>,至于为什么,下节我们会详细分析。</li></ul></div></div></div></main><footer class="VPDocFooter" data-v-39a288b8 data-v-e257564d><!--[--><!--]--><div class="edit-info" data-v-e257564d><!----><div class="last-updated" data-v-e257564d><p class="VPLastUpdated" data-v-e257564d data-v-e98dd255>上次更新: <time datetime="2024-08-26T06:06:37.000Z" data-v-e98dd255></time></p></div></div><nav class="prev-next" aria-labelledby="doc-footer-aria-label" data-v-e257564d><span class="visually-hidden" id="doc-footer-aria-label" data-v-e257564d>Pager</span><div class="pager" data-v-e257564d><a class="VPLink link pager-link prev" href="/c/notes/01_c-basic/01_xdx/" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>上一篇</span><span class="title" data-v-e257564d>C 语言入门</span><!--]--></a></div><div class="pager" data-v-e257564d><a class="VPLink link pager-link next" href="/c/notes/01_c-basic/03_xdx/" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>下一篇</span><span class="title" data-v-e257564d>数据类型和运算符</span><!--]--></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><footer class="VPFooter has-sidebar" data-v-5d98c3a5 data-v-e315a0ad><div class="container" data-v-e315a0ad><p class="message" data-v-e315a0ad>Released under the MIT License.</p><p class="copyright" data-v-e315a0ad>Copyright © 2024 许大仙</p></div></footer><!--[--><!--]--></div></div>
<script>window.__VP_HASH_MAP__=JSON.parse("{\"index.md\":\"Dga0tMF5\",\"notes_01_c-basic_00_xdx_index.md\":\"BRC7slaL\",\"notes_01_c-basic_01_xdx_index.md\":\"DvCUr2L0\",\"notes_01_c-basic_02_xdx_index.md\":\"CC2Mg9VD\",\"notes_01_c-basic_03_xdx_index.md\":\"CcATnhKW\",\"notes_01_c-basic_04_xdx_index.md\":\"DABEMZSO\",\"notes_01_c-basic_05_xdx_index.md\":\"CGbN5wss\",\"notes_01_c-basic_06_xdx_index.md\":\"CIGNaKYV\",\"notes_04_linux_01_xdx_index.md\":\"C9IatKsj\",\"notes_about_index.md\":\"DLuQgC_8\",\"notes_index.md\":\"CeV-uJ5V\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"zh-CN\",\"dir\":\"ltr\",\"title\":\"许大仙\",\"titleTemplate\":\"Hi终于等到你\",\"description\":\"许大仙前端、Java、大数据、云原生\",\"base\":\"/c/\",\"head\":[],\"router\":{\"prefetchLinks\":true},\"appearance\":true,\"themeConfig\":{\"lastUpdatedText\":\"上次更新\",\"returnToTopLabel\":\"返回顶部\",\"search\":{\"provider\":\"local\"},\"logo\":\"/logo.svg\",\"nav\":[{\"text\":\"首页\",\"link\":\"https://aexiar.github.io/\"},{\"text\":\"计组6件套\",\"link\":\"https://aexiar.github.io/coa6/notes/\"},{\"text\":\"编程语言\",\"items\":[{\"text\":\"c/c++\",\"link\":\"/notes/\"},{\"text\":\"前端\",\"link\":\"https://aexiar.github.io/web-design/notes/\"},{\"text\":\"Java\",\"link\":\"https://aexiar.github.io/java/notes/\"},{\"text\":\"大数据\",\"link\":\"https://aexiar.github.io/big-data/notes/\"},{\"text\":\"云原生\",\"link\":\"https://aexiar.github.io/linux/notes/\"},{\"text\":\"Go\",\"link\":\"https://aexiar.github.io/go/notes/\"},{\"text\":\"Python\",\"link\":\"https://aexiar.github.io/python/notes/\"}]},{\"text\":\"数据库\",\"link\":\"https://aexiar.github.io/db/notes/\"},{\"text\":\"开源软件\",\"link\":\"https://aexiar.github.io/open-software/notes/\"},{\"text\":\"关于我\",\"link\":\"/notes/about/\"}],\"sidebar\":{\"/notes/\":[{\"text\":\"C 语言基础\",\"collapsed\":true,\"items\":[{\"text\":\"编程基础\",\"link\":\"/notes/01_c-basic/00_xdx/\"},{\"text\":\"C 语言入门\",\"link\":\"/notes/01_c-basic/01_xdx/\"},{\"text\":\"变量和进制\",\"link\":\"/notes/01_c-basic/02_xdx/\"},{\"text\":\"数据类型和运算符\",\"link\":\"/notes/01_c-basic/03_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/01_c-basic/04_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/01_c-basic/05_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/01_c-basic/06_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/01_c-basic/07_xdx/\"},{\"text\":\"预处理器\",\"link\":\"/notes/01_c-basic/08_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/01_c-basic/09_xdx/\"},{\"text\":\"内存管理\",\"link\":\"/notes/01_c-basic/10_xdx/\"},{\"text\":\"文件操作\",\"link\":\"/notes/01_c-basic/11_xdx/\"},{\"text\":\"调试工具和调试技巧gdb和make\",\"link\":\"/notes/02_c-basic/13_xdx/\"},{\"text\":\"常用库函数\",\"link\":\"/notes/01_c-basic/13_xdx/\"}]},{\"text\":\"C 语言高级\",\"collapsed\":true,\"items\":[{\"text\":\"变量和内存分布\",\"link\":\"/notes/02_c-advance/01_xdx/\"},{\"text\":\"指针强化\",\"link\":\"/notes/02_c-advance/02_xdx/\"},{\"text\":\"结构体和文件的高级用法\",\"link\":\"/notes/02_c-advance/03_xdx/\"},{\"text\":\"链表和回调函数\",\"link\":\"/notes/02_c-advance/04_xdx/\"},{\"text\":\"编译过程和面向接口\",\"link\":\"/notes/02_c-advance/05_xdx/\"}]},{\"text\":\"项目构建工具\",\"collapsed\":true,\"items\":[{\"text\":\"meson\",\"collapsed\":true,\"items\":[{\"text\":\"meson 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Cmake\",\"collapsed\":true,\"items\":[{\"text\":\"Cmake 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Conan \",\"link\":\"/notes/03_build/01_${commonDirectoryName}/\"},{\"text\":\"Gradle\",\"collapsed\":true,\"items\":[{\"text\":\"Gradle 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]}]},{\"text\":\"Linux\",\"collapsed\":true,\"items\":[{\"text\":\"Linux 初识和安装\",\"link\":\"/notes/04_linux/01_xdx/\"}]},{\"text\":\"C++ 基础\",\"collapsed\":true,\"items\":[{\"text\":\"C++ 入门\",\"link\":\"/notes/05_cpp/01_xdx/\"},{\"text\":\"变量、数据类型、运算符\",\"link\":\"/notes/05_cpp/02_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/05_cpp/03_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/05_cpp/04_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/05_cpp/05_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/05_cpp/06_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/05_cpp/07_xdx/\"},{\"text\":\"类和对象\",\"link\":\"/notes/05_cpp/08_xdx/\"},{\"text\":\"C++ 引用\",\"link\":\"/notes/05_cpp/09_xdx/\"},{\"text\":\"继承和派生\",\"link\":\"/notes/05_cpp/10_xdx/\"},{\"text\":\"C++ 多态和虚函数\",\"link\":\"/notes/05_cpp/11_xdx/\"},{\"text\":\"运算符重载\",\"link\":\"/notes/05_cpp/12_xdx/\"},{\"text\":\"模板\",\"link\":\"/notes/05_cpp/13_xdx/\"},{\"text\":\"C++ 异常\",\"link\":\"/notes/05_cpp/14_xdx/\"},{\"text\":\"面向对象进阶\",\"link\":\"/notes/05_cpp/15_xdx/\"},{\"text\":\"文件操作和 IO 流\",\"link\":\"/notes/05_cpp/16_xdx/\"},{\"text\":\"STL标准模板库\",\"link\":\"/notes/05_cpp/17_xdx/\"}]},{\"text\":\"C++ 高级\",\"collapsed\":true,\"items\":[]},{\"text\":\"QT 桌面开发\",\"collapsed\":true,\"items\":[]},{\"text\":\"Linux 高并发服务器开发\",\"collapsed\":true,\"items\":[]}]},\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/Aurorxa\"}],\"docFooter\":{\"prev\":\"上一篇\",\"next\":\"下一篇\"},\"darkModeSwitchLabel\":\"深浅模式\",\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2024 许大仙\"},\"outline\":{\"level\":[1,6],\"label\":\"目录\"},\"outlineTitle\":\"当前页大纲\"},\"locales\":{},\"scrollOffset\":134,\"cleanUrls\":false}");</script>
<script>window.__VP_HASH_MAP__=JSON.parse("{\"index.md\":\"Dga0tMF5\",\"notes_01_c-basic_00_xdx_index.md\":\"BRC7slaL\",\"notes_01_c-basic_01_xdx_index.md\":\"Fg4OXydV\",\"notes_01_c-basic_02_xdx_index.md\":\"CC2Mg9VD\",\"notes_01_c-basic_03_xdx_index.md\":\"Cw3Z19MO\",\"notes_01_c-basic_04_xdx_index.md\":\"ySxH8sG-\",\"notes_01_c-basic_05_xdx_index.md\":\"DUbOwEts\",\"notes_01_c-basic_06_xdx_index.md\":\"CV_r2WNu\",\"notes_01_c-basic_07_xdx_index.md\":\"CE9q5cmu\",\"notes_04_linux_01_xdx_index.md\":\"C9IatKsj\",\"notes_about_index.md\":\"DLuQgC_8\",\"notes_index.md\":\"CeV-uJ5V\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"zh-CN\",\"dir\":\"ltr\",\"title\":\"许大仙\",\"titleTemplate\":\"Hi终于等到你\",\"description\":\"许大仙前端、Java、大数据、云原生\",\"base\":\"/c/\",\"head\":[],\"router\":{\"prefetchLinks\":true},\"appearance\":true,\"themeConfig\":{\"lastUpdatedText\":\"上次更新\",\"returnToTopLabel\":\"返回顶部\",\"search\":{\"provider\":\"local\"},\"logo\":\"/logo.svg\",\"nav\":[{\"text\":\"首页\",\"link\":\"https://aexiar.github.io/\"},{\"text\":\"计组6件套\",\"link\":\"https://aexiar.github.io/coa6/notes/\"},{\"text\":\"编程语言\",\"items\":[{\"text\":\"c/c++\",\"link\":\"/notes/\"},{\"text\":\"前端\",\"link\":\"https://aexiar.github.io/web-design/notes/\"},{\"text\":\"Java\",\"link\":\"https://aexiar.github.io/java/notes/\"},{\"text\":\"大数据\",\"link\":\"https://aexiar.github.io/big-data/notes/\"},{\"text\":\"云原生\",\"link\":\"https://aexiar.github.io/linux/notes/\"},{\"text\":\"Go\",\"link\":\"https://aexiar.github.io/go/notes/\"},{\"text\":\"Python\",\"link\":\"https://aexiar.github.io/python/notes/\"}]},{\"text\":\"数据库\",\"link\":\"https://aexiar.github.io/db/notes/\"},{\"text\":\"开源软件\",\"link\":\"https://aexiar.github.io/open-software/notes/\"},{\"text\":\"关于我\",\"link\":\"/notes/about/\"}],\"sidebar\":{\"/notes/\":[{\"text\":\"C 语言基础\",\"collapsed\":true,\"items\":[{\"text\":\"编程基础\",\"link\":\"/notes/01_c-basic/00_xdx/\"},{\"text\":\"C 语言入门\",\"link\":\"/notes/01_c-basic/01_xdx/\"},{\"text\":\"变量和进制\",\"link\":\"/notes/01_c-basic/02_xdx/\"},{\"text\":\"数据类型和运算符\",\"link\":\"/notes/01_c-basic/03_xdx/\"},{\"text\":\"大话小数\",\"link\":\"/notes/01_c-basic/04_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/01_c-basic/05_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/01_c-basic/06_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/01_c-basic/07_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/01_c-basic/08_xdx/\"},{\"text\":\"预处理器\",\"link\":\"/notes/01_c-basic/09_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/01_c-basic/10_xdx/\"},{\"text\":\"内存管理\",\"link\":\"/notes/01_c-basic/11_xdx/\"},{\"text\":\"文件操作\",\"link\":\"/notes/01_c-basic/12_xdx/\"},{\"text\":\"调试工具和调试技巧gdb和make\",\"link\":\"/notes/02_c-basic/13_xdx/\"},{\"text\":\"常用库函数\",\"link\":\"/notes/01_c-basic/14_xdx/\"}]},{\"text\":\"C 语言高级\",\"collapsed\":true,\"items\":[{\"text\":\"变量和内存分布\",\"link\":\"/notes/02_c-advance/01_xdx/\"},{\"text\":\"指针强化\",\"link\":\"/notes/02_c-advance/02_xdx/\"},{\"text\":\"结构体和文件的高级用法\",\"link\":\"/notes/02_c-advance/03_xdx/\"},{\"text\":\"链表和回调函数\",\"link\":\"/notes/02_c-advance/04_xdx/\"},{\"text\":\"编译过程和面向接口\",\"link\":\"/notes/02_c-advance/05_xdx/\"}]},{\"text\":\"项目构建工具\",\"collapsed\":true,\"items\":[{\"text\":\"meson\",\"collapsed\":true,\"items\":[{\"text\":\"meson 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Cmake\",\"collapsed\":true,\"items\":[{\"text\":\"Cmake 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Conan \",\"link\":\"/notes/03_build/01_${commonDirectoryName}/\"},{\"text\":\"Gradle\",\"collapsed\":true,\"items\":[{\"text\":\"Gradle 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]}]},{\"text\":\"Linux\",\"collapsed\":true,\"items\":[{\"text\":\"Linux 初识和安装\",\"link\":\"/notes/04_linux/01_xdx/\"}]},{\"text\":\"C++ 基础\",\"collapsed\":true,\"items\":[{\"text\":\"C++ 入门\",\"link\":\"/notes/05_cpp/01_xdx/\"},{\"text\":\"变量、数据类型、运算符\",\"link\":\"/notes/05_cpp/02_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/05_cpp/03_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/05_cpp/04_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/05_cpp/05_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/05_cpp/06_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/05_cpp/07_xdx/\"},{\"text\":\"类和对象\",\"link\":\"/notes/05_cpp/08_xdx/\"},{\"text\":\"C++ 引用\",\"link\":\"/notes/05_cpp/09_xdx/\"},{\"text\":\"继承和派生\",\"link\":\"/notes/05_cpp/10_xdx/\"},{\"text\":\"C++ 多态和虚函数\",\"link\":\"/notes/05_cpp/11_xdx/\"},{\"text\":\"运算符重载\",\"link\":\"/notes/05_cpp/12_xdx/\"},{\"text\":\"模板\",\"link\":\"/notes/05_cpp/13_xdx/\"},{\"text\":\"C++ 异常\",\"link\":\"/notes/05_cpp/14_xdx/\"},{\"text\":\"面向对象进阶\",\"link\":\"/notes/05_cpp/15_xdx/\"},{\"text\":\"文件操作和 IO 流\",\"link\":\"/notes/05_cpp/16_xdx/\"},{\"text\":\"STL标准模板库\",\"link\":\"/notes/05_cpp/17_xdx/\"}]},{\"text\":\"C++ 高级\",\"collapsed\":true,\"items\":[]},{\"text\":\"QT 桌面开发\",\"collapsed\":true,\"items\":[]},{\"text\":\"Linux 高并发服务器开发\",\"collapsed\":true,\"items\":[]}]},\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/Aurorxa\"}],\"docFooter\":{\"prev\":\"上一篇\",\"next\":\"下一篇\"},\"darkModeSwitchLabel\":\"深浅模式\",\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2024 许大仙\"},\"outline\":{\"level\":[1,6],\"label\":\"目录\"},\"outlineTitle\":\"当前页大纲\"},\"locales\":{},\"scrollOffset\":134,\"cleanUrls\":false}");</script>
</body>
</html>

View File

@ -8,11 +8,11 @@
<meta name="generator" content="VitePress v1.3.3">
<link rel="preload stylesheet" href="/c/assets/style.zDJ0OJGU.css" as="style">
<script type="module" src="/c/assets/app.Ca2FOFw4.js"></script>
<script type="module" src="/c/assets/app.1a4d5P-6.js"></script>
<link rel="preload" href="/c/assets/inter-roman-latin.Di8DUHzh.woff2" as="font" type="font/woff2" crossorigin="">
<link rel="modulepreload" href="/c/assets/chunks/theme.C6fZfLtk.js">
<link rel="modulepreload" href="/c/assets/chunks/theme.Ddh-lpYV.js">
<link rel="modulepreload" href="/c/assets/chunks/framework.hMCIpNYY.js">
<link rel="modulepreload" href="/c/assets/notes_01_c-basic_03_xdx_index.md.CcATnhKW.lean.js">
<link rel="modulepreload" href="/c/assets/notes_01_c-basic_03_xdx_index.md.Cw3Z19MO.lean.js">
<link rel="shortcut icon" href="/c//logo.svg">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="">
<script id="register-sw">"serviceWorker"in navigator&&navigator.serviceWorker.register("/sw.js");</script>
@ -22,7 +22,7 @@
<script id="check-mac-os">document.documentElement.classList.toggle("mac",/Mac|iPhone|iPod|iPad/i.test(navigator.platform));</script>
</head>
<body>
<div id="app"><div class="Layout" data-v-5d98c3a5><!--[--><!--]--><!--[--><span tabindex="-1" data-v-0f60ec36></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-0f60ec36> Skip to content </a><!--]--><!----><header class="VPNav" data-v-5d98c3a5 data-v-ae24b3ad><div class="VPNavBar has-sidebar top" data-v-ae24b3ad data-v-6aa21345><div class="wrapper" data-v-6aa21345><div class="container" data-v-6aa21345><div class="title" data-v-6aa21345><div class="VPNavBarTitle has-sidebar" data-v-6aa21345 data-v-ab179fa1><a class="title" href="/c/" data-v-ab179fa1><!--[--><!--]--><!--[--><img class="VPImage logo" src="/c/logo.svg" alt data-v-8426fc1a><!--]--><span data-v-ab179fa1>许大仙</span><!--[--><!--]--></a></div></div><div class="content" data-v-6aa21345><div class="content-body" data-v-6aa21345><!--[--><!--]--><div class="VPNavBarSearch search" data-v-6aa21345><!--[--><!----><div id="local-search"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><span class="vp-icon DocSearch-Search-Icon"></span><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key">K</kbd></span></button></div><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-6aa21345 data-v-dc692963><span id="main-nav-aria-label" class="visually-hidden" data-v-dc692963> Main Navigation </span><!--[--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>首页</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/coa6/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>计组6件套</span><!--]--></a><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-dc692963 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-b6c34ac9><span class="text" data-v-b6c34ac9><!----><span data-v-b6c34ac9>编程语言</span><span class="vpi-chevron-down text-icon" data-v-b6c34ac9></span></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><div class="items" data-v-b98bc113><!--[--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link" href="/c/notes/" data-v-43f1e123><!--[-->c/c++<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/web-design/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->前端<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/java/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Java<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/big-data/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->大数据<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/linux/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->云原生<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/go/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Go<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/python/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Python<!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/db/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>数据库</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/open-software/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>开源软件</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/c/notes/about/" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>关于我</span><!--]--></a><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-6aa21345 data-v-6c893767><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-6c893767 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-6aa21345 data-v-0394ad82 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-6aa21345 data-v-bb2aa2f0 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-b6c34ac9><span class="vpi-more-horizontal icon" data-v-b6c34ac9></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><!----><!--[--><!--[--><!----><div class="group" data-v-bb2aa2f0><div class="item appearance" data-v-bb2aa2f0><p class="label" data-v-bb2aa2f0>深浅模式</p><div class="appearance-action" data-v-bb2aa2f0><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-bb2aa2f0 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div></div></div><div class="group" data-v-bb2aa2f0><div class="item social-links" data-v-bb2aa2f0><div class="VPSocialLinks social-links-list" data-v-bb2aa2f0 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div></div></div><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-6aa21345 data-v-e5dd9c1c><span class="container" data-v-e5dd9c1c><span class="top" data-v-e5dd9c1c></span><span class="middle" data-v-e5dd9c1c></span><span class="bottom" data-v-e5dd9c1c></span></span></button></div></div></div></div><div class="divider" data-v-6aa21345><div class="divider-line" data-v-6aa21345></div></div></div><!----></header><div class="VPLocalNav has-sidebar empty" data-v-5d98c3a5 data-v-a6f0e41e><div class="container" data-v-a6f0e41e><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-a6f0e41e><span class="vpi-align-left menu-icon" data-v-a6f0e41e></span><span class="menu-text" data-v-a6f0e41e>Menu</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-a6f0e41e data-v-17a5e62e><button data-v-17a5e62e>返回顶部</button><!----></div></div></div><aside class="VPSidebar" data-v-5d98c3a5 data-v-319d5ca6><div class="curtain" data-v-319d5ca6></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-319d5ca6><span class="visually-hidden" id="sidebar-aria-label" data-v-319d5ca6> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible has-active" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/00_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编程基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C 语言入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和进制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数据类型和运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>预处理器</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>内存管理</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-basic/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>调试工具和调试技巧gdb和make</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>常用库函数</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言高级</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和内存分布</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针强化</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>结构体和文件的高级用法</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>链表和回调函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编译过程和面向接口</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>项目构建工具</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>meson</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>meson 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Cmake</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Cmake 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_${commonDirectoryName}/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Conan </p><!--]--></a><!----></div><!----></div><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Gradle</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Gradle 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>Linux</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/04_linux/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Linux 初识和安装</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C++ 基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量、数据类型、运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>类和对象</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 引用</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>继承和派生</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 多态和虚函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/12_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>运算符重载</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>模板</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/14_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 异常</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/15_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>面向对象进阶</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/16_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作和 IO 流</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/17_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>STL标准模板库</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>C++ 高级</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>QT 桌面开发</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>Linux 高并发服务器开发</p><!----></div><!----></div></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-5d98c3a5 data-v-1428d186><div class="VPDoc has-sidebar has-aside" data-v-1428d186 data-v-39a288b8><!--[--><!--]--><div class="container" data-v-39a288b8><div class="aside" data-v-39a288b8><div class="aside-curtain" data-v-39a288b8></div><div class="aside-container" data-v-39a288b8><div class="aside-content" data-v-39a288b8><div class="VPDocAside" data-v-39a288b8 data-v-3f215769><!--[--><!--]--><!--[--><!--]--><nav aria-labelledby="doc-outline-aria-label" class="VPDocAsideOutline" data-v-3f215769 data-v-a5bbad30><div class="content" data-v-a5bbad30><div class="outline-marker" data-v-a5bbad30></div><div aria-level="2" class="outline-title" id="doc-outline-aria-label" role="heading" data-v-a5bbad30>目录</div><ul class="VPDocOutlineItem root" data-v-a5bbad30 data-v-b933a997><!--[--><!--]--></ul></div></nav><!--[--><!--]--><div class="spacer" data-v-3f215769></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-39a288b8><div class="content-container" data-v-39a288b8><!--[--><!--]--><main class="main" data-v-39a288b8><div style="position:relative;" class="vp-doc _c_notes_01_c-basic_03_xdx_" data-v-39a288b8><div><h1 id="第一章-数据类型-⭐" tabindex="-1">第一章:数据类型(⭐) <a class="header-anchor" href="#第一章-数据类型-⭐" aria-label="Permalink to &quot;第一章:数据类型(⭐)&quot;"></a></h1><h2 id="_1-1-概述" tabindex="-1">1.1 概述 <a class="header-anchor" href="#_1-1-概述" aria-label="Permalink to &quot;1.1 概述&quot;"></a></h2><ul><li><p>根据<code>变量</code><code>存储</code><code></code><code>不同</code>,我们可以将<code>变量</code>分为两类:</p><ul><li><code>普通变量</code>:变量所对应的内存中存储的是<code>普通值</code></li><li><code>指针变量</code>:变量所对应的内存中存储的是<code>另一个变量的地址</code></li></ul></li><li><p>如下图所示:</p></li></ul><p><img src="/c/assets/1.L8V3GBrc.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>普通变量和指针变量的相同点:</p><ul><li>普通变量有内存空间,指针变量也有内存空间。</li><li>普通变量有内存地址,指针变量也有内存地址。</li><li>普通变量所对应的内存空间中有值,指针变量所对应的内存空间中也有值。</li></ul><p>普通变量和指针变量的不同点:</p><ul><li>普通变量所对应的内存空间存储的是普通的值,如:整数、小数、字符等;指针变量所对应的内存空间存储的是另外一个变量的地址。</li><li>普通变量有普通变量的运算方式,而指针变量有指针变量的运算方式(后续讲解)。</li></ul></div><ul><li>那么,在 C 语言中变量的数据类型就可以这么划分,如下所示:</li></ul><p><img src="/c/assets/2.nqdAY_P3.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>根据<code>普通变量</code><code>存储</code><code></code>的类型不同,可以将<code>普通变量类型</code>划分为<code>基本数据类型</code>(整型、字符类型、浮点类型、布尔类型)和<code>复合数据类型</code>(数组类型、结构体类型、共用体类型、枚举类型)。</li><li>根据<code>指针变量</code><code>指向空间</code><code>存储</code><code></code>的类型不同,可以将<code>指针类型</code>分为<code>基本数据类型指针</code><code>复合数据类型指针</code><code>函数指针</code><code>数组指针</code>等,例如:如果指针所指向的空间保存的是 int 类型,那么该指针就是 int 类型的指针。</li></ul></div><h2 id="_1-2-整数类型" tabindex="-1">1.2 整数类型 <a class="header-anchor" href="#_1-2-整数类型" aria-label="Permalink to &quot;1.2 整数类型&quot;"></a></h2><h3 id="_1-2-1-概述" tabindex="-1">1.2.1 概述 <a class="header-anchor" href="#_1-2-1-概述" aria-label="Permalink to &quot;1.2.1 概述&quot;"></a></h3><ul><li>整数类型简称整型用于存储整数值12、20、50 等。</li><li>根据所占<code>内存空间</code>大小的不同,可以将整数类型划分为:</li><li>① 短整型:</li></ul><table tabindex="0"><thead><tr><th>类型</th><th>存储空间(内存空间)</th><th>取值范围</th></tr></thead><tbody><tr><td>unsigned short (无符号短整型)</td><td>2 字节</td><td>0 ~ 65,535 (2^16 - 1)</td></tr><tr><td>[signed] short有符号短整型默认</td><td>2 字节</td><td>-32,768 (- 2^15) ~ 32,767 (2^15 -1)</td></tr></tbody></table><ul><li>② 整型:</li></ul><table tabindex="0"><thead><tr><th>类型</th><th>存储空间(内存空间)</th><th>取值范围</th></tr></thead><tbody><tr><td>unsigned int无符号整型</td><td>4 字节(通常)</td><td>0 ~ 4294967295 (0 ~2^32 -1)</td></tr><tr><td>[signed] int有符号整型默认</td><td>4 字节(通常)</td><td>-2147483648- 2^31 ~ 2147483647 (2^31-1)</td></tr></tbody></table><ul><li>③ 长整型:</li></ul><table tabindex="0"><thead><tr><th>类型</th><th>存储空间(内存空间)</th><th>取值范围</th></tr></thead><tbody><tr><td>unsigned long无符号长整型</td><td>4 字节(通常)</td><td>0 ~2^32 -1</td></tr><tr><td>[signed] long有符号长整型默认</td><td>4 字节(通常)</td><td>- 2^31 ~ 2^31-1</td></tr></tbody></table><ul><li>④ 长长整型:</li></ul><table tabindex="0"><thead><tr><th>类型</th><th>存储空间(内存空间)</th><th>取值范围</th></tr></thead><tbody><tr><td>unsigned long long无符号长整型</td><td>8 字节(通常)</td><td>0 ~2^64 -1</td></tr><tr><td>[signed] long long有符号长整型默认</td><td>8 字节(通常)</td><td>- 2^63 ~ 2^63-1</td></tr></tbody></table><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li><p>① 数据类型在内存中占用的存储单元字节数就称为该数据类型的长度步长short 占用 2 个字节的内存,就称 short 的长度(步长)是 2。</p></li><li><p>② C 语言并没有严格规定各种整数数据类型在内存中所占存储单元的长度,只做了宽泛的限制:</p><ul><li>short 至少占用 2 个字节的存储单元。</li><li>int 建议为一个机器字长(指计算机的处理器在一次操作中能够处理的二进制数据的位数,机器字长是处理器的“字”长度,它决定了处理器在一个时钟周期内能够处理的数据量,如:早期的计算机的处理器通常是 8 位的机器字长,意味着处理器一次只能处理 8 位(二进制)数据;之后的计算机的处理器有 16 位的机器字长,意味着处理器一次可以处理 16 位的数据;再之后计算机的处理器有 32 位或 64 位的机器字长,意味着处理器一次可以处理 32 位或 64位的数据。即32 位环境下 int 占用 4 个字节的存储单元64 位环境下 int 占用 8 个字节的存储单元。</li><li>short 的长度(步长)不能大于 intlong 的长度(步长)不能小于 intlong long 不能小于 long。</li></ul></li><li><p>③ 那么,各种整数数据类型在内存中所占存储单元的长度的公式就是 <code>2 ≤ sizeof(short) ≤ sizeof(int) ≤ sizeof(long) ≤ sizeof(long long)</code>,具体的存储空间由编译系统自行决定。其中,<code>sizeof</code> 是测量类型或变量、常量长度的<code>运算符</code></p></li></ul></div><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li>① 之所以这么规定,是为了可以让 C 语言长久使用,因为目前主流的 CPU 都是 64 位,但是在 C 语言刚刚出现的时候CPU 还是以 8 位和 16 位为主。如果当时就将整型定死为 8 位或 16 位,那么现在我们肯定不会再学习 C 语言了。</li><li>② 整型分为有符号 signed 和无符号 unsigned 两种,默认是 signed。</li><li>③ 在实际开发中,<code>最常用的整数类型</code>就是 <code>int</code> 类型了,如果取值范围不够,就使用 long 或 long long 。</li><li>④ C 语言中的<code>格式占位符</code>非常多,只需要大致了解即可;因为,我们在实际开发中,一般都会使用 C++ 或 Rust 以及其它的高级编程语言Java 等,早已经解决了必须通过<code>格式占位符</code>来才能将变量进行输入和输出。</li></ul></div><h3 id="_1-2-2-短整型-了解" tabindex="-1">1.2.2 短整型(了解) <a class="header-anchor" href="#_1-2-2-短整型-了解" aria-label="Permalink to &quot;1.2.2 短整型(了解)&quot;"></a></h3><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">unsigned</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> short</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> x </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 无符号短整型</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">short</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> x </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> -</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 有符号短整型</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 有符号表示的是正数、负数和 0 ,即有正负号。无符号表示的是 0 和正数,即正整数,没有符号。</li><li>② 在 <code>printf</code><code>无符号短整型unsigned short</code><code>格式占位符</code><code>%hu</code> <code>有符号短整型signed short</code><code>格式占位符</code><code>%hd</code></li><li>③ 可以通过 <code>sizeof</code> 运算符获取<code>无符号短整型unsigned short</code><code>有符号短整型signed short</code><code>存储空间(所占内存空间)</code></li><li>③ 可以通过 <code>#include &lt;limits.h&gt;</code> 来获取 <code>无符号短整型unsigned short</code><code>有符号短整型signed short</code><code>取值范围</code></li></ul></div><ul><li>示例:定义和打印短整型变量</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<div id="app"><div class="Layout" data-v-5d98c3a5><!--[--><!--]--><!--[--><span tabindex="-1" data-v-0f60ec36></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-0f60ec36> Skip to content </a><!--]--><!----><header class="VPNav" data-v-5d98c3a5 data-v-ae24b3ad><div class="VPNavBar has-sidebar top" data-v-ae24b3ad data-v-6aa21345><div class="wrapper" data-v-6aa21345><div class="container" data-v-6aa21345><div class="title" data-v-6aa21345><div class="VPNavBarTitle has-sidebar" data-v-6aa21345 data-v-ab179fa1><a class="title" href="/c/" data-v-ab179fa1><!--[--><!--]--><!--[--><img class="VPImage logo" src="/c/logo.svg" alt data-v-8426fc1a><!--]--><span data-v-ab179fa1>许大仙</span><!--[--><!--]--></a></div></div><div class="content" data-v-6aa21345><div class="content-body" data-v-6aa21345><!--[--><!--]--><div class="VPNavBarSearch search" data-v-6aa21345><!--[--><!----><div id="local-search"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><span class="vp-icon DocSearch-Search-Icon"></span><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key">K</kbd></span></button></div><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-6aa21345 data-v-dc692963><span id="main-nav-aria-label" class="visually-hidden" data-v-dc692963> Main Navigation </span><!--[--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>首页</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/coa6/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>计组6件套</span><!--]--></a><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-dc692963 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-b6c34ac9><span class="text" data-v-b6c34ac9><!----><span data-v-b6c34ac9>编程语言</span><span class="vpi-chevron-down text-icon" data-v-b6c34ac9></span></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><div class="items" data-v-b98bc113><!--[--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link" href="/c/notes/" data-v-43f1e123><!--[-->c/c++<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/web-design/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->前端<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/java/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Java<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/big-data/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->大数据<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/linux/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->云原生<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/go/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Go<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/python/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Python<!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/db/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>数据库</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/open-software/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>开源软件</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/c/notes/about/" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>关于我</span><!--]--></a><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-6aa21345 data-v-6c893767><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-6c893767 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-6aa21345 data-v-0394ad82 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-6aa21345 data-v-bb2aa2f0 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-b6c34ac9><span class="vpi-more-horizontal icon" data-v-b6c34ac9></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><!----><!--[--><!--[--><!----><div class="group" data-v-bb2aa2f0><div class="item appearance" data-v-bb2aa2f0><p class="label" data-v-bb2aa2f0>深浅模式</p><div class="appearance-action" data-v-bb2aa2f0><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-bb2aa2f0 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div></div></div><div class="group" data-v-bb2aa2f0><div class="item social-links" data-v-bb2aa2f0><div class="VPSocialLinks social-links-list" data-v-bb2aa2f0 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div></div></div><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-6aa21345 data-v-e5dd9c1c><span class="container" data-v-e5dd9c1c><span class="top" data-v-e5dd9c1c></span><span class="middle" data-v-e5dd9c1c></span><span class="bottom" data-v-e5dd9c1c></span></span></button></div></div></div></div><div class="divider" data-v-6aa21345><div class="divider-line" data-v-6aa21345></div></div></div><!----></header><div class="VPLocalNav has-sidebar empty" data-v-5d98c3a5 data-v-a6f0e41e><div class="container" data-v-a6f0e41e><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-a6f0e41e><span class="vpi-align-left menu-icon" data-v-a6f0e41e></span><span class="menu-text" data-v-a6f0e41e>Menu</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-a6f0e41e data-v-17a5e62e><button data-v-17a5e62e>返回顶部</button><!----></div></div></div><aside class="VPSidebar" data-v-5d98c3a5 data-v-319d5ca6><div class="curtain" data-v-319d5ca6></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-319d5ca6><span class="visually-hidden" id="sidebar-aria-label" data-v-319d5ca6> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible has-active" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/00_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编程基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C 语言入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和进制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数据类型和运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>大话小数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>预处理器</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>内存管理</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/12_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-basic/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>调试工具和调试技巧gdb和make</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/14_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>常用库函数</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言高级</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和内存分布</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针强化</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>结构体和文件的高级用法</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>链表和回调函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编译过程和面向接口</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>项目构建工具</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>meson</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>meson 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Cmake</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Cmake 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_${commonDirectoryName}/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Conan </p><!--]--></a><!----></div><!----></div><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Gradle</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Gradle 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>Linux</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/04_linux/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Linux 初识和安装</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C++ 基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量、数据类型、运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>类和对象</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 引用</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>继承和派生</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 多态和虚函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/12_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>运算符重载</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>模板</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/14_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 异常</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/15_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>面向对象进阶</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/16_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作和 IO 流</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/17_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>STL标准模板库</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>C++ 高级</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>QT 桌面开发</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>Linux 高并发服务器开发</p><!----></div><!----></div></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-5d98c3a5 data-v-1428d186><div class="VPDoc has-sidebar has-aside" data-v-1428d186 data-v-39a288b8><!--[--><!--]--><div class="container" data-v-39a288b8><div class="aside" data-v-39a288b8><div class="aside-curtain" data-v-39a288b8></div><div class="aside-container" data-v-39a288b8><div class="aside-content" data-v-39a288b8><div class="VPDocAside" data-v-39a288b8 data-v-3f215769><!--[--><!--]--><!--[--><!--]--><nav aria-labelledby="doc-outline-aria-label" class="VPDocAsideOutline" data-v-3f215769 data-v-a5bbad30><div class="content" data-v-a5bbad30><div class="outline-marker" data-v-a5bbad30></div><div aria-level="2" class="outline-title" id="doc-outline-aria-label" role="heading" data-v-a5bbad30>目录</div><ul class="VPDocOutlineItem root" data-v-a5bbad30 data-v-b933a997><!--[--><!--]--></ul></div></nav><!--[--><!--]--><div class="spacer" data-v-3f215769></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-39a288b8><div class="content-container" data-v-39a288b8><!--[--><!--]--><main class="main" data-v-39a288b8><div style="position:relative;" class="vp-doc _c_notes_01_c-basic_03_xdx_" data-v-39a288b8><div><h1 id="第一章-数据类型-⭐" tabindex="-1">第一章:数据类型(⭐) <a class="header-anchor" href="#第一章-数据类型-⭐" aria-label="Permalink to &quot;第一章:数据类型(⭐)&quot;"></a></h1><h2 id="_1-1-概述" tabindex="-1">1.1 概述 <a class="header-anchor" href="#_1-1-概述" aria-label="Permalink to &quot;1.1 概述&quot;"></a></h2><ul><li><p>根据<code>变量</code><code>存储</code><code></code><code>不同</code>,我们可以将<code>变量</code>分为两类:</p><ul><li><code>普通变量</code>:变量所对应的内存中存储的是<code>普通值</code></li><li><code>指针变量</code>:变量所对应的内存中存储的是<code>另一个变量的地址</code></li></ul></li><li><p>如下图所示:</p></li></ul><p><img src="/c/assets/1.L8V3GBrc.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>普通变量和指针变量的相同点:</p><ul><li>普通变量有内存空间,指针变量也有内存空间。</li><li>普通变量有内存地址,指针变量也有内存地址。</li><li>普通变量所对应的内存空间中有值,指针变量所对应的内存空间中也有值。</li></ul><p>普通变量和指针变量的不同点:</p><ul><li>普通变量所对应的内存空间存储的是普通的值,如:整数、小数、字符等;指针变量所对应的内存空间存储的是另外一个变量的地址。</li><li>普通变量有普通变量的运算方式,而指针变量有指针变量的运算方式(后续讲解)。</li></ul></div><ul><li>那么,在 C 语言中变量的数据类型就可以这么划分,如下所示:</li></ul><p><img src="/c/assets/2.nqdAY_P3.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>根据<code>普通变量</code><code>存储</code><code></code>的类型不同,可以将<code>普通变量类型</code>划分为<code>基本数据类型</code>(整型、字符类型、浮点类型、布尔类型)和<code>复合数据类型</code>(数组类型、结构体类型、共用体类型、枚举类型)。</li><li>根据<code>指针变量</code><code>指向空间</code><code>存储</code><code></code>的类型不同,可以将<code>指针类型</code>分为<code>基本数据类型指针</code><code>复合数据类型指针</code><code>函数指针</code><code>数组指针</code>等,例如:如果指针所指向的空间保存的是 int 类型,那么该指针就是 int 类型的指针。</li></ul></div><h2 id="_1-2-整数类型" tabindex="-1">1.2 整数类型 <a class="header-anchor" href="#_1-2-整数类型" aria-label="Permalink to &quot;1.2 整数类型&quot;"></a></h2><h3 id="_1-2-1-概述" tabindex="-1">1.2.1 概述 <a class="header-anchor" href="#_1-2-1-概述" aria-label="Permalink to &quot;1.2.1 概述&quot;"></a></h3><ul><li>整数类型简称整型用于存储整数值12、20、50 等。</li><li>根据所占<code>内存空间</code>大小的不同,可以将整数类型划分为:</li><li>① 短整型:</li></ul><table tabindex="0"><thead><tr><th>类型</th><th>存储空间(内存空间)</th><th>取值范围</th></tr></thead><tbody><tr><td>unsigned short (无符号短整型)</td><td>2 字节</td><td>0 ~ 65,535 (2^16 - 1)</td></tr><tr><td>[signed] short有符号短整型默认</td><td>2 字节</td><td>-32,768 (- 2^15) ~ 32,767 (2^15 -1)</td></tr></tbody></table><ul><li>② 整型:</li></ul><table tabindex="0"><thead><tr><th>类型</th><th>存储空间(内存空间)</th><th>取值范围</th></tr></thead><tbody><tr><td>unsigned int无符号整型</td><td>4 字节(通常)</td><td>0 ~ 4294967295 (0 ~2^32 -1)</td></tr><tr><td>[signed] int有符号整型默认</td><td>4 字节(通常)</td><td>-2147483648- 2^31 ~ 2147483647 (2^31-1)</td></tr></tbody></table><ul><li>③ 长整型:</li></ul><table tabindex="0"><thead><tr><th>类型</th><th>存储空间(内存空间)</th><th>取值范围</th></tr></thead><tbody><tr><td>unsigned long无符号长整型</td><td>4 字节(通常)</td><td>0 ~2^32 -1</td></tr><tr><td>[signed] long有符号长整型默认</td><td>4 字节(通常)</td><td>- 2^31 ~ 2^31-1</td></tr></tbody></table><ul><li>④ 长长整型:</li></ul><table tabindex="0"><thead><tr><th>类型</th><th>存储空间(内存空间)</th><th>取值范围</th></tr></thead><tbody><tr><td>unsigned long long无符号长整型</td><td>8 字节(通常)</td><td>0 ~2^64 -1</td></tr><tr><td>[signed] long long有符号长整型默认</td><td>8 字节(通常)</td><td>- 2^63 ~ 2^63-1</td></tr></tbody></table><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li><p>① 数据类型在内存中占用的存储单元字节数就称为该数据类型的长度步长short 占用 2 个字节的内存,就称 short 的长度(步长)是 2。</p></li><li><p>② C 语言并没有严格规定各种整数数据类型在内存中所占存储单元的长度,只做了宽泛的限制:</p><ul><li>short 至少占用 2 个字节的存储单元。</li><li>int 建议为一个机器字长(指计算机的处理器在一次操作中能够处理的二进制数据的位数,机器字长是处理器的“字”长度,它决定了处理器在一个时钟周期内能够处理的数据量,如:早期的计算机的处理器通常是 8 位的机器字长,意味着处理器一次只能处理 8 位(二进制)数据;之后的计算机的处理器有 16 位的机器字长,意味着处理器一次可以处理 16 位的数据;再之后计算机的处理器有 32 位或 64 位的机器字长,意味着处理器一次可以处理 32 位或 64位的数据。即32 位环境下 int 占用 4 个字节的存储单元64 位环境下 int 占用 8 个字节的存储单元。</li><li>short 的长度(步长)不能大于 intlong 的长度(步长)不能小于 intlong long 不能小于 long。</li></ul></li><li><p>③ 那么,各种整数数据类型在内存中所占存储单元的长度的公式就是 <code>2 ≤ sizeof(short) ≤ sizeof(int) ≤ sizeof(long) ≤ sizeof(long long)</code>,具体的存储空间由编译系统自行决定。其中,<code>sizeof</code> 是测量类型或变量、常量长度的<code>运算符</code></p></li></ul></div><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li>① 之所以这么规定,是为了可以让 C 语言长久使用,因为目前主流的 CPU 都是 64 位,但是在 C 语言刚刚出现的时候CPU 还是以 8 位和 16 位为主。如果当时就将整型定死为 8 位或 16 位,那么现在我们肯定不会再学习 C 语言了。</li><li>② 整型分为有符号 signed 和无符号 unsigned 两种,默认是 signed。</li><li>③ 在实际开发中,<code>最常用的整数类型</code>就是 <code>int</code> 类型了,如果取值范围不够,就使用 long 或 long long 。</li><li>④ C 语言中的<code>格式占位符</code>非常多,只需要大致了解即可;因为,我们在实际开发中,一般都会使用 C++ 或 Rust 以及其它的高级编程语言Java 等,早已经解决了必须通过<code>格式占位符</code>来才能将变量进行输入和输出。</li></ul></div><h3 id="_1-2-2-短整型-了解" tabindex="-1">1.2.2 短整型(了解) <a class="header-anchor" href="#_1-2-2-短整型-了解" aria-label="Permalink to &quot;1.2.2 短整型(了解)&quot;"></a></h3><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">unsigned</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> short</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> x </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 无符号短整型</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">short</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> x </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> -</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 有符号短整型</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 有符号表示的是正数、负数和 0 ,即有正负号。无符号表示的是 0 和正数,即正整数,没有符号。</li><li>② 在 <code>printf</code><code>无符号短整型unsigned short</code><code>格式占位符</code><code>%hu</code> <code>有符号短整型signed short</code><code>格式占位符</code><code>%hd</code></li><li>③ 可以通过 <code>sizeof</code> 运算符获取<code>无符号短整型unsigned short</code><code>有符号短整型signed short</code><code>存储空间(所占内存空间)</code></li><li>③ 可以通过 <code>#include &lt;limits.h&gt;</code> 来获取 <code>无符号短整型unsigned short</code><code>有符号短整型signed short</code><code>取值范围</code></li></ul></div><ul><li>示例:定义和打印短整型变量</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
@ -369,7 +369,7 @@
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> b </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 123.00</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 浮点赋值给整数类型,会直接截断小数点后面的数</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;b=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, b);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // b=123</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><h2 id="_1-5-字符类型" tabindex="-1">1.5 字符类型 <a class="header-anchor" href="#_1-5-字符类型" aria-label="Permalink to &quot;1.5 字符类型&quot;"></a></h2><h3 id="_1-5-1-概述" tabindex="-1">1.5.1 概述 <a class="header-anchor" href="#_1-5-1-概述" aria-label="Permalink to &quot;1.5.1 概述&quot;"></a></h3><ul><li>在生活中,我们会经常说:今天天气真 <code></code>,我的性别是 <code></code>,我今年 <code>10</code>,像这类数据,在 C 语言中就可以用字符char来表示。</li><li>在 C 语言中,变量的<code>字符类型</code>可以表示<code></code>个字符,如:<code>&#39;1&#39;</code><code>&#39;A&#39;</code><code>&#39;&amp;&#39;</code></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① C 语言的出现在 1972 年,由美国人丹尼斯·里奇设计出来;那个时候,只需要 1 个字节的内存空间就可以完美的表示拉丁体系英文文字a-z、A-Z、0-9 以及一些特殊符号所以C 语言中不支持多个字节的字符,如:中文、日文等。</li><li>② 像拉丁体系英文文字a-z、A-Z、0-9 以及一些特殊符号,只需要单个字节的内存存储空间就能存储的,我们就称为窄类型;而像中文、日文等单个字节的内存空间存储不了的,我们就称为宽类型。</li><li>③ C 语言中没有字符串类型是使用字符数组char 数组)来模拟字符串的,并且字符数组也不是字符串,而是构造类型</li><li>④ 在 C 语言中如果想要输出中文、日文等多字节字符就需要使用字符数组char 数组)。</li><li>⑤ 在 C++、Java 等高级编程语言中,已经提供了 String (字符串)类型,原生支持 Unicode可以方便地处理多语言和特殊字符。</li></ul></div><ul><li>在 C 语言中,可以使用<code>转义字符 \</code>来表示特殊含义的字符。</li></ul><table tabindex="0"><thead><tr><th><strong>转义字符</strong></th><th><strong>说明</strong></th></tr></thead><tbody><tr><td><code>\b</code></td><td>退格</td></tr><tr><td><code>\n</code></td><td>换行符</td></tr><tr><td><code>\r</code></td><td>回车符</td></tr><tr><td><code>\t</code></td><td>制表符</td></tr><tr><td><code>\&quot;</code></td><td>双引号</td></tr><tr><td><code>\&#39;</code></td><td>单引号</td></tr><tr><td><code>\\</code></td><td>反斜杠</td></tr><tr><td>...</td><td></td></tr></tbody></table><h3 id="_1-5-2-格式占位符" tabindex="-1">1.5.2 格式占位符 <a class="header-anchor" href="#_1-5-2-格式占位符" aria-label="Permalink to &quot;1.5.2 格式占位符&quot;"></a></h3><ul><li><p>在 C 语言中,使用 <code>%c</code> 来表示 char 类型。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><h2 id="_1-5-字符类型" tabindex="-1">1.5 字符类型 <a class="header-anchor" href="#_1-5-字符类型" aria-label="Permalink to &quot;1.5 字符类型&quot;"></a></h2><h3 id="_1-5-1-概述" tabindex="-1">1.5.1 概述 <a class="header-anchor" href="#_1-5-1-概述" aria-label="Permalink to &quot;1.5.1 概述&quot;"></a></h3><ul><li>在生活中,我们会经常说:今天天气真 <code></code>,我的性别是 <code></code>,我今年 <code>10</code>等。像这类数据,在 C 语言中就可以用<code>字符类型</code>char来表示。<code>字符类型</code>表示<code></code>个字符,使用单引号(<code>&#39;&#39;</code>)括起来,如:<code>&#39;1&#39;</code><code>&#39;A&#39;</code><code>&#39;&amp;&#39;</code></li><li>但是,在生活中,也许会听到:<code>你是好人,只是现阶段,我想学习</code><code>好的啊,我们在一起</code>等。像这类数据,在 C 语言中就可以用<code>字符</code>String来表示。<code>字符串类型</code>表示<code></code>个字符的集合,使用双引号(<code>&quot;&quot;</code>)括起来,如:<code>&quot;1&quot;</code><code>&quot;A&quot;</code><code>&quot;&amp;&quot;</code><code>&quot;我们&quot;</code></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① C 语言的出现在 1972 年,由美国人丹尼斯·里奇设计出来;那个时候,只需要 1 个字节的内存空间就可以完美的表示拉丁体系英文文字a-z、A-Z、0-9 以及一些特殊符号所以C 语言中不支持多个字节的字符,如:中文、日文等。</li><li>② 像拉丁体系英文文字a-z、A-Z、0-9 以及一些特殊符号,只需要单个字节的内存存储空间就能存储的,我们就称为窄类型;而像中文、日文等单个字节的内存空间存储不了的,我们就称为宽类型。</li><li>C 语言中,是没有字符串类型是使用字符数组char 数组)来模拟字符串的。字符串中的字符在内存中按照次序、紧挨着排列,整个字符串占用一块连续的内存</li><li>④ 在 C 语言中如果想要输出中文、日文等多字节字符就需要使用字符数组char 数组)。</li><li>⑤ 在 C++、Java 等高级编程语言中,已经提供了 String (字符串)类型,原生支持 Unicode可以方便地处理多语言和特殊字符。</li></ul></div><ul><li>在 C 语言中,可以使用<code>转义字符 \</code>来表示特殊含义的字符。</li></ul><table tabindex="0"><thead><tr><th><strong>转义字符</strong></th><th><strong>说明</strong></th></tr></thead><tbody><tr><td><code>\b</code></td><td>退格</td></tr><tr><td><code>\n</code></td><td>换行符</td></tr><tr><td><code>\r</code></td><td>回车符</td></tr><tr><td><code>\t</code></td><td>制表符</td></tr><tr><td><code>\&quot;</code></td><td>双引号</td></tr><tr><td><code>\&#39;</code></td><td>单引号</td></tr><tr><td><code>\\</code></td><td>反斜杠</td></tr><tr><td>...</td><td></td></tr></tbody></table><h3 id="_1-5-2-格式占位符" tabindex="-1">1.5.2 格式占位符 <a class="header-anchor" href="#_1-5-2-格式占位符" aria-label="Permalink to &quot;1.5.2 格式占位符&quot;"></a></h3><ul><li><p>在 C 语言中,使用 <code>%c</code> 来表示 char 类型。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
@ -425,7 +425,45 @@
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;c1=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">, c2=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">, c3=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, c1, c2, c3);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br></div></div><h2 id="_1-6-布尔类型" tabindex="-1">1.6 布尔类型 <a class="header-anchor" href="#_1-6-布尔类型" aria-label="Permalink to &quot;1.6 布尔类型&quot;"></a></h2><h3 id="_1-6-1-概述" tabindex="-1">1.6.1 概述 <a class="header-anchor" href="#_1-6-1-概述" aria-label="Permalink to &quot;1.6.1 概述&quot;"></a></h3><ul><li>布尔值用于表示 true、false两种状态通常用于逻辑运算和条件判断。</li></ul><h3 id="_1-6-2-早期的布尔类型" tabindex="-1">1.6.2 早期的布尔类型 <a class="header-anchor" href="#_1-6-2-早期的布尔类型" aria-label="Permalink to &quot;1.6.2 早期的布尔类型&quot;"></a></h3><ul><li><p>在 C 语言标准C89并没有为布尔值单独设置一个数据类型所以在判断真、假的时候使用 <code>0</code> 表示 <code>false</code>(假),<code>非 0</code> 表示 <code>true</code>(真)。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br></div></div><h3 id="_1-5-6-输出字符方式二-了解" tabindex="-1">1.5.6 输出字符方式二(了解) <a class="header-anchor" href="#_1-5-6-输出字符方式二-了解" aria-label="Permalink to &quot;1.5.6 输出字符方式二(了解)&quot;"></a></h3><ul><li>在 C 语言中,除了可以使用 <code>printf()</code> 函数输出字符之外,还可以使用 <code>putchar()</code>函数输出字符。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li><code>putchar()</code> 函数每次只能输出一个字符,如果需要输出多个字符需要调用多次;而 <code>printf()</code> 函数一次可以输出多个字符,并且 <code>char</code> 类型对应的格式占位符是 <code>%c</code></li><li>② 在实际开发中,使用 <code>printf()</code> 函数居多。</li></ul></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> a </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;1&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> b </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;2&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> c </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;&amp;&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> /* 12&amp; */</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> putchar</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(a);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> putchar</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(b);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> putchar</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(c);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><h3 id="_1-5-7-初谈字符串-了解" tabindex="-1">1.5.7 初谈字符串(了解) <a class="header-anchor" href="#_1-5-7-初谈字符串-了解" aria-label="Permalink to &quot;1.5.7 初谈字符串(了解)&quot;"></a></h3><ul><li>在 C 语言中没有专门的字符串类型,是使用<code>字符数组</code>来模拟字符串的,即:可以使用字符数组来存储字符串。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 在 C 语言中,<code>数组</code><code>指针</code>通常会一起出现,所以当<code>字符数组</code>可以保存字符串,也就意味着可以使用<code>指针</code>来间接存储字符串。</li><li>② 在 C 语言中,可以使用 <code>puts()</code> 函数输出字符串,每调用一次 <code>puts()</code> 函数,除了输出字符串之外,还会在字符串后面加上换行,即:<code>\n</code></li><li>③ 在 C 语言中,可以使用 <code>printf()</code> 函数输出字符串,并且字符串对应的格式占位符是 <code>%s</code>。和 <code>puts()</code> 函数不同的是,<code>printf()</code> 函数不会在字符串后面加上换行,即:<code>\n</code></li><li>④ 在实际开发中,使用 <code>printf()</code> 函数居多。</li></ul></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 存储字符串</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> str</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">str2 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;爱你&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> puts</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(str);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 我</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> puts</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(str2);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 爱你</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 存储字符串</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> str</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">str2 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;是好人&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%s\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, str);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 你</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%s\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, str2);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 是好人</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><h2 id="_1-6-布尔类型" tabindex="-1">1.6 布尔类型 <a class="header-anchor" href="#_1-6-布尔类型" aria-label="Permalink to &quot;1.6 布尔类型&quot;"></a></h2><h3 id="_1-6-1-概述" tabindex="-1">1.6.1 概述 <a class="header-anchor" href="#_1-6-1-概述" aria-label="Permalink to &quot;1.6.1 概述&quot;"></a></h3><ul><li>布尔值用于表示 true、false两种状态通常用于逻辑运算和条件判断。</li></ul><h3 id="_1-6-2-早期的布尔类型" tabindex="-1">1.6.2 早期的布尔类型 <a class="header-anchor" href="#_1-6-2-早期的布尔类型" aria-label="Permalink to &quot;1.6.2 早期的布尔类型&quot;"></a></h3><ul><li><p>在 C 语言标准C89并没有为布尔值单独设置一个数据类型所以在判断真、假的时候使用 <code>0</code> 表示 <code>false</code>(假),<code>非 0</code> 表示 <code>true</code>(真)。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 禁用 stdout 缓冲区</span></span>
@ -840,8 +878,8 @@
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;result = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, result);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // result = 110</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><h2 id="_2-8-运算符优先级" tabindex="-1">2.8 运算符优先级 <a class="header-anchor" href="#_2-8-运算符优先级" aria-label="Permalink to &quot;2.8 运算符优先级&quot;"></a></h2><ul><li>C 语言中运算符的优先级,如下所示:</li></ul><table tabindex="0"><thead><tr><th><strong>优先级</strong></th><th><strong>运算符</strong></th><th><strong>名称或含义</strong></th><th><strong>结合方向</strong></th></tr></thead><tbody><tr><td><strong>1</strong></td><td><code>[]</code></td><td>数组下标</td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>()</code></td><td>圆括号</td><td></td></tr><tr><td></td><td><code>.</code></td><td>成员选择(对象)</td><td></td></tr><tr><td></td><td><code>-&gt;</code></td><td>成员选择(指针)</td><td></td></tr><tr><td><strong>2</strong></td><td><code>-</code></td><td>负号运算符</td><td>⬅️(从右到左)</td></tr><tr><td></td><td><code>(类型)</code></td><td>强制类型转换</td><td></td></tr><tr><td></td><td><code>++</code></td><td>自增运算符</td><td></td></tr><tr><td></td><td><code>--</code></td><td>自减运算符</td><td></td></tr><tr><td></td><td><code>*</code></td><td>取值运算符</td><td></td></tr><tr><td></td><td><code>&amp;</code></td><td>取地址运算符</td><td></td></tr><tr><td></td><td><code>!</code></td><td>逻辑非运算符</td><td></td></tr><tr><td></td><td><code>~</code></td><td>按位取反运算符</td><td></td></tr><tr><td></td><td><code>sizeof</code></td><td>长度运算符</td><td></td></tr><tr><td><strong>3</strong></td><td><code>/</code></td><td></td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>*</code></td><td></td><td></td></tr><tr><td></td><td><code>%</code></td><td>余数(取模)</td><td></td></tr><tr><td><strong>4</strong></td><td><code>+</code></td><td></td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>-</code></td><td></td><td></td></tr><tr><td><strong>5</strong></td><td><code>&lt;&lt;</code></td><td>左移</td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>&gt;&gt;</code></td><td>右移</td><td></td></tr><tr><td><strong>6</strong></td><td><code>&gt;</code></td><td>大于</td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>&gt;=</code></td><td>大于等于</td><td></td></tr><tr><td></td><td><code>&lt;</code></td><td>小于</td><td></td></tr><tr><td></td><td><code>&lt;=</code></td><td>小于等于</td><td></td></tr><tr><td><strong>7</strong></td><td><code>==</code></td><td>等于</td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>!=</code></td><td>不等于</td><td></td></tr><tr><td><strong>8</strong></td><td><code>&amp;</code></td><td>按位与</td><td>➡️(从左到右)</td></tr><tr><td><strong>9</strong></td><td><code>^</code></td><td>按位异或</td><td>➡️(从左到右)</td></tr><tr><td><strong>10</strong></td><td><code>|</code></td><td>按位或</td><td>➡️(从左到右)</td></tr><tr><td><strong>11</strong></td><td><code>&amp;&amp;</code></td><td>逻辑与</td><td>➡️(从左到右)</td></tr><tr><td><strong>12</strong></td><td><code>||</code></td><td>逻辑或</td><td>➡️(从左到右)</td></tr><tr><td><strong>13</strong></td><td><code>?:</code></td><td>条件运算符</td><td>⬅️(从右到左)</td></tr><tr><td><strong>14</strong></td><td><code>=</code></td><td>赋值运算符</td><td>⬅️(从右到左)</td></tr><tr><td></td><td><code>/=</code></td><td>除后赋值</td><td></td></tr><tr><td></td><td><code>*=</code></td><td>乘后赋值</td><td></td></tr><tr><td></td><td><code>%=</code></td><td>取模后赋值</td><td></td></tr><tr><td></td><td><code>+=</code></td><td>加后赋值</td><td></td></tr><tr><td></td><td><code>-=</code></td><td>减后赋值</td><td></td></tr><tr><td></td><td><code>&lt;&lt;=</code></td><td>左移后赋值</td><td></td></tr><tr><td></td><td><code>&gt;&gt;=</code></td><td>右移后赋值</td><td></td></tr><tr><td></td><td><code>&amp;=</code></td><td>按位与后赋值</td><td></td></tr><tr><td></td><td><code>^=</code></td><td>按位异或后赋值</td><td></td></tr><tr><td></td><td><code>|=</code></td><td>按位或后赋值</td><td></td></tr><tr><td><strong>15</strong></td><td><code>,</code></td><td>逗号运算符</td><td>➡️(从左到右)</td></tr></tbody></table><div class="warning custom-block github-alert"><p class="custom-block-title">WARNING</p><p></p><ul><li>① 不要过多的依赖运算符的优先级来控制表达式的执行顺序,这样可读性太差,尽量<code>使用小括号来控制</code>表达式的执行顺序。</li><li>② 不要把一个表达式写得过于复杂,如果一个表达式过于复杂,则把它<code>分成几步</code>来完成。</li><li>③ 运算符优先级不用刻意地去记忆,总体上:一元运算符 &gt; 算术运算符 &gt; 关系运算符 &gt; 逻辑运算符 &gt; 三元运算符 &gt; 赋值运算符。</li></ul></div><h1 id="第三章-附录" tabindex="-1">第三章:附录 <a class="header-anchor" href="#第三章-附录" aria-label="Permalink to &quot;第三章:附录&quot;"></a></h1><h2 id="_3-1-字符集和字符集编码" tabindex="-1">3.1 字符集和字符集编码 <a class="header-anchor" href="#_3-1-字符集和字符集编码" aria-label="Permalink to &quot;3.1 字符集和字符集编码&quot;"></a></h2><h3 id="_3-3-1-概述" tabindex="-1">3.3.1 概述 <a class="header-anchor" href="#_3-3-1-概述" aria-label="Permalink to &quot;3.3.1 概述&quot;"></a></h3><ul><li>字符集和字符集编码(简称编码)计算机系统中处理文本数据的两个基本概念,它们密切相关但又有区别。</li><li>字符集Character Set是一组字符的集合其中每个字符都被分配了一个<code>唯一的编号</code>(通常是数字)。字符可以是字母、数字、符号、控制代码(如换行符)等。<code>字符集定义了可以表示的字符的范围</code>,但它并不直接定义如何将这些字符存储在计算机中。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>ASCII美国信息交换标准代码是最早期和最简单的字符集之一它只包括了英文字母、数字和一些特殊字符共 128 个字符。每个字符都分配给了一个从 0 到 127 的数字。</p></div><ul><li>字符集编码Character Encoding简称编码是一种方案或方法<code>它定义了如何将字符集中的字符转换为计算机存储和传输的数据(通常是一串二进制数字)</code>。简而言之,编码是字符到二进制数据之间的映射规则。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>ASCII 编码方案定义了如何将 ASCII 字符集中的每个字符表示为 7 位的二进制数字。例如:大写字母<code>&#39;A&#39;</code>在 ASCII 编码中表示为二进制的<code>1000001</code>,十进制的 <code>65</code></p></div><ul><li><code>字符集</code><code>字符集编码</code>之间的关系如下:</li></ul><p><img src="/c/assets/35.CGTVELeO.png" alt="" loading="lazy"></p><ul><li>Linux 中安装帮助手册:</li></ul><p><img src="/c/assets/36.Bz4_lEH0.gif" alt="" loading="lazy"></p><h3 id="_3-3-2-ascii-编码" tabindex="-1">3.3.2 ASCII 编码 <a class="header-anchor" href="#_3-3-2-ascii-编码" aria-label="Permalink to &quot;3.3.2 ASCII 编码&quot;"></a></h3><ul><li><code>冯·诺依曼</code>体系结构中,我们知道,计算机中所有的<code>数据</code><code>指令</code>都是以<code>二进制</code>的形式表示的;所以,计算机中对于文本数据的数据也是以二进制来存储的,那么对应的流程如下:</li></ul><p><img src="/c/assets/37.CcDWE4nn.png" alt="" loading="lazy"></p><ul><li>我们知道,计算机是上个世纪 60 年代在美国研制成功的,为了实现字符和二进制的转换,美国就制定了一套字符编码,即英语字符和二进制位之间的关系,即 ASCII American Standard Code for Information Interchange编码 <ul><li>ASCII 编码只包括了英文字符、数字和一些特殊字符,一共 128 个字符,并且每个字符都分配了唯一的数字,范围是 0 - 127。</li><li>ASCII 编码中的每个字符都使用 7 位的二进制数字表示;但是,计算机中的存储的最小单位是 1 B = 8 位,那么最高位统一规定为 0 。</li></ul></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 其实,早期是没有字符集的概念的,只是后来为了解决乱码问题,而产生了字符集的概念。</li><li>② 对于英文体系来说,<code>a-zA-Z0-9</code>以及一些<code>特殊字符</code>一共 <code>128</code> 就可以满足实际存储需求;所以,在也是为什么 ASCII 码使用 7 位二进制2^7 = 128 )来存储的。</li></ul></div><ul><li>在操作系统中就内置了对应的编码表Linux 也不例外;可以使用如下的命令查看:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">man</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ascii</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/38.B7y2_JVX.gif" alt="" loading="lazy"></p><ul><li>其对应的 ASCII 编码表,如下所示:</li></ul><p><img src="/c/assets/39.Btcc3rs2.gif" alt="" loading="lazy"></p><ul><li>但是,随着计算机的发展,计算机开始了东征之路,由美国传播到东方:</li></ul><p><img src="/c/assets/40.CR4ARW8y.png" alt="" loading="lazy"></p><ul><li>先是传播到了欧洲,欧洲在兼容 ASCII 编码的基础上,推出了 ISO8859-1 编码,即: <ul><li>ISO8859-1 编码包括基本的拉丁字母表、数字、标点符号,以及西欧语言中特有的一些字符,如:法语中的 <code>è</code>、德语中的 <code>ü</code> 等。</li><li>ISO 8859-1 为每个字符分配一个单字节8 位)编码,意味着它可以表示最多 256 2^8个不同的字符编号从 0 到 255</li><li>ISO 8859-1 的前 128 个字符与 ASCII 编码完全一致,这使得 ASCII 编码的文本可以无缝转换为 ISO 8859-1 编码。</li></ul></li></ul><p><img src="/c/assets/39.Btcc3rs2.gif" alt="" loading="lazy"></p><p><img src="/c/assets/42.DOX3ymYP.gif" alt="" loading="lazy"></p><ul><li>计算机继续传播到了亚洲,亚洲(双字节)各个国家分别给出了自己国家对应的字符集编码,如: <ul><li>日本推出了 Shift-JIS 编码: <ul><li>单字节 ASCII 范围0 - 127。</li><li>双字节范围: <ul><li>第一个字节129 - 159 和 224 - 239 。</li><li>第二个字节64 - 126 和 128 - 252 。</li></ul></li></ul></li><li>韩国推出了 EUC-KR 编码: <ul><li>单字节 ASCII 范围0 - 127。</li><li>双字节范围:从 41281 - 65278。</li></ul></li><li>中国推出了 GBK 编码: <ul><li>单字节 ASCII 范围0 - 127。</li><li>双字节范围33088 - 65278 。</li></ul></li></ul></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 通过上面日本、韩国、中国的编码十进制范围,我们可以看到,虽然这些编码系统在技术上的编码范围存在重叠(特别是在高位字节区域),但因为它们各自支持的字符集完全不同,所以实际上它们并不直接冲突。</li><li>② 但是,如果一个中国人通过 GBK 编码写的文章,通过邮件发送给韩国人,因为韩国和中国在字符集编码上的高位字节有重叠部分,必然会造成歧义。</li></ul></div><h3 id="_3-3-3-unicode-编码" tabindex="-1">3.3.3 Unicode 编码 <a class="header-anchor" href="#_3-3-3-unicode-编码" aria-label="Permalink to &quot;3.3.3 Unicode 编码&quot;"></a></h3><ul><li><p>在 Unicode 之前世界上存在着数百种不同的编码系统每一种编码系统都是为了支持特定语言或一组语言的字符集。这些编码系统包括ASCII、ISO 8859 系列、GBK、Shift-JIS、EUC-KR 等,它们各自有不同的字符范围和编码方式。这种多样性虽然在局部范围内解决了字符表示的问题,但也带来了以下几个方面的挑战:</p><ul><li><code>编码冲突</code>:由于不同的编码系统可以为相同的字节值分配不同的字符,因此在不同编码之间转换文本时,如果没有正确处理编码信息,就很容易产生乱码。这种编码冲突在尝试处理多种语言的文本时尤为突出。</li><li><code>编码的复杂性</code>:随着全球化的发展,软件和系统需要支持越来越多的语言,这就要求开发者和系统同时处理多种不同的编码系统。这不仅增加了开发和维护的复杂性,而且也增加了出错的风险。</li><li><code>资源限制</code>:在早期计算机技术中,内存和存储资源相对有限。不同的编码标准要求系统存储多套字符集数据,这无疑增加了对有限资源的消耗。</li><li>……</li></ul></li><li><p>针对上述的种种问题为了推行全球化Unicode 应运而生Unicode 的核心规则和设计原则是建立一个全球统一的字符集,使得世界上所有的文字和符号都能被唯一地识别和使用,无论使用者位于何地或使用何种语言。这套规则包括了字符的编码、表示、处理和转换机制,旨在确保不同系统和软件间能够无缝交换和处理文本数据。</p><ul><li><code>通用字符集 (UCS)</code>Unicode 为每一个字符分配一个唯一的编号(称为<code>“码点”</code>)。这些码点被组织在一个统一的字符集中,官方称之为 “通用字符集”Universal Character SetUCS。码点通常表示为 <code>U+</code> 后跟一个十六进制数,例如:<code>U+0041</code> 代表大写的英文字母 <code>“A”</code></li><li><code>编码平面和区段</code>Unicode 码点被划分为多个 “平面Planes每个平面包含 6553616^4个码点。目前Unicode定义了 17 个平面(从 0 到16每个平面被分配了一个编号从 “基本多文种平面BMP” 的 0 开始,到 16 号平面结束。这意味着 Unicode 理论上可以支持超过 110万17*65536个码点。</li></ul></li><li><p>Unicode 仅仅只是字符集,给每个字符设置了唯一的数字编号而已,却没有给出这些数字编号实际如何存储,可以通过如下命令查看:</p></li></ul><p><img src="/c/assets/43.Cie9_tkP.gif" alt="" loading="lazy"></p><ul><li>为了在计算机系统中表示 Unicode 字符,定义了几种编码方案,这些方案包括 UTF-8、UTF-16 和 UTF-32 等。 <ul><li><strong>UTF-8</strong>:使用 1 - 4 个字节表示每个 Unicode 字符,兼容 ASCII是网络上最常用的编码。</li><li><strong>UTF-16</strong>:使用 2 - 4 个字节表示每个 Unicode 字符,适合于需要经常处理基本多文种平面之外字符的应用。</li><li><strong>UTF-32</strong>:使用固定的 4 个字节表示每个 Unicode 字符,简化了字符处理,但增加了存储空间的需求。</li></ul></li><li><code>Unicode 字符集</code>和对应的<code>UTF-8 字符编码</code>之间的关系,如下所示:</li></ul><p><img src="/c/assets/44.DLjH9Ges.png" alt="" loading="lazy"></p><h2 id="_3-2-wsl2-中设置默认编码为中文" tabindex="-1">3.2 WSL2 中设置默认编码为中文 <a class="header-anchor" href="#_3-2-wsl2-中设置默认编码为中文" aria-label="Permalink to &quot;3.2 WSL2 中设置默认编码为中文&quot;"></a></h2><h3 id="_3-2-1-概述" tabindex="-1">3.2.1 概述 <a class="header-anchor" href="#_3-2-1-概述" aria-label="Permalink to &quot;3.2.1 概述&quot;"></a></h3><ul><li>查看 WSL2 的 Linux 发行版的默认编码:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $LANG</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/45.DhSh546m.gif" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p><code>C.UTF-8</code> 是一种字符编码设置,结合了 <code>C</code> 区域设定和 <code>UTF-8</code> 字符编码。</p><ul><li><strong>C 区域设定</strong>:这是一个标准的、最小化的区域设置,通常用于系统默认的语言环境。<code>C</code> 区域设定下,所有字符都被认为是 ASCII 字符集的一部分,这意味着仅支持基本的英文字符和符号。在 <code>C</code> 区域设定中,字符串的排序和比较是基于简单的二进制值比较,这与本地化的语言设置相比相对简单。</li><li><strong>UTF-8 编码</strong>UTF-8 是一种变长的字符编码方式,可以编码所有的 Unicode 字符。它是一种广泛使用的字符编码,能够支持多种语言和符号。每个 UTF-8 字符可以由1到4个字节表示这使得它兼容 ASCII对于标准 ASCII 字符UTF-8 只使用一个字节)。</li></ul><p>因此,<code>C.UTF-8</code> 结合了 <code>C</code> 区域设定和 UTF-8 字符编码的优势。使用 <code>C.UTF-8</code> 时,系统默认语言环境保持简单和高效,同时支持更广泛的字符集,特别是多语言和非英语字符。这样可以在需要兼容性的同时,提供对全球化字符的支持。</p></div><h3 id="_3-2-2-almalinux9-设置默认编码" tabindex="-1">3.2.2 AlmaLinux9 设置默认编码 <a class="header-anchor" href="#_3-2-2-almalinux9-设置默认编码" aria-label="Permalink to &quot;3.2.2 AlmaLinux9 设置默认编码&quot;"></a></h3><ul><li>① 搜索中文语言包:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">dnf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> search</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> locale</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> zh</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/46.CCFwxiA0.gif" alt="" loading="lazy"></p><ul><li>② 安装中文语言包:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">dnf</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> glibc-langpack-zh</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/47.DCdP5ufU.gif" alt="" loading="lazy"></p><ul><li>③ 切换语言环境为中文:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">localectl</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> set-locale</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> LANG=zh_CN.UTF-8</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/48.CjdgNuy4.gif" alt="" loading="lazy"></p><ul><li>④ 手动加载配置文件,使其生效:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">source</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /etc/locale.conf</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/49.Bg9sWT0a.gif" alt="" loading="lazy"></p><h3 id="_3-2-3-ubuntu-22-04-设置默认编码" tabindex="-1">3.2.3 Ubuntu 22.04 设置默认编码 <a class="header-anchor" href="#_3-2-3-ubuntu-22-04-设置默认编码" aria-label="Permalink to &quot;3.2.3 Ubuntu 22.04 设置默认编码&quot;"></a></h3><ul><li>① 安装中文语言包:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">apt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> update</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &amp;&amp; </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">apt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> language-pack-zh-hans</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/50.Ma73wRvf.gif" alt="" loading="lazy"></p><ul><li>② 切换环境为中文:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">update-locale</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> LANG=zh_CN.UTF-8</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> LANGUAGE=zh_CN:zh</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/51.rJLsU7Sw.gif" alt="" loading="lazy"></p><ul><li>③ 手动加载配置文件,使其生效:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">source</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /etc/default/locale</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/52.3DsEIiSv.gif" alt="" loading="lazy"></p></div></div></main><footer class="VPDocFooter" data-v-39a288b8 data-v-e257564d><!--[--><!--]--><div class="edit-info" data-v-e257564d><!----><div class="last-updated" data-v-e257564d><p class="VPLastUpdated" data-v-e257564d data-v-e98dd255>上次更新: <time datetime="2024-08-26T08:34:17.000Z" data-v-e98dd255></time></p></div></div><nav class="prev-next" aria-labelledby="doc-footer-aria-label" data-v-e257564d><span class="visually-hidden" id="doc-footer-aria-label" data-v-e257564d>Pager</span><div class="pager" data-v-e257564d><a class="VPLink link pager-link prev" href="/c/notes/01_c-basic/02_xdx/" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>上一篇</span><span class="title" data-v-e257564d>变量和进制</span><!--]--></a></div><div class="pager" data-v-e257564d><a class="VPLink link pager-link next" href="/c/notes/01_c-basic/04_xdx/" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>下一篇</span><span class="title" data-v-e257564d>流程控制</span><!--]--></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><footer class="VPFooter has-sidebar" data-v-5d98c3a5 data-v-e315a0ad><div class="container" data-v-e315a0ad><p class="message" data-v-e315a0ad>Released under the MIT License.</p><p class="copyright" data-v-e315a0ad>Copyright © 2024 许大仙</p></div></footer><!--[--><!--]--></div></div>
<script>window.__VP_HASH_MAP__=JSON.parse("{\"index.md\":\"Dga0tMF5\",\"notes_01_c-basic_00_xdx_index.md\":\"BRC7slaL\",\"notes_01_c-basic_01_xdx_index.md\":\"DvCUr2L0\",\"notes_01_c-basic_02_xdx_index.md\":\"CC2Mg9VD\",\"notes_01_c-basic_03_xdx_index.md\":\"CcATnhKW\",\"notes_01_c-basic_04_xdx_index.md\":\"DABEMZSO\",\"notes_01_c-basic_05_xdx_index.md\":\"CGbN5wss\",\"notes_01_c-basic_06_xdx_index.md\":\"CIGNaKYV\",\"notes_04_linux_01_xdx_index.md\":\"C9IatKsj\",\"notes_about_index.md\":\"DLuQgC_8\",\"notes_index.md\":\"CeV-uJ5V\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"zh-CN\",\"dir\":\"ltr\",\"title\":\"许大仙\",\"titleTemplate\":\"Hi终于等到你\",\"description\":\"许大仙前端、Java、大数据、云原生\",\"base\":\"/c/\",\"head\":[],\"router\":{\"prefetchLinks\":true},\"appearance\":true,\"themeConfig\":{\"lastUpdatedText\":\"上次更新\",\"returnToTopLabel\":\"返回顶部\",\"search\":{\"provider\":\"local\"},\"logo\":\"/logo.svg\",\"nav\":[{\"text\":\"首页\",\"link\":\"https://aexiar.github.io/\"},{\"text\":\"计组6件套\",\"link\":\"https://aexiar.github.io/coa6/notes/\"},{\"text\":\"编程语言\",\"items\":[{\"text\":\"c/c++\",\"link\":\"/notes/\"},{\"text\":\"前端\",\"link\":\"https://aexiar.github.io/web-design/notes/\"},{\"text\":\"Java\",\"link\":\"https://aexiar.github.io/java/notes/\"},{\"text\":\"大数据\",\"link\":\"https://aexiar.github.io/big-data/notes/\"},{\"text\":\"云原生\",\"link\":\"https://aexiar.github.io/linux/notes/\"},{\"text\":\"Go\",\"link\":\"https://aexiar.github.io/go/notes/\"},{\"text\":\"Python\",\"link\":\"https://aexiar.github.io/python/notes/\"}]},{\"text\":\"数据库\",\"link\":\"https://aexiar.github.io/db/notes/\"},{\"text\":\"开源软件\",\"link\":\"https://aexiar.github.io/open-software/notes/\"},{\"text\":\"关于我\",\"link\":\"/notes/about/\"}],\"sidebar\":{\"/notes/\":[{\"text\":\"C 语言基础\",\"collapsed\":true,\"items\":[{\"text\":\"编程基础\",\"link\":\"/notes/01_c-basic/00_xdx/\"},{\"text\":\"C 语言入门\",\"link\":\"/notes/01_c-basic/01_xdx/\"},{\"text\":\"变量和进制\",\"link\":\"/notes/01_c-basic/02_xdx/\"},{\"text\":\"数据类型和运算符\",\"link\":\"/notes/01_c-basic/03_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/01_c-basic/04_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/01_c-basic/05_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/01_c-basic/06_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/01_c-basic/07_xdx/\"},{\"text\":\"预处理器\",\"link\":\"/notes/01_c-basic/08_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/01_c-basic/09_xdx/\"},{\"text\":\"内存管理\",\"link\":\"/notes/01_c-basic/10_xdx/\"},{\"text\":\"文件操作\",\"link\":\"/notes/01_c-basic/11_xdx/\"},{\"text\":\"调试工具和调试技巧gdb和make\",\"link\":\"/notes/02_c-basic/13_xdx/\"},{\"text\":\"常用库函数\",\"link\":\"/notes/01_c-basic/13_xdx/\"}]},{\"text\":\"C 语言高级\",\"collapsed\":true,\"items\":[{\"text\":\"变量和内存分布\",\"link\":\"/notes/02_c-advance/01_xdx/\"},{\"text\":\"指针强化\",\"link\":\"/notes/02_c-advance/02_xdx/\"},{\"text\":\"结构体和文件的高级用法\",\"link\":\"/notes/02_c-advance/03_xdx/\"},{\"text\":\"链表和回调函数\",\"link\":\"/notes/02_c-advance/04_xdx/\"},{\"text\":\"编译过程和面向接口\",\"link\":\"/notes/02_c-advance/05_xdx/\"}]},{\"text\":\"项目构建工具\",\"collapsed\":true,\"items\":[{\"text\":\"meson\",\"collapsed\":true,\"items\":[{\"text\":\"meson 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Cmake\",\"collapsed\":true,\"items\":[{\"text\":\"Cmake 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Conan \",\"link\":\"/notes/03_build/01_${commonDirectoryName}/\"},{\"text\":\"Gradle\",\"collapsed\":true,\"items\":[{\"text\":\"Gradle 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]}]},{\"text\":\"Linux\",\"collapsed\":true,\"items\":[{\"text\":\"Linux 初识和安装\",\"link\":\"/notes/04_linux/01_xdx/\"}]},{\"text\":\"C++ 基础\",\"collapsed\":true,\"items\":[{\"text\":\"C++ 入门\",\"link\":\"/notes/05_cpp/01_xdx/\"},{\"text\":\"变量、数据类型、运算符\",\"link\":\"/notes/05_cpp/02_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/05_cpp/03_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/05_cpp/04_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/05_cpp/05_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/05_cpp/06_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/05_cpp/07_xdx/\"},{\"text\":\"类和对象\",\"link\":\"/notes/05_cpp/08_xdx/\"},{\"text\":\"C++ 引用\",\"link\":\"/notes/05_cpp/09_xdx/\"},{\"text\":\"继承和派生\",\"link\":\"/notes/05_cpp/10_xdx/\"},{\"text\":\"C++ 多态和虚函数\",\"link\":\"/notes/05_cpp/11_xdx/\"},{\"text\":\"运算符重载\",\"link\":\"/notes/05_cpp/12_xdx/\"},{\"text\":\"模板\",\"link\":\"/notes/05_cpp/13_xdx/\"},{\"text\":\"C++ 异常\",\"link\":\"/notes/05_cpp/14_xdx/\"},{\"text\":\"面向对象进阶\",\"link\":\"/notes/05_cpp/15_xdx/\"},{\"text\":\"文件操作和 IO 流\",\"link\":\"/notes/05_cpp/16_xdx/\"},{\"text\":\"STL标准模板库\",\"link\":\"/notes/05_cpp/17_xdx/\"}]},{\"text\":\"C++ 高级\",\"collapsed\":true,\"items\":[]},{\"text\":\"QT 桌面开发\",\"collapsed\":true,\"items\":[]},{\"text\":\"Linux 高并发服务器开发\",\"collapsed\":true,\"items\":[]}]},\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/Aurorxa\"}],\"docFooter\":{\"prev\":\"上一篇\",\"next\":\"下一篇\"},\"darkModeSwitchLabel\":\"深浅模式\",\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2024 许大仙\"},\"outline\":{\"level\":[1,6],\"label\":\"目录\"},\"outlineTitle\":\"当前页大纲\"},\"locales\":{},\"scrollOffset\":134,\"cleanUrls\":false}");</script>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><h2 id="_2-8-运算符优先级" tabindex="-1">2.8 运算符优先级 <a class="header-anchor" href="#_2-8-运算符优先级" aria-label="Permalink to &quot;2.8 运算符优先级&quot;"></a></h2><ul><li>C 语言中运算符的优先级,如下所示:</li></ul><table tabindex="0"><thead><tr><th><strong>优先级</strong></th><th><strong>运算符</strong></th><th><strong>名称或含义</strong></th><th><strong>结合方向</strong></th></tr></thead><tbody><tr><td><strong>1</strong></td><td><code>[]</code></td><td>数组下标</td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>()</code></td><td>圆括号</td><td></td></tr><tr><td></td><td><code>.</code></td><td>成员选择(对象)</td><td></td></tr><tr><td></td><td><code>-&gt;</code></td><td>成员选择(指针)</td><td></td></tr><tr><td><strong>2</strong></td><td><code>-</code></td><td>负号运算符</td><td>⬅️(从右到左)</td></tr><tr><td></td><td><code>(类型)</code></td><td>强制类型转换</td><td></td></tr><tr><td></td><td><code>++</code></td><td>自增运算符</td><td></td></tr><tr><td></td><td><code>--</code></td><td>自减运算符</td><td></td></tr><tr><td></td><td><code>*</code></td><td>取值运算符</td><td></td></tr><tr><td></td><td><code>&amp;</code></td><td>取地址运算符</td><td></td></tr><tr><td></td><td><code>!</code></td><td>逻辑非运算符</td><td></td></tr><tr><td></td><td><code>~</code></td><td>按位取反运算符</td><td></td></tr><tr><td></td><td><code>sizeof</code></td><td>长度运算符</td><td></td></tr><tr><td><strong>3</strong></td><td><code>/</code></td><td></td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>*</code></td><td></td><td></td></tr><tr><td></td><td><code>%</code></td><td>余数(取模)</td><td></td></tr><tr><td><strong>4</strong></td><td><code>+</code></td><td></td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>-</code></td><td></td><td></td></tr><tr><td><strong>5</strong></td><td><code>&lt;&lt;</code></td><td>左移</td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>&gt;&gt;</code></td><td>右移</td><td></td></tr><tr><td><strong>6</strong></td><td><code>&gt;</code></td><td>大于</td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>&gt;=</code></td><td>大于等于</td><td></td></tr><tr><td></td><td><code>&lt;</code></td><td>小于</td><td></td></tr><tr><td></td><td><code>&lt;=</code></td><td>小于等于</td><td></td></tr><tr><td><strong>7</strong></td><td><code>==</code></td><td>等于</td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>!=</code></td><td>不等于</td><td></td></tr><tr><td><strong>8</strong></td><td><code>&amp;</code></td><td>按位与</td><td>➡️(从左到右)</td></tr><tr><td><strong>9</strong></td><td><code>^</code></td><td>按位异或</td><td>➡️(从左到右)</td></tr><tr><td><strong>10</strong></td><td><code>|</code></td><td>按位或</td><td>➡️(从左到右)</td></tr><tr><td><strong>11</strong></td><td><code>&amp;&amp;</code></td><td>逻辑与</td><td>➡️(从左到右)</td></tr><tr><td><strong>12</strong></td><td><code>||</code></td><td>逻辑或</td><td>➡️(从左到右)</td></tr><tr><td><strong>13</strong></td><td><code>?:</code></td><td>条件运算符</td><td>⬅️(从右到左)</td></tr><tr><td><strong>14</strong></td><td><code>=</code></td><td>赋值运算符</td><td>⬅️(从右到左)</td></tr><tr><td></td><td><code>/=</code></td><td>除后赋值</td><td></td></tr><tr><td></td><td><code>*=</code></td><td>乘后赋值</td><td></td></tr><tr><td></td><td><code>%=</code></td><td>取模后赋值</td><td></td></tr><tr><td></td><td><code>+=</code></td><td>加后赋值</td><td></td></tr><tr><td></td><td><code>-=</code></td><td>减后赋值</td><td></td></tr><tr><td></td><td><code>&lt;&lt;=</code></td><td>左移后赋值</td><td></td></tr><tr><td></td><td><code>&gt;&gt;=</code></td><td>右移后赋值</td><td></td></tr><tr><td></td><td><code>&amp;=</code></td><td>按位与后赋值</td><td></td></tr><tr><td></td><td><code>^=</code></td><td>按位异或后赋值</td><td></td></tr><tr><td></td><td><code>|=</code></td><td>按位或后赋值</td><td></td></tr><tr><td><strong>15</strong></td><td><code>,</code></td><td>逗号运算符</td><td>➡️(从左到右)</td></tr></tbody></table><div class="warning custom-block github-alert"><p class="custom-block-title">WARNING</p><p></p><ul><li>① 不要过多的依赖运算符的优先级来控制表达式的执行顺序,这样可读性太差,尽量<code>使用小括号来控制</code>表达式的执行顺序。</li><li>② 不要把一个表达式写得过于复杂,如果一个表达式过于复杂,则把它<code>分成几步</code>来完成。</li><li>③ 运算符优先级不用刻意地去记忆,总体上:一元运算符 &gt; 算术运算符 &gt; 关系运算符 &gt; 逻辑运算符 &gt; 三元运算符 &gt; 赋值运算符。</li></ul></div><h1 id="第三章-附录" tabindex="-1">第三章:附录 <a class="header-anchor" href="#第三章-附录" aria-label="Permalink to &quot;第三章:附录&quot;"></a></h1><h2 id="_3-1-字符集和字符集编码" tabindex="-1">3.1 字符集和字符集编码 <a class="header-anchor" href="#_3-1-字符集和字符集编码" aria-label="Permalink to &quot;3.1 字符集和字符集编码&quot;"></a></h2><h3 id="_3-3-1-概述" tabindex="-1">3.3.1 概述 <a class="header-anchor" href="#_3-3-1-概述" aria-label="Permalink to &quot;3.3.1 概述&quot;"></a></h3><ul><li>字符集和字符集编码(简称编码)计算机系统中处理文本数据的两个基本概念,它们密切相关但又有区别。</li><li>字符集Character Set是一组字符的集合其中每个字符都被分配了一个<code>唯一的编号</code>(通常是数字)。字符可以是字母、数字、符号、控制代码(如换行符)等。<code>字符集定义了可以表示的字符的范围</code>,但它并不直接定义如何将这些字符存储在计算机中。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>ASCII美国信息交换标准代码是最早期和最简单的字符集之一它只包括了英文字母、数字和一些特殊字符共 128 个字符。每个字符都分配给了一个从 0 到 127 的数字。</p></div><ul><li>字符集编码Character Encoding简称编码是一种方案或方法<code>它定义了如何将字符集中的字符转换为计算机存储和传输的数据(通常是一串二进制数字)</code>。简而言之,编码是字符到二进制数据之间的映射规则。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>ASCII 编码方案定义了如何将 ASCII 字符集中的每个字符表示为 7 位的二进制数字。例如:大写字母<code>&#39;A&#39;</code>在 ASCII 编码中表示为二进制的<code>1000001</code>,十进制的 <code>65</code></p></div><ul><li><code>字符集</code><code>字符集编码</code>之间的关系如下:</li></ul><p><img src="/c/assets/35.CGTVELeO.png" alt="" loading="lazy"></p><ul><li>Linux 中安装帮助手册:</li></ul><p><img src="/c/assets/36.Bz4_lEH0.gif" alt="" loading="lazy"></p><h3 id="_3-3-2-ascii-编码" tabindex="-1">3.3.2 ASCII 编码 <a class="header-anchor" href="#_3-3-2-ascii-编码" aria-label="Permalink to &quot;3.3.2 ASCII 编码&quot;"></a></h3><ul><li><code>冯·诺依曼</code>体系结构中,我们知道,计算机中所有的<code>数据</code><code>指令</code>都是以<code>二进制</code>的形式表示的;所以,计算机中对于文本数据的数据也是以二进制来存储的,那么对应的流程如下:</li></ul><p><img src="/c/assets/37.CcDWE4nn.png" alt="" loading="lazy"></p><ul><li>我们知道,计算机是上个世纪 60 年代在美国研制成功的,为了实现字符和二进制的转换,美国就制定了一套字符编码,即英语字符和二进制位之间的关系,即 ASCII American Standard Code for Information Interchange编码 <ul><li>ASCII 编码只包括了英文字符、数字和一些特殊字符,一共 128 个字符,并且每个字符都分配了唯一的数字,范围是 0 - 127。</li><li>ASCII 编码中的每个字符都使用 7 位的二进制数字表示;但是,计算机中的存储的最小单位是 1 B = 8 位,那么最高位统一规定为 0 。</li></ul></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 其实,早期是没有字符集的概念的,只是后来为了解决乱码问题,而产生了字符集的概念。</li><li>② 对于英文体系来说,<code>a-zA-Z0-9</code>以及一些<code>特殊字符</code>一共 <code>128</code> 就可以满足实际存储需求;所以,在也是为什么 ASCII 码使用 7 位二进制2^7 = 128 )来存储的。</li></ul></div><ul><li>在操作系统中就内置了对应的编码表Linux 也不例外;可以使用如下的命令查看:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">man</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ascii</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/38.B7y2_JVX.gif" alt="" loading="lazy"></p><ul><li>其对应的 ASCII 编码表,如下所示:</li></ul><p><img src="/c/assets/39.Btcc3rs2.gif" alt="" loading="lazy"></p><ul><li>但是,随着计算机的发展,计算机开始了东征之路,由美国传播到东方:</li></ul><p><img src="/c/assets/40.CR4ARW8y.png" alt="" loading="lazy"></p><ul><li>先是传播到了欧洲,欧洲在兼容 ASCII 编码的基础上,推出了 ISO8859-1 编码,即: <ul><li>ISO8859-1 编码包括基本的拉丁字母表、数字、标点符号,以及西欧语言中特有的一些字符,如:法语中的 <code>è</code>、德语中的 <code>ü</code> 等。</li><li>ISO 8859-1 为每个字符分配一个单字节8 位)编码,意味着它可以表示最多 256 2^8个不同的字符编号从 0 到 255</li><li>ISO 8859-1 的前 128 个字符与 ASCII 编码完全一致,这使得 ASCII 编码的文本可以无缝转换为 ISO 8859-1 编码。</li></ul></li></ul><p><img src="/c/assets/39.Btcc3rs2.gif" alt="" loading="lazy"></p><p><img src="/c/assets/42.DOX3ymYP.gif" alt="" loading="lazy"></p><ul><li>计算机继续传播到了亚洲,亚洲(双字节)各个国家分别给出了自己国家对应的字符集编码,如: <ul><li>日本推出了 Shift-JIS 编码: <ul><li>单字节 ASCII 范围0 - 127。</li><li>双字节范围: <ul><li>第一个字节129 - 159 和 224 - 239 。</li><li>第二个字节64 - 126 和 128 - 252 。</li></ul></li></ul></li><li>韩国推出了 EUC-KR 编码: <ul><li>单字节 ASCII 范围0 - 127。</li><li>双字节范围:从 41281 - 65278。</li></ul></li><li>中国推出了 GBK 编码: <ul><li>单字节 ASCII 范围0 - 127。</li><li>双字节范围33088 - 65278 。</li></ul></li></ul></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 通过上面日本、韩国、中国的编码十进制范围,我们可以看到,虽然这些编码系统在技术上的编码范围存在重叠(特别是在高位字节区域),但因为它们各自支持的字符集完全不同,所以实际上它们并不直接冲突。</li><li>② 但是,如果一个中国人通过 GBK 编码写的文章,通过邮件发送给韩国人,因为韩国和中国在字符集编码上的高位字节有重叠部分,必然会造成歧义。</li></ul></div><h3 id="_3-3-3-unicode-编码" tabindex="-1">3.3.3 Unicode 编码 <a class="header-anchor" href="#_3-3-3-unicode-编码" aria-label="Permalink to &quot;3.3.3 Unicode 编码&quot;"></a></h3><ul><li><p>在 Unicode 之前世界上存在着数百种不同的编码系统每一种编码系统都是为了支持特定语言或一组语言的字符集。这些编码系统包括ASCII、ISO 8859 系列、GBK、Shift-JIS、EUC-KR 等,它们各自有不同的字符范围和编码方式。这种多样性虽然在局部范围内解决了字符表示的问题,但也带来了以下几个方面的挑战:</p><ul><li><code>编码冲突</code>:由于不同的编码系统可以为相同的字节值分配不同的字符,因此在不同编码之间转换文本时,如果没有正确处理编码信息,就很容易产生乱码。这种编码冲突在尝试处理多种语言的文本时尤为突出。</li><li><code>编码的复杂性</code>:随着全球化的发展,软件和系统需要支持越来越多的语言,这就要求开发者和系统同时处理多种不同的编码系统。这不仅增加了开发和维护的复杂性,而且也增加了出错的风险。</li><li><code>资源限制</code>:在早期计算机技术中,内存和存储资源相对有限。不同的编码标准要求系统存储多套字符集数据,这无疑增加了对有限资源的消耗。</li><li>……</li></ul></li><li><p>针对上述的种种问题为了推行全球化Unicode 应运而生Unicode 的核心规则和设计原则是建立一个全球统一的字符集,使得世界上所有的文字和符号都能被唯一地识别和使用,无论使用者位于何地或使用何种语言。这套规则包括了字符的编码、表示、处理和转换机制,旨在确保不同系统和软件间能够无缝交换和处理文本数据。</p><ul><li><code>通用字符集 (UCS)</code>Unicode 为每一个字符分配一个唯一的编号(称为<code>“码点”</code>)。这些码点被组织在一个统一的字符集中,官方称之为 “通用字符集”Universal Character SetUCS。码点通常表示为 <code>U+</code> 后跟一个十六进制数,例如:<code>U+0041</code> 代表大写的英文字母 <code>“A”</code></li><li><code>编码平面和区段</code>Unicode 码点被划分为多个 “平面Planes每个平面包含 6553616^4个码点。目前Unicode定义了 17 个平面(从 0 到16每个平面被分配了一个编号从 “基本多文种平面BMP” 的 0 开始,到 16 号平面结束。这意味着 Unicode 理论上可以支持超过 110万17*65536个码点。</li></ul></li><li><p>Unicode 仅仅只是字符集,给每个字符设置了唯一的数字编号而已,却没有给出这些数字编号实际如何存储,可以通过如下命令查看:</p></li></ul><p><img src="/c/assets/43.Cie9_tkP.gif" alt="" loading="lazy"></p><ul><li>为了在计算机系统中表示 Unicode 字符,定义了几种编码方案,这些方案包括 UTF-8、UTF-16 和 UTF-32 等。 <ul><li><strong>UTF-8</strong>:使用 1 - 4 个字节表示每个 Unicode 字符,兼容 ASCII是网络上最常用的编码。</li><li><strong>UTF-16</strong>:使用 2 - 4 个字节表示每个 Unicode 字符,适合于需要经常处理基本多文种平面之外字符的应用。</li><li><strong>UTF-32</strong>:使用固定的 4 个字节表示每个 Unicode 字符,简化了字符处理,但增加了存储空间的需求。</li></ul></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 只有 UTF-8 兼容 ASCIIUTF-32 和 UTF-16 都不兼容 ASCII因为它们没有单字节编码。 <ul><li>UTF-8 使用尽量少的字节来存储一个字符不但能够节省存储空间而且在网络传输时也能节省流量所以很多纯文本类型的文件各种编程语言的源文件、各种日志文件和配置文件等以及绝大多数的网页百度、新浪、163 等都采用 UTF-8 编码。但是UTF-8 的缺点是效率低,不但在存储和读取时都要经过转换,而且在处理字符串时也非常麻烦。例如:要在一个 UTF-8 编码的字符串中找到第 10 个字符,就得从头开始一个一个地检索字符,这是一个很耗时的过程,因为 UTF-8 编码的字符串中每个字符占用的字节数不一样,如果不从头遍历每个字符,就不知道第 10 个字符位于第几个字节处就无法定位。不过随着算法的逐年精进UTF-8 字符串的定位效率也越来越高了,往往不再是槽点了。</li><li>UTF-32 是“以空间换效率”,正好弥补了 UTF-8 的缺点UTF-32 的优势就是效率高UTF-32 在存储和读取字符时不需要任何转换,在处理字符串时也能最快速地定位字符。例如:在一个 UTF-32 编码的字符串中查找第 10 个字符,很容易计算出它位于第 37 个字节处直接获取就行不用再逐个遍历字符了没有比这更快的定位字符的方法了。但是UTF-32 的缺点也很明显,就是太占用存储空间了,在网络传输时也会消耗很多流量。我们平常使用的字符编码值一般都比较小,用一两个字节存储足以,用四个字节简直是暴殄天物,甚至说是不能容忍的,所以 UTF-32 在应用上不如 UTF-8 和 UTF-16 广泛。</li><li>UTF-16 可以看做是 UTF-8 和 UTF-32 的折中方案,它平衡了存储空间和处理效率的矛盾。对于常用的字符,用两个字节存储足以,这个时候 UTF-16 是不需要转换的,直接存储字符的编码值即可。</li></ul></li><li>② 总而言之,<strong>UTF-8</strong> 编码兼容性强,适合大多数应用,特别是英文文本处理。<strong>UTF-16</strong> 编码适合处理大量亚洲字符,但在处理英文或其他拉丁字符时相对浪费空间。<strong>UTF-32</strong>编码简单直接,但非常浪费空间,适合需要固定字符宽度的特殊场景。</li><li>③ 在实际应用中UTF-8 通常是最常用的编码方式,因为它在兼容性和空间效率之间提供了良好的平衡。</li><li>④ Windows 内核、.NET Framework、Java String 内部采用的都是 <code>UTF-16</code> 编码,主要原因是为了在兼顾字符处理效率的同时,能够有效处理多种语言的字符集,即:历史遗留问题、兼容性要求和多语言支持的需要。</li><li>⑤ 不过UNIX 家族的操作系统Linux、Mac OS、iOS 等)内核都采用 <code>UTF-8</code> 编码,主要是为了兼容性和灵活性,因为 UTF-8 编码可以无缝处理 ASCII 字符,同时也能够支持多字节的 Unicode 字符,即:为了最大限度地兼容 ASCII同时保持系统的简单性、灵活性和效率。</li></ul></div><ul><li><code>Unicode 字符集</code>和对应的<code>UTF-8 字符编码</code>之间的关系,如下所示:</li></ul><p><img src="/c/assets/44.DLjH9Ges.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p><code>宽字符</code><code>窄字符</code>是编程和计算机系统中对字符类型的一种分类,主要用于描述字符在内存中的表示形式及其与编码方式的关系。</p><ul><li><code>窄字符</code>通常指使用单个字节8 位)来表示的字符。在许多传统的编码系统中,窄字符通常代表 ASCII 字符或其它单字节字符集中的字符。换言之,<code>窄字符</code>适合处理简单的单字节字符集ASCII适用于处理西方语言的应用。</li><li><code>宽字符</code>指使用多个字节(通常是两个或更多)来表示的字符。这些字符通常用于表示比 ASCII 范围更广的字符集,如 Unicode 字符。换言之,<code>宽字符</code>适合处理多字节字符集UTF-32、UTF-16 等,适用于需要处理多种语言和符号的国际化应用。</li></ul><p>在现代编程中,<code>窄字符</code>通常与 <code>UTF-8</code> 编码关联,特别是在处理文本输入、输出和网络传输时。尽管 <code>UTF-8</code> 是变长编码,由于其高效的空间利用和对 <code>ASCII</code> 的优化,通常与<code>窄字符</code>概念关联。而<code>宽字符</code>通常与 <code>UTF-16</code> 编码或 <code>UTF-32</code>编码关联,这些编码使用更大的固定或半固定长度来表示字符,适合处理更大的字符集。</p></div><h2 id="_3-2-wsl2-中设置默认编码为中文" tabindex="-1">3.2 WSL2 中设置默认编码为中文 <a class="header-anchor" href="#_3-2-wsl2-中设置默认编码为中文" aria-label="Permalink to &quot;3.2 WSL2 中设置默认编码为中文&quot;"></a></h2><h3 id="_3-2-1-概述" tabindex="-1">3.2.1 概述 <a class="header-anchor" href="#_3-2-1-概述" aria-label="Permalink to &quot;3.2.1 概述&quot;"></a></h3><ul><li>查看 WSL2 的 Linux 发行版的默认编码:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $LANG</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/45.DhSh546m.gif" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p><code>C.UTF-8</code> 是一种字符编码设置,结合了 <code>C</code> 区域设定和 <code>UTF-8</code> 字符编码。</p><ul><li><strong>C 区域设定</strong>:这是一个标准的、最小化的区域设置,通常用于系统默认的语言环境。<code>C</code> 区域设定下,所有字符都被认为是 ASCII 字符集的一部分,这意味着仅支持基本的英文字符和符号。在 <code>C</code> 区域设定中,字符串的排序和比较是基于简单的二进制值比较,这与本地化的语言设置相比相对简单。</li><li><strong>UTF-8 编码</strong>UTF-8 是一种变长的字符编码方式,可以编码所有的 Unicode 字符。它是一种广泛使用的字符编码,能够支持多种语言和符号。每个 UTF-8 字符可以由1到4个字节表示这使得它兼容 ASCII对于标准 ASCII 字符UTF-8 只使用一个字节)。</li></ul><p>因此,<code>C.UTF-8</code> 结合了 <code>C</code> 区域设定和 UTF-8 字符编码的优势。使用 <code>C.UTF-8</code> 时,系统默认语言环境保持简单和高效,同时支持更广泛的字符集,特别是多语言和非英语字符。这样可以在需要兼容性的同时,提供对全球化字符的支持。</p></div><h3 id="_3-2-2-almalinux9-设置默认编码" tabindex="-1">3.2.2 AlmaLinux9 设置默认编码 <a class="header-anchor" href="#_3-2-2-almalinux9-设置默认编码" aria-label="Permalink to &quot;3.2.2 AlmaLinux9 设置默认编码&quot;"></a></h3><ul><li>① 搜索中文语言包:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">dnf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> search</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> locale</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> zh</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/46.CCFwxiA0.gif" alt="" loading="lazy"></p><ul><li>② 安装中文语言包:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">dnf</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> glibc-langpack-zh</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/47.DCdP5ufU.gif" alt="" loading="lazy"></p><ul><li>③ 切换语言环境为中文:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">localectl</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> set-locale</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> LANG=zh_CN.UTF-8</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/48.CjdgNuy4.gif" alt="" loading="lazy"></p><ul><li>④ 手动加载配置文件,使其生效:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">source</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /etc/locale.conf</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/49.Bg9sWT0a.gif" alt="" loading="lazy"></p><h3 id="_3-2-3-ubuntu-22-04-设置默认编码" tabindex="-1">3.2.3 Ubuntu 22.04 设置默认编码 <a class="header-anchor" href="#_3-2-3-ubuntu-22-04-设置默认编码" aria-label="Permalink to &quot;3.2.3 Ubuntu 22.04 设置默认编码&quot;"></a></h3><ul><li>① 安装中文语言包:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">apt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> update</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &amp;&amp; </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">apt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> language-pack-zh-hans</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/50.Ma73wRvf.gif" alt="" loading="lazy"></p><ul><li>② 切换环境为中文:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">update-locale</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> LANG=zh_CN.UTF-8</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> LANGUAGE=zh_CN:zh</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/51.rJLsU7Sw.gif" alt="" loading="lazy"></p><ul><li>③ 手动加载配置文件,使其生效:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">source</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /etc/default/locale</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/c/assets/52.3DsEIiSv.gif" alt="" loading="lazy"></p></div></div></main><footer class="VPDocFooter" data-v-39a288b8 data-v-e257564d><!--[--><!--]--><div class="edit-info" data-v-e257564d><!----><div class="last-updated" data-v-e257564d><p class="VPLastUpdated" data-v-e257564d data-v-e98dd255>上次更新: <time datetime="2024-08-27T03:11:14.000Z" data-v-e98dd255></time></p></div></div><nav class="prev-next" aria-labelledby="doc-footer-aria-label" data-v-e257564d><span class="visually-hidden" id="doc-footer-aria-label" data-v-e257564d>Pager</span><div class="pager" data-v-e257564d><a class="VPLink link pager-link prev" href="/c/notes/01_c-basic/02_xdx/" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>上一篇</span><span class="title" data-v-e257564d>变量和进制</span><!--]--></a></div><div class="pager" data-v-e257564d><a class="VPLink link pager-link next" href="/c/notes/01_c-basic/04_xdx/" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>下一篇</span><span class="title" data-v-e257564d>大话小数</span><!--]--></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><footer class="VPFooter has-sidebar" data-v-5d98c3a5 data-v-e315a0ad><div class="container" data-v-e315a0ad><p class="message" data-v-e315a0ad>Released under the MIT License.</p><p class="copyright" data-v-e315a0ad>Copyright © 2024 许大仙</p></div></footer><!--[--><!--]--></div></div>
<script>window.__VP_HASH_MAP__=JSON.parse("{\"index.md\":\"Dga0tMF5\",\"notes_01_c-basic_00_xdx_index.md\":\"BRC7slaL\",\"notes_01_c-basic_01_xdx_index.md\":\"Fg4OXydV\",\"notes_01_c-basic_02_xdx_index.md\":\"CC2Mg9VD\",\"notes_01_c-basic_03_xdx_index.md\":\"Cw3Z19MO\",\"notes_01_c-basic_04_xdx_index.md\":\"ySxH8sG-\",\"notes_01_c-basic_05_xdx_index.md\":\"DUbOwEts\",\"notes_01_c-basic_06_xdx_index.md\":\"CV_r2WNu\",\"notes_01_c-basic_07_xdx_index.md\":\"CE9q5cmu\",\"notes_04_linux_01_xdx_index.md\":\"C9IatKsj\",\"notes_about_index.md\":\"DLuQgC_8\",\"notes_index.md\":\"CeV-uJ5V\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"zh-CN\",\"dir\":\"ltr\",\"title\":\"许大仙\",\"titleTemplate\":\"Hi终于等到你\",\"description\":\"许大仙前端、Java、大数据、云原生\",\"base\":\"/c/\",\"head\":[],\"router\":{\"prefetchLinks\":true},\"appearance\":true,\"themeConfig\":{\"lastUpdatedText\":\"上次更新\",\"returnToTopLabel\":\"返回顶部\",\"search\":{\"provider\":\"local\"},\"logo\":\"/logo.svg\",\"nav\":[{\"text\":\"首页\",\"link\":\"https://aexiar.github.io/\"},{\"text\":\"计组6件套\",\"link\":\"https://aexiar.github.io/coa6/notes/\"},{\"text\":\"编程语言\",\"items\":[{\"text\":\"c/c++\",\"link\":\"/notes/\"},{\"text\":\"前端\",\"link\":\"https://aexiar.github.io/web-design/notes/\"},{\"text\":\"Java\",\"link\":\"https://aexiar.github.io/java/notes/\"},{\"text\":\"大数据\",\"link\":\"https://aexiar.github.io/big-data/notes/\"},{\"text\":\"云原生\",\"link\":\"https://aexiar.github.io/linux/notes/\"},{\"text\":\"Go\",\"link\":\"https://aexiar.github.io/go/notes/\"},{\"text\":\"Python\",\"link\":\"https://aexiar.github.io/python/notes/\"}]},{\"text\":\"数据库\",\"link\":\"https://aexiar.github.io/db/notes/\"},{\"text\":\"开源软件\",\"link\":\"https://aexiar.github.io/open-software/notes/\"},{\"text\":\"关于我\",\"link\":\"/notes/about/\"}],\"sidebar\":{\"/notes/\":[{\"text\":\"C 语言基础\",\"collapsed\":true,\"items\":[{\"text\":\"编程基础\",\"link\":\"/notes/01_c-basic/00_xdx/\"},{\"text\":\"C 语言入门\",\"link\":\"/notes/01_c-basic/01_xdx/\"},{\"text\":\"变量和进制\",\"link\":\"/notes/01_c-basic/02_xdx/\"},{\"text\":\"数据类型和运算符\",\"link\":\"/notes/01_c-basic/03_xdx/\"},{\"text\":\"大话小数\",\"link\":\"/notes/01_c-basic/04_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/01_c-basic/05_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/01_c-basic/06_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/01_c-basic/07_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/01_c-basic/08_xdx/\"},{\"text\":\"预处理器\",\"link\":\"/notes/01_c-basic/09_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/01_c-basic/10_xdx/\"},{\"text\":\"内存管理\",\"link\":\"/notes/01_c-basic/11_xdx/\"},{\"text\":\"文件操作\",\"link\":\"/notes/01_c-basic/12_xdx/\"},{\"text\":\"调试工具和调试技巧gdb和make\",\"link\":\"/notes/02_c-basic/13_xdx/\"},{\"text\":\"常用库函数\",\"link\":\"/notes/01_c-basic/14_xdx/\"}]},{\"text\":\"C 语言高级\",\"collapsed\":true,\"items\":[{\"text\":\"变量和内存分布\",\"link\":\"/notes/02_c-advance/01_xdx/\"},{\"text\":\"指针强化\",\"link\":\"/notes/02_c-advance/02_xdx/\"},{\"text\":\"结构体和文件的高级用法\",\"link\":\"/notes/02_c-advance/03_xdx/\"},{\"text\":\"链表和回调函数\",\"link\":\"/notes/02_c-advance/04_xdx/\"},{\"text\":\"编译过程和面向接口\",\"link\":\"/notes/02_c-advance/05_xdx/\"}]},{\"text\":\"项目构建工具\",\"collapsed\":true,\"items\":[{\"text\":\"meson\",\"collapsed\":true,\"items\":[{\"text\":\"meson 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Cmake\",\"collapsed\":true,\"items\":[{\"text\":\"Cmake 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Conan \",\"link\":\"/notes/03_build/01_${commonDirectoryName}/\"},{\"text\":\"Gradle\",\"collapsed\":true,\"items\":[{\"text\":\"Gradle 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]}]},{\"text\":\"Linux\",\"collapsed\":true,\"items\":[{\"text\":\"Linux 初识和安装\",\"link\":\"/notes/04_linux/01_xdx/\"}]},{\"text\":\"C++ 基础\",\"collapsed\":true,\"items\":[{\"text\":\"C++ 入门\",\"link\":\"/notes/05_cpp/01_xdx/\"},{\"text\":\"变量、数据类型、运算符\",\"link\":\"/notes/05_cpp/02_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/05_cpp/03_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/05_cpp/04_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/05_cpp/05_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/05_cpp/06_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/05_cpp/07_xdx/\"},{\"text\":\"类和对象\",\"link\":\"/notes/05_cpp/08_xdx/\"},{\"text\":\"C++ 引用\",\"link\":\"/notes/05_cpp/09_xdx/\"},{\"text\":\"继承和派生\",\"link\":\"/notes/05_cpp/10_xdx/\"},{\"text\":\"C++ 多态和虚函数\",\"link\":\"/notes/05_cpp/11_xdx/\"},{\"text\":\"运算符重载\",\"link\":\"/notes/05_cpp/12_xdx/\"},{\"text\":\"模板\",\"link\":\"/notes/05_cpp/13_xdx/\"},{\"text\":\"C++ 异常\",\"link\":\"/notes/05_cpp/14_xdx/\"},{\"text\":\"面向对象进阶\",\"link\":\"/notes/05_cpp/15_xdx/\"},{\"text\":\"文件操作和 IO 流\",\"link\":\"/notes/05_cpp/16_xdx/\"},{\"text\":\"STL标准模板库\",\"link\":\"/notes/05_cpp/17_xdx/\"}]},{\"text\":\"C++ 高级\",\"collapsed\":true,\"items\":[]},{\"text\":\"QT 桌面开发\",\"collapsed\":true,\"items\":[]},{\"text\":\"Linux 高并发服务器开发\",\"collapsed\":true,\"items\":[]}]},\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/Aurorxa\"}],\"docFooter\":{\"prev\":\"上一篇\",\"next\":\"下一篇\"},\"darkModeSwitchLabel\":\"深浅模式\",\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2024 许大仙\"},\"outline\":{\"level\":[1,6],\"label\":\"目录\"},\"outlineTitle\":\"当前页大纲\"},\"locales\":{},\"scrollOffset\":134,\"cleanUrls\":false}");</script>
</body>
</html>

View File

@ -3,16 +3,16 @@
<head>
<meta charset="utf-8">
<title>第一章:概述 | Hi终于等到你</title>
<title>许大仙 | Hi终于等到你</title>
<meta name="description" content="许大仙前端、Java、大数据、云原生">
<meta name="generator" content="VitePress v1.3.3">
<link rel="preload stylesheet" href="/c/assets/style.zDJ0OJGU.css" as="style">
<script type="module" src="/c/assets/app.Ca2FOFw4.js"></script>
<script type="module" src="/c/assets/app.1a4d5P-6.js"></script>
<link rel="preload" href="/c/assets/inter-roman-latin.Di8DUHzh.woff2" as="font" type="font/woff2" crossorigin="">
<link rel="modulepreload" href="/c/assets/chunks/theme.C6fZfLtk.js">
<link rel="modulepreload" href="/c/assets/chunks/theme.Ddh-lpYV.js">
<link rel="modulepreload" href="/c/assets/chunks/framework.hMCIpNYY.js">
<link rel="modulepreload" href="/c/assets/notes_01_c-basic_04_xdx_index.md.DABEMZSO.lean.js">
<link rel="modulepreload" href="/c/assets/notes_01_c-basic_04_xdx_index.md.ySxH8sG-.lean.js">
<link rel="shortcut icon" href="/c//logo.svg">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="">
<script id="register-sw">"serviceWorker"in navigator&&navigator.serviceWorker.register("/sw.js");</script>
@ -22,759 +22,8 @@
<script id="check-mac-os">document.documentElement.classList.toggle("mac",/Mac|iPhone|iPod|iPad/i.test(navigator.platform));</script>
</head>
<body>
<div id="app"><div class="Layout" data-v-5d98c3a5><!--[--><!--]--><!--[--><span tabindex="-1" data-v-0f60ec36></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-0f60ec36> Skip to content </a><!--]--><!----><header class="VPNav" data-v-5d98c3a5 data-v-ae24b3ad><div class="VPNavBar has-sidebar top" data-v-ae24b3ad data-v-6aa21345><div class="wrapper" data-v-6aa21345><div class="container" data-v-6aa21345><div class="title" data-v-6aa21345><div class="VPNavBarTitle has-sidebar" data-v-6aa21345 data-v-ab179fa1><a class="title" href="/c/" data-v-ab179fa1><!--[--><!--]--><!--[--><img class="VPImage logo" src="/c/logo.svg" alt data-v-8426fc1a><!--]--><span data-v-ab179fa1>许大仙</span><!--[--><!--]--></a></div></div><div class="content" data-v-6aa21345><div class="content-body" data-v-6aa21345><!--[--><!--]--><div class="VPNavBarSearch search" data-v-6aa21345><!--[--><!----><div id="local-search"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><span class="vp-icon DocSearch-Search-Icon"></span><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key">K</kbd></span></button></div><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-6aa21345 data-v-dc692963><span id="main-nav-aria-label" class="visually-hidden" data-v-dc692963> Main Navigation </span><!--[--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>首页</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/coa6/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>计组6件套</span><!--]--></a><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-dc692963 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-b6c34ac9><span class="text" data-v-b6c34ac9><!----><span data-v-b6c34ac9>编程语言</span><span class="vpi-chevron-down text-icon" data-v-b6c34ac9></span></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><div class="items" data-v-b98bc113><!--[--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link" href="/c/notes/" data-v-43f1e123><!--[-->c/c++<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/web-design/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->前端<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/java/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Java<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/big-data/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->大数据<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/linux/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->云原生<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/go/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Go<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/python/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Python<!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/db/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>数据库</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/open-software/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>开源软件</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/c/notes/about/" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>关于我</span><!--]--></a><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-6aa21345 data-v-6c893767><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-6c893767 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-6aa21345 data-v-0394ad82 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-6aa21345 data-v-bb2aa2f0 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-b6c34ac9><span class="vpi-more-horizontal icon" data-v-b6c34ac9></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><!----><!--[--><!--[--><!----><div class="group" data-v-bb2aa2f0><div class="item appearance" data-v-bb2aa2f0><p class="label" data-v-bb2aa2f0>深浅模式</p><div class="appearance-action" data-v-bb2aa2f0><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-bb2aa2f0 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div></div></div><div class="group" data-v-bb2aa2f0><div class="item social-links" data-v-bb2aa2f0><div class="VPSocialLinks social-links-list" data-v-bb2aa2f0 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div></div></div><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-6aa21345 data-v-e5dd9c1c><span class="container" data-v-e5dd9c1c><span class="top" data-v-e5dd9c1c></span><span class="middle" data-v-e5dd9c1c></span><span class="bottom" data-v-e5dd9c1c></span></span></button></div></div></div></div><div class="divider" data-v-6aa21345><div class="divider-line" data-v-6aa21345></div></div></div><!----></header><div class="VPLocalNav has-sidebar empty" data-v-5d98c3a5 data-v-a6f0e41e><div class="container" data-v-a6f0e41e><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-a6f0e41e><span class="vpi-align-left menu-icon" data-v-a6f0e41e></span><span class="menu-text" data-v-a6f0e41e>Menu</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-a6f0e41e data-v-17a5e62e><button data-v-17a5e62e>返回顶部</button><!----></div></div></div><aside class="VPSidebar" data-v-5d98c3a5 data-v-319d5ca6><div class="curtain" data-v-319d5ca6></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-319d5ca6><span class="visually-hidden" id="sidebar-aria-label" data-v-319d5ca6> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible has-active" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/00_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编程基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C 语言入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和进制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数据类型和运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>预处理器</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>内存管理</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-basic/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>调试工具和调试技巧gdb和make</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>常用库函数</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言高级</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和内存分布</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针强化</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>结构体和文件的高级用法</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>链表和回调函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编译过程和面向接口</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>项目构建工具</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>meson</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>meson 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Cmake</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Cmake 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_${commonDirectoryName}/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Conan </p><!--]--></a><!----></div><!----></div><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Gradle</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Gradle 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>Linux</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/04_linux/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Linux 初识和安装</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C++ 基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量、数据类型、运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>类和对象</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 引用</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>继承和派生</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 多态和虚函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/12_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>运算符重载</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>模板</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/14_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 异常</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/15_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>面向对象进阶</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/16_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作和 IO 流</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/17_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>STL标准模板库</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>C++ 高级</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>QT 桌面开发</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>Linux 高并发服务器开发</p><!----></div><!----></div></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-5d98c3a5 data-v-1428d186><div class="VPDoc has-sidebar has-aside" data-v-1428d186 data-v-39a288b8><!--[--><!--]--><div class="container" data-v-39a288b8><div class="aside" data-v-39a288b8><div class="aside-curtain" data-v-39a288b8></div><div class="aside-container" data-v-39a288b8><div class="aside-content" data-v-39a288b8><div class="VPDocAside" data-v-39a288b8 data-v-3f215769><!--[--><!--]--><!--[--><!--]--><nav aria-labelledby="doc-outline-aria-label" class="VPDocAsideOutline" data-v-3f215769 data-v-a5bbad30><div class="content" data-v-a5bbad30><div class="outline-marker" data-v-a5bbad30></div><div aria-level="2" class="outline-title" id="doc-outline-aria-label" role="heading" data-v-a5bbad30>目录</div><ul class="VPDocOutlineItem root" data-v-a5bbad30 data-v-b933a997><!--[--><!--]--></ul></div></nav><!--[--><!--]--><div class="spacer" data-v-3f215769></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-39a288b8><div class="content-container" data-v-39a288b8><!--[--><!--]--><main class="main" data-v-39a288b8><div style="position:relative;" class="vp-doc _c_notes_01_c-basic_04_xdx_" data-v-39a288b8><div><h1 id="第一章-概述" tabindex="-1">第一章:概述 <a class="header-anchor" href="#第一章-概述" aria-label="Permalink to &quot;第一章:概述&quot;"></a></h1><ul><li><p><code>流程控制结构</code>是用来控制程序中<code>各语句执行顺序</code>的语句,并且可以将语句组合成能<code>完成一定功能</code><code>小逻辑模块</code></p></li><li><p>在程序设计中规定了<code>三种</code>流程结构,如下所示:</p><ul><li><code>顺序结构</code>:程序从上到下逐行执行,中间没有任何判断和跳转。</li><li><code>分支结构</code>:根据条件,有选择的执行某段代码。在 C 语言中,有 <code>if...else</code><code>switch...case</code> 两种分支语句。</li><li><code>循环结构</code>:根据循环条件,重复性的执行某段代码。在 C 语言中,有 <code>for</code><code>while</code><code>do...while</code> 三种循环结构。</li></ul></li><li><p>在生活中的<code>洗衣工厂</code>,就包含了上述的三种流程结构,如下所示:</p></li></ul><p><img src="/c/assets/1.CTMA-Poz.jpg" alt="" loading="lazy"></p><h1 id="第二章-顺序结构" tabindex="-1">第二章:顺序结构 <a class="header-anchor" href="#第二章-顺序结构" aria-label="Permalink to &quot;第二章:顺序结构&quot;"></a></h1><h2 id="_2-1-概述" tabindex="-1">2.1 概述 <a class="header-anchor" href="#_2-1-概述" aria-label="Permalink to &quot;2.1 概述&quot;"></a></h2><ul><li>程序从上到下逐行地执行,表达式语句都是顺序执行的,并且上一行对某个变量的修改对下一行会产生影响。</li></ul><p><img src="/c/assets/2.B2g4y1OY.png" alt="" loading="lazy"></p><h2 id="_2-2-应用示例" tabindex="-1">2.2 应用示例 <a class="header-anchor" href="#_2-2-应用示例" aria-label="Permalink to &quot;2.2 应用示例&quot;"></a></h2><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> x </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> y </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;x = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, x);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // x = 1</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;y = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, y);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // y = 2</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 对 x 和 y 的值进行修改</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> x</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> y </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> x </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> y;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> x </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> x </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;x = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, x);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // x = 20</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;y = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, y);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // y = 6</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br></div></div><h1 id="第三章-分支结构-⭐" tabindex="-1">第三章:分支结构(⭐) <a class="header-anchor" href="#第三章-分支结构-⭐" aria-label="Permalink to &quot;第三章:分支结构(⭐)&quot;"></a></h1><h2 id="_3-1-概述" tabindex="-1">3.1 概述 <a class="header-anchor" href="#_3-1-概述" aria-label="Permalink to &quot;3.1 概述&quot;"></a></h2><ul><li>根据特定条件执行不同的代码块,从而实现灵活的程序控制和更复杂的逻辑。</li></ul><h2 id="_3-2-单分支结构" tabindex="-1">3.2 单分支结构 <a class="header-anchor" href="#_3-2-单分支结构" aria-label="Permalink to &quot;3.2 单分支结构&quot;"></a></h2><h3 id="_3-2-1-概述" tabindex="-1">3.2.1 概述 <a class="header-anchor" href="#_3-2-1-概述" aria-label="Permalink to &quot;3.2.1 概述&quot;"></a></h3><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(条件表达式){</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 语句;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 在 C 语言中,严格意义上是没有 boolean 类型的,使用<code>非0</code> 表示<code>true</code><code>0</code> 表示<code>false</code></li><li>② 当条件表达式为真(<code>非0</code> ),就会执行代码块中的语句;否则,就不会执行代码块中的语句。</li></ul></div><ul><li>流程图,如下所示:</li></ul><p><img src="/c/assets/3.DEoM0p3m.png" alt="" loading="lazy"></p><h3 id="_3-2-2-应用示例" tabindex="-1">3.2.2 应用示例 <a class="header-anchor" href="#_3-2-2-应用示例" aria-label="Permalink to &quot;3.2.2 应用示例&quot;"></a></h3><ul><li><p>需求:成年人心率的正常范围是每分钟 60~100 次。体检时,如果心率不在此范围内,则提示需要做进一步的检查。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> heartBeats </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入您的心率:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">heartBeats);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (heartBeats </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 60</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ||</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> heartBeats </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 100</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;您的心率不在正常范围内,请做进一步的检查。</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;体检结束!!!&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><h3 id="_3-2-3-应用示例" tabindex="-1">3.2.3 应用示例 <a class="header-anchor" href="#_3-2-3-应用示例" aria-label="Permalink to &quot;3.2.3 应用示例&quot;"></a></h3><ul><li><p>需求:根据年龄判断,如果是未成年人,则提示 &quot;未成年人请在家长陪同下访问!&quot;</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> age </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入你的年龄:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">age);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (age </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 18</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;未成年人请在家长陪同下访问!</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;欢迎继续访问!&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><h2 id="_3-3-双分支结构" tabindex="-1">3.3 双分支结构 <a class="header-anchor" href="#_3-3-双分支结构" aria-label="Permalink to &quot;3.3 双分支结构&quot;"></a></h2><h3 id="_3-3-1-概述" tabindex="-1">3.3.1 概述 <a class="header-anchor" href="#_3-3-1-概述" aria-label="Permalink to &quot;3.3.1 概述&quot;"></a></h3><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(条件表达式) { </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 语句块1;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 语句块2;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 在 C 语言中,严格意义上是没有 boolean 类型的,使用<code>非0</code> 表示<code>true</code><code>0</code> 表示<code>false</code></li><li>② 当条件表达式为真(<code>非0</code> ),就会执行代码块 1 中的语句;否则,执行代码块 2 中的语句。</li></ul></div><ul><li>流程图,如下所示:</li></ul><p><img src="/c/assets/4.DxEoA7Ht.png" alt="" loading="lazy"></p><h3 id="_3-3-2-应用示例" tabindex="-1">3.3.2 应用示例 <a class="header-anchor" href="#_3-3-2-应用示例" aria-label="Permalink to &quot;3.3.2 应用示例&quot;"></a></h3><ul><li><p>需求:判断一个整数,是奇数还是偶数。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入一个整数:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">num);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 是偶数</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 是奇数</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><h3 id="_3-3-2-应用示例-1" tabindex="-1">3.3.2 应用示例 <a class="header-anchor" href="#_3-3-2-应用示例-1" aria-label="Permalink to &quot;3.3.2 应用示例&quot;"></a></h3><ul><li><p>需求输入年龄如果大于18岁则输出 &quot;你年龄大于18要对自己的行为负责!&quot;;否则,输出 &quot;你的年龄不大这次放过你了。&quot;</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> age </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入年龄:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">age);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (age </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 18</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;你年龄大于18要对自己的行为负责!</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;你的年龄不大,这次放过你了!</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><h3 id="_3-3-3-应用示例" tabindex="-1">3.3.3 应用示例 <a class="header-anchor" href="#_3-3-3-应用示例" aria-label="Permalink to &quot;3.3.3 应用示例&quot;"></a></h3><ul><li>需求:判定某个年份是否为闰年?</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① year 是 400 的整倍数: year%400==0</li><li>② 能被 4 整除,但不能被 100 整除year % 4 == 0 &amp;&amp; year % 100 != 0</li></ul></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> year </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入年份:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">year);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (year </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 400</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ||</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (year </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 4</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &amp;&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> year </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 100</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> !=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 是闰年</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, year);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 不是闰年</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, year);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><h2 id="_3-4-多重分支结构" tabindex="-1">3.4 多重分支结构 <a class="header-anchor" href="#_3-4-多重分支结构" aria-label="Permalink to &quot;3.4 多重分支结构&quot;"></a></h2><h3 id="_3-4-1-概述" tabindex="-1">3.4.1 概述 <a class="header-anchor" href="#_3-4-1-概述" aria-label="Permalink to &quot;3.4.1 概述&quot;"></a></h3><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (条件表达式1) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 语句块1;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">} </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (条件表达式2) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 语句块2;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">...</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">} </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (条件表达式n) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 语句块n;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">} </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 语句块n</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 在 C 语言中,严格意义上是没有 boolean 类型的,使用<code>非0</code> 表示<code>true</code><code>0</code> 表示<code>false</code></li><li>② 首先判断关系表达式 1 的结果是真(值为 <code>非0</code>)还是假(值为 <code>0</code> <ul><li>如果为真,就执行语句块 1然后结束当前多分支。</li><li>如果是假,就继续判断条件表达式 2看其结果是真还是假。</li><li>如果是真,就执行语句块 2然后结束当前多分支。</li><li>如果是假,就继续判断条件表达式…看其结果是真还是假。</li><li>...</li><li>如果没有任何关系表达式为真,就执行语句块 n+1然后结束当前多分支。</li></ul></li><li>③ 当条件表达式之间是<code>互斥</code>(彼此之间没有交集)关系时,条件判断语句及执行语句间顺序无所谓。</li><li>④ 当条件表达式之间是<code>包含</code>关系时,必须<code>小上大下 / 子上父下</code>,否则范围小的条件表达式将不可能被执行。</li><li>⑤ 当 if-else 结构是多选一的时候,最后的 else 是可选的,可以根据需要省略。</li><li>⑥ 如果语句块中只有一条执行语句的时候,<code>{}</code>是可以省略的;但是,强烈建议保留!!!</li></ul></div><ul><li>流程图,如下所示:</li></ul><p><img src="/c/assets/5.DtY5Pf6u.png" alt="image-20240722075241253" loading="lazy"></p><h3 id="_3-4-1-应用示例" tabindex="-1">3.4.1 应用示例 <a class="header-anchor" href="#_3-4-1-应用示例" aria-label="Permalink to &quot;3.4.1 应用示例&quot;"></a></h3><ul><li><p>需求:张三参加考试,他和父亲达成协议,如果成绩不到 60 分没有任何奖励;如果成绩 60分到 80 分,奖励一个肉夹馍;如果成绩 80 分(含)到 90 分,奖励一个 ipad如果成绩 90 分及以上,奖励一部华为 mate60 pro 。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> score </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入分数:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">score);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 容错:分数不可能小于 0 或大于 100</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (score </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ||</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> score </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 100</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;输入的分数有误!</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (score </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 90</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;奖励你一部华为 mate60 pro</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (score </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 80</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;奖励你一个 ipad</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (score </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 60</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;奖励你一个肉夹馍</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;你的成绩不及格,没有任何奖励!&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br></div></div><h3 id="_3-4-2-应用示例" tabindex="-1">3.4.2 应用示例 <a class="header-anchor" href="#_3-4-2-应用示例" aria-label="Permalink to &quot;3.4.2 应用示例&quot;"></a></h3><ul><li><p>需求:判断水的温度,如果大于 95℃则打印 &quot;开水&quot;;如果大于 70℃ 且小于等于 95℃则打印 &quot;热水&quot;;如果大于 40℃ 且小于等于 70℃则打印 &quot;温水&quot;;如果小于等于 40℃则打印 &quot;凉水&quot;</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> temperature </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入水的温度:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">temperature);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (temperature </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 95</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;开水 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (temperature </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 70</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &amp;&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> temperature </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 95</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;热水 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (temperature </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 40</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &amp;&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> temperature </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 70</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;温水 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;凉水 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br></div></div><h2 id="_3-5-多重分支结构-switch" tabindex="-1">3.5 多重分支结构 switch <a class="header-anchor" href="#_3-5-多重分支结构-switch" aria-label="Permalink to &quot;3.5 多重分支结构 switch&quot;"></a></h2><h3 id="_3-5-1-概述" tabindex="-1">3.5.1 概述 <a class="header-anchor" href="#_3-5-1-概述" aria-label="Permalink to &quot;3.5.1 概述&quot;"></a></h3><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">switch</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(表达式){</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 常量值1: </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 语句块1;</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> //break;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 常量值2: </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 语句块2;</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> //break;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ...</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 常量值n: </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 语句块n; </span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> //break;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> [default: </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 语句块n</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ]</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① switch 后面表达式的值必须是一个整型char、short、int、long 等)或枚举类型。</li><li>② case 后面的值必须是常量,不能是变量。</li><li>③ default 是可选的,当没有匹配的 case 的时候,就执行 default 。</li><li>④ break 语句可以使程序跳出 switch 语句块,如果没有 break会执行下一个 case 语句块,直到遇到 break 或者执行到 switch 结尾,这个现象称为穿透。</li></ul></div><ul><li>流程图,如下所示:</li></ul><p><img src="/c/assets/6.CButBugT.png" alt="" loading="lazy"></p><h3 id="_3-5-2-应用示例" tabindex="-1">3.5.2 应用示例 <a class="header-anchor" href="#_3-5-2-应用示例" aria-label="Permalink to &quot;3.5.2 应用示例&quot;"></a></h3><ul><li><p>需求编写一个程序该程序可以接收一个字符比如a、b、c、d其中 a 表示星期一b 表示星期二…,根据用户的输入显示相应的信息,要求使用 switch 语句。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> chs;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入一个字符a、b、c、d&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%c</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">chs);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> switch</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (chs) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;a&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;今天是星期一 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;窗前明月光 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;b&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;今天是星期二 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;疑是地上霜 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;c&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;今天是星期三 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;举头望明月 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;d&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;今天是星期四 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;低头思故乡 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> default</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;输入错误!&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br></div></div><h3 id="_3-5-3-应用示例" tabindex="-1">3.5.3 应用示例 <a class="header-anchor" href="#_3-5-3-应用示例" aria-label="Permalink to &quot;3.5.3 应用示例&quot;"></a></h3><ul><li><p>需求编写程序输入月份输出该月份有多少天。说明1 月、3 月、5 月、7月、8 月、10 月、12 月有 31 天4 月、6 月、9 月、11 月有 30 天2 月有 28 天或 29 天。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> month;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入月份 (1-12)&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">month);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> switch</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (month) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 7</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 8</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 月有 31 天</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, month);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 6</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 9</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 11</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 月有 30 天</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, month);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 月有 28 天或 29 天</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, month);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> default</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;输入错误!&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br></div></div><h3 id="_3-5-4-switch-和-if-else-if-的比较" tabindex="-1">3.5.4 switch 和 if else if 的比较 <a class="header-anchor" href="#_3-5-4-switch-和-if-else-if-的比较" aria-label="Permalink to &quot;3.5.4 switch 和 if else if 的比较&quot;"></a></h3><ul><li>① 如果判断条件是判等,而且符合整型、枚举类型,虽然两个语句都可以使用,建议使用 swtich 语句。</li><li>② 如果判断条件是区间判断,大小判断等,使用 if...else...if。</li></ul><h2 id="_3-6-嵌套分支" tabindex="-1">3.6 嵌套分支 <a class="header-anchor" href="#_3-6-嵌套分支" aria-label="Permalink to &quot;3.6 嵌套分支&quot;"></a></h2><h3 id="_3-6-1-概述" tabindex="-1">3.6.1 概述 <a class="header-anchor" href="#_3-6-1-概述" aria-label="Permalink to &quot;3.6.1 概述&quot;"></a></h3><ul><li>嵌套分支是指,在一个分支结构中又嵌套了另一个分支结构,里面的分支的结构称为内层分支,外面的分支结构称为外层分支。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>嵌套分支层数不宜过多,建议最多不要超过 3 层。</p></div><h3 id="_3-6-2-应用示例" tabindex="-1">3.6.2 应用示例 <a class="header-anchor" href="#_3-6-2-应用示例" aria-label="Permalink to &quot;3.6.2 应用示例&quot;"></a></h3><ul><li>需求:根据淡旺季的月份和年龄,打印票价。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 4 -10 是旺季: <ul><li>成人18-6060 。</li><li>儿童(&lt;18半价。</li><li>老人(&gt;601/3 。</li></ul></li><li>② 其余是淡季: <ul><li>成人40。</li><li>其他20。</li></ul></li></ul></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> month;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> age;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> price </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 60</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入月份 (1-12)&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">month);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入年龄:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">age);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 旺季</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (month </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 4</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &amp;&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> month </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (age </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 18</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> price </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (age </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 60</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> price </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (age </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 18</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> price </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 40</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> price </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 20</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;票价: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%.2lf\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, price);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br></div></div><h1 id="第四章-随机数" tabindex="-1">第四章:随机数 <a class="header-anchor" href="#第四章-随机数" aria-label="Permalink to &quot;第四章:随机数&quot;"></a></h1><h2 id="_4-1-概述" tabindex="-1">4.1 概述 <a class="header-anchor" href="#_4-1-概述" aria-label="Permalink to &quot;4.1 概述&quot;"></a></h2><ul><li>所谓的随机数就是没有规则,并且不能预测的一些数字,也称为真随机数。</li><li>程序中也是可以产生随机数的,但是是通过一些固定规则产生的,称为伪随机数。</li><li>常见的伪随机数线性同余方程LCG的公式如下所示</li></ul><p><mjx-container class="MathJax" jax="SVG" style="direction:ltr;position:relative;"><svg style="overflow:visible;min-height:1px;min-width:1px;vertical-align:-0.566ex;" xmlns="http://www.w3.org/2000/svg" width="28.71ex" height="2.262ex" role="img" focusable="false" viewBox="0 -750 12690 1000" aria-hidden="true"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(1,-1)"><g data-mml-node="math"><g data-mml-node="msub"><g data-mml-node="mi"><path data-c="1D44B" d="M42 0H40Q26 0 26 11Q26 15 29 27Q33 41 36 43T55 46Q141 49 190 98Q200 108 306 224T411 342Q302 620 297 625Q288 636 234 637H206Q200 643 200 645T202 664Q206 677 212 683H226Q260 681 347 681Q380 681 408 681T453 682T473 682Q490 682 490 671Q490 670 488 658Q484 643 481 640T465 637Q434 634 411 620L488 426L541 485Q646 598 646 610Q646 628 622 635Q617 635 609 637Q594 637 594 648Q594 650 596 664Q600 677 606 683H618Q619 683 643 683T697 681T738 680Q828 680 837 683H845Q852 676 852 672Q850 647 840 637H824Q790 636 763 628T722 611T698 593L687 584Q687 585 592 480L505 384Q505 383 536 304T601 142T638 56Q648 47 699 46Q734 46 734 37Q734 35 732 23Q728 7 725 4T711 1Q708 1 678 1T589 2Q528 2 496 2T461 1Q444 1 444 10Q444 11 446 25Q448 35 450 39T455 44T464 46T480 47T506 54Q523 62 523 64Q522 64 476 181L429 299Q241 95 236 84Q232 76 232 72Q232 53 261 47Q262 47 267 47T273 46Q276 46 277 46T280 45T283 42T284 35Q284 26 282 19Q279 6 276 4T261 1Q258 1 243 1T201 2T142 2Q64 2 42 0Z" style="stroke-width:3;"></path></g><g data-mml-node="TeXAtom" transform="translate(861,-150) scale(0.707)" data-mjx-texclass="ORD"><g data-mml-node="mi"><path data-c="1D45B" d="M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z" style="stroke-width:3;"></path></g><g data-mml-node="mo" transform="translate(600,0)"><path data-c="2B" d="M56 237T56 250T70 270H369V420L370 570Q380 583 389 583Q402 583 409 568V270H707Q722 262 722 250T707 230H409V-68Q401 -82 391 -82H389H387Q375 -82 369 -68V230H70Q56 237 56 250Z" style="stroke-width:3;"></path></g><g data-mml-node="mn" transform="translate(1378,0)"><path data-c="31" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z" style="stroke-width:3;"></path></g></g></g><g data-mml-node="mo" transform="translate(2516.7,0)"><path data-c="3D" d="M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z" style="stroke-width:3;"></path></g><g data-mml-node="mo" transform="translate(3572.5,0)"><path data-c="28" d="M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z" style="stroke-width:3;"></path></g><g data-mml-node="mi" transform="translate(3961.5,0)"><path data-c="1D44E" d="M33 157Q33 258 109 349T280 441Q331 441 370 392Q386 422 416 422Q429 422 439 414T449 394Q449 381 412 234T374 68Q374 43 381 35T402 26Q411 27 422 35Q443 55 463 131Q469 151 473 152Q475 153 483 153H487Q506 153 506 144Q506 138 501 117T481 63T449 13Q436 0 417 -8Q409 -10 393 -10Q359 -10 336 5T306 36L300 51Q299 52 296 50Q294 48 292 46Q233 -10 172 -10Q117 -10 75 30T33 157ZM351 328Q351 334 346 350T323 385T277 405Q242 405 210 374T160 293Q131 214 119 129Q119 126 119 118T118 106Q118 61 136 44T179 26Q217 26 254 59T298 110Q300 114 325 217T351 328Z" style="stroke-width:3;"></path></g><g data-mml-node="mo" transform="translate(4712.7,0)"><path data-c="22C5" d="M78 250Q78 274 95 292T138 310Q162 310 180 294T199 251Q199 226 182 208T139 190T96 207T78 250Z" style="stroke-width:3;"></path></g><g data-mml-node="msub" transform="translate(5212.9,0)"><g data-mml-node="mi"><path data-c="1D44B" d="M42 0H40Q26 0 26 11Q26 15 29 27Q33 41 36 43T55 46Q141 49 190 98Q200 108 306 224T411 342Q302 620 297 625Q288 636 234 637H206Q200 643 200 645T202 664Q206 677 212 683H226Q260 681 347 681Q380 681 408 681T453 682T473 682Q490 682 490 671Q490 670 488 658Q484 643 481 640T465 637Q434 634 411 620L488 426L541 485Q646 598 646 610Q646 628 622 635Q617 635 609 637Q594 637 594 648Q594 650 596 664Q600 677 606 683H618Q619 683 643 683T697 681T738 680Q828 680 837 683H845Q852 676 852 672Q850 647 840 637H824Q790 636 763 628T722 611T698 593L687 584Q687 585 592 480L505 384Q505 383 536 304T601 142T638 56Q648 47 699 46Q734 46 734 37Q734 35 732 23Q728 7 725 4T711 1Q708 1 678 1T589 2Q528 2 496 2T461 1Q444 1 444 10Q444 11 446 25Q448 35 450 39T455 44T464 46T480 47T506 54Q523 62 523 64Q522 64 476 181L429 299Q241 95 236 84Q232 76 232 72Q232 53 261 47Q262 47 267 47T273 46Q276 46 277 46T280 45T283 42T284 35Q284 26 282 19Q279 6 276 4T261 1Q258 1 243 1T201 2T142 2Q64 2 42 0Z" style="stroke-width:3;"></path></g><g data-mml-node="mi" transform="translate(861,-150) scale(0.707)"><path data-c="1D45B" d="M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z" style="stroke-width:3;"></path></g></g><g data-mml-node="mo" transform="translate(6770.4,0)"><path data-c="2B" d="M56 237T56 250T70 270H369V420L370 570Q380 583 389 583Q402 583 409 568V270H707Q722 262 722 250T707 230H409V-68Q401 -82 391 -82H389H387Q375 -82 369 -68V230H70Q56 237 56 250Z" style="stroke-width:3;"></path></g><g data-mml-node="mi" transform="translate(7770.7,0)"><path data-c="1D44F" d="M73 647Q73 657 77 670T89 683Q90 683 161 688T234 694Q246 694 246 685T212 542Q204 508 195 472T180 418L176 399Q176 396 182 402Q231 442 283 442Q345 442 383 396T422 280Q422 169 343 79T173 -11Q123 -11 82 27T40 150V159Q40 180 48 217T97 414Q147 611 147 623T109 637Q104 637 101 637H96Q86 637 83 637T76 640T73 647ZM336 325V331Q336 405 275 405Q258 405 240 397T207 376T181 352T163 330L157 322L136 236Q114 150 114 114Q114 66 138 42Q154 26 178 26Q211 26 245 58Q270 81 285 114T318 219Q336 291 336 325Z" style="stroke-width:3;"></path></g><g data-mml-node="mo" transform="translate(8199.7,0)"><path data-c="29" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z" style="stroke-width:3;"></path></g><g data-mml-node="mspace" transform="translate(8588.7,0)"></g><g data-mml-node="mi" transform="translate(9422.3,0)"><path data-c="6D" d="M41 46H55Q94 46 102 60V68Q102 77 102 91T102 122T103 161T103 203Q103 234 103 269T102 328V351Q99 370 88 376T43 385H25V408Q25 431 27 431L37 432Q47 433 65 434T102 436Q119 437 138 438T167 441T178 442H181V402Q181 364 182 364T187 369T199 384T218 402T247 421T285 437Q305 442 336 442Q351 442 364 440T387 434T406 426T421 417T432 406T441 395T448 384T452 374T455 366L457 361L460 365Q463 369 466 373T475 384T488 397T503 410T523 422T546 432T572 439T603 442Q729 442 740 329Q741 322 741 190V104Q741 66 743 59T754 49Q775 46 803 46H819V0H811L788 1Q764 2 737 2T699 3Q596 3 587 0H579V46H595Q656 46 656 62Q657 64 657 200Q656 335 655 343Q649 371 635 385T611 402T585 404Q540 404 506 370Q479 343 472 315T464 232V168V108Q464 78 465 68T468 55T477 49Q498 46 526 46H542V0H534L510 1Q487 2 460 2T422 3Q319 3 310 0H302V46H318Q379 46 379 62Q380 64 380 200Q379 335 378 343Q372 371 358 385T334 402T308 404Q263 404 229 370Q202 343 195 315T187 232V168V108Q187 78 188 68T191 55T200 49Q221 46 249 46H265V0H257L234 1Q210 2 183 2T145 3Q42 3 33 0H25V46H41Z" style="stroke-width:3;"></path><path data-c="6F" d="M28 214Q28 309 93 378T250 448Q340 448 405 380T471 215Q471 120 407 55T250 -10Q153 -10 91 57T28 214ZM250 30Q372 30 372 193V225V250Q372 272 371 288T364 326T348 362T317 390T268 410Q263 411 252 411Q222 411 195 399Q152 377 139 338T126 246V226Q126 130 145 91Q177 30 250 30Z" transform="translate(833,0)" style="stroke-width:3;"></path><path data-c="64" d="M376 495Q376 511 376 535T377 568Q377 613 367 624T316 637H298V660Q298 683 300 683L310 684Q320 685 339 686T376 688Q393 689 413 690T443 693T454 694H457V390Q457 84 458 81Q461 61 472 55T517 46H535V0Q533 0 459 -5T380 -11H373V44L365 37Q307 -11 235 -11Q158 -11 96 50T34 215Q34 315 97 378T244 442Q319 442 376 393V495ZM373 342Q328 405 260 405Q211 405 173 369Q146 341 139 305T131 211Q131 155 138 120T173 59Q203 26 251 26Q322 26 373 103V342Z" transform="translate(1333,0)" style="stroke-width:3;"></path></g><g data-mml-node="mstyle" transform="translate(11311.3,0)"><g data-mml-node="mspace"></g></g><g data-mml-node="mstyle" transform="translate(11478.3,0)"><g data-mml-node="mspace"></g></g><g data-mml-node="mi" transform="translate(11812,0)"><path data-c="1D45A" d="M21 287Q22 293 24 303T36 341T56 388T88 425T132 442T175 435T205 417T221 395T229 376L231 369Q231 367 232 367L243 378Q303 442 384 442Q401 442 415 440T441 433T460 423T475 411T485 398T493 385T497 373T500 364T502 357L510 367Q573 442 659 442Q713 442 746 415T780 336Q780 285 742 178T704 50Q705 36 709 31T724 26Q752 26 776 56T815 138Q818 149 821 151T837 153Q857 153 857 145Q857 144 853 130Q845 101 831 73T785 17T716 -10Q669 -10 648 17T627 73Q627 92 663 193T700 345Q700 404 656 404H651Q565 404 506 303L499 291L466 157Q433 26 428 16Q415 -11 385 -11Q372 -11 364 -4T353 8T350 18Q350 29 384 161L420 307Q423 322 423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 181Q151 335 151 342Q154 357 154 369Q154 405 129 405Q107 405 92 377T69 316T57 280Q55 278 41 278H27Q21 284 21 287Z" style="stroke-width:3;"></path></g></g></g></svg><mjx-assistive-mml unselectable="on" display="inline" style="top:0px;left:0px;clip:rect(1px, 1px, 1px, 1px);-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;position:absolute;padding:1px 0px 0px 0px;border:0px;display:block;width:auto;overflow:hidden;"><math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>X</mi><mrow data-mjx-texclass="ORD"><mi>n</mi><mo>+</mo><mn>1</mn></mrow></msub><mo>=</mo><mo stretchy="false">(</mo><mi>a</mi><mo></mo><msub><mi>X</mi><mi>n</mi></msub><mo>+</mo><mi>b</mi><mo stretchy="false">)</mo><mspace width="0.667em"></mspace><mi>mod</mi><mstyle scriptlevel="0"><mspace width="0.167em"></mspace></mstyle><mstyle scriptlevel="0"><mspace width="0.167em"></mspace></mstyle><mi>m</mi></math></mjx-assistive-mml></mjx-container></p><ul><li>其中X 是伪随机序列a 是乘数(通常选择一个大于 0 的常数,典型值有 1664525b 是增量(选择一个大于 0 的常数,典型值有 1013904223 m 是模数( 通常选择一个大的常数,常见值有 ( 2^{32} ) ,即 4294967296</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>假设 a = 31 b = 13 m = 100 ;那么,伪随机数的公式就是 <code>X_{n+1} = (31 × X_n + 13) % 100 </code></p><ul><li>如果 <code>X_{n}</code> = 1 ,那么 <code>X_{n+1}</code> = 44 。</li><li>如果 <code>X_{n}</code> = 44 ,那么 <code>X_{n+1}</code> = 77 。</li><li>如果 <code>X_{n}</code> = 77 ,那么 <code>X_{n+1}</code> = 0 。</li><li>...</li></ul><p>最后,将得到 44、77、0、13、16、9 、92、65、28 ... ,其中 1 也称为初始种子(随机数种子)。</p></div><ul><li>工作原理: <ul><li>① 设置初始种子X_0 <ul><li>种子值是算法生成随机数序列的起点。</li><li>不同的种子值会产生不同的随机数序列。</li></ul></li><li>② 递归生成随机数: <ul><li>从初始种子开始,通过公式不断生成新的随机数。</li><li>每次迭代都使用前一次生成的随机数作为输入。</li></ul></li></ul></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>如果种子的值相同,那么每次生成的随机数将相同,解决方案就是将种子的值设置为当前的时间戳。</p></div><h2 id="_4-2-c-语言中随机数的产生" tabindex="-1">4.2 C 语言中随机数的产生 <a class="header-anchor" href="#_4-2-c-语言中随机数的产生" aria-label="Permalink to &quot;4.2 C 语言中随机数的产生&quot;"></a></h2><ul><li>① 设置随机数种子:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">srand</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // seed 种⼦ rand random 随机</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>随机数函数在 <code>#include &lt;stdlib.h&gt;</code> 中声明。</p></div><ul><li>② 根据随机数种⼦计算出⼀个伪随机数:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 根据种⼦值产⽣⼀个 0-32767 范围的随机数</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> result </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> rand</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">();</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><ul><li>③ 产生一个指定范围内的随机数:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> random_in_range</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> min</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> max</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> rand</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (max </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> min </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> min;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdlib.h&gt;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;time.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 生成指定范围的随机数的函数</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> randomInRange</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> min</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> max</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> rand</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (max </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> min </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> min;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 使用当前时间作为种子</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> srand</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">time</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">));</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义范围</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> min </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> max </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 100</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 生成并打印随机数</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">i) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> random </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> randomInRange</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(min, max);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, random);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br></div></div><h1 id="第五章-循环结构-⭐" tabindex="-1">第五章:循环结构(⭐) <a class="header-anchor" href="#第五章-循环结构-⭐" aria-label="Permalink to &quot;第五章:循环结构(⭐)&quot;"></a></h1><h2 id="_5-1-概述" tabindex="-1">5.1 概述 <a class="header-anchor" href="#_5-1-概述" aria-label="Permalink to &quot;5.1 概述&quot;"></a></h2><ul><li>循环结构:在某些条件满足的情况下,反复执行特定代码的功能。</li></ul><h2 id="_5-2-for-循环" tabindex="-1">5.2 for 循环 <a class="header-anchor" href="#_5-2-for-循环" aria-label="Permalink to &quot;5.2 for 循环&quot;"></a></h2><h3 id="_5-2-1-概述" tabindex="-1">5.2.1 概述 <a class="header-anchor" href="#_5-2-1-概述" aria-label="Permalink to &quot;5.2.1 概述&quot;"></a></h3><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(初始化条件①;循环条件表达式②;迭代语句④){</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 循环体语句③</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 初始化条件,用于初始化循环变量,只会执行一次,且循环开始前就执行(可以声明多个变量,但是必须是同一类型,用逗号 <code>,</code> 隔开)。</li><li>② 循环条件表达式每次循环都执行,同 while 循环一样,每次先判断后执行循环体语句。</li><li>③ 迭代语句每次循环都执行,在大括号中循环体语句之后执行(如果有多个变量更新,用逗号 <code>,</code> 隔开)。</li></ul></div><ul><li>流程图,如下所示:</li></ul><p><img src="/c/assets/7.DG_I9X5w.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>执行过程是:① --&gt; ② --&gt; ③ --&gt; ④ --&gt; ② --&gt; ③ --&gt; ④ --&gt; ... --&gt; ② 。</p></div><h3 id="_5-2-2-应用示例" tabindex="-1">5.2.2 应用示例 <a class="header-anchor" href="#_5-2-2-应用示例" aria-label="Permalink to &quot;5.2.2 应用示例&quot;"></a></h3><ul><li><p>需求:输出 5 行 <code>Hello World!</code></p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">i) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;Hello World!</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><h3 id="_5-2-3-应用示例" tabindex="-1">5.2.3 应用示例 <a class="header-anchor" href="#_5-2-3-应用示例" aria-label="Permalink to &quot;5.2.3 应用示例&quot;"></a></h3><ul><li><p>需求:求 1 ~ 100 之内所有偶数的和,以及偶数的个数。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> sum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> count </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 100</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> sum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> count</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;1 ~ 100 中的所有偶数的和为: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, sum);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;1 ~ 100 中的所有偶数的个数为: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, count);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br></div></div><h3 id="_5-2-4-应用示例" tabindex="-1">5.2.4 应用示例 <a class="header-anchor" href="#_5-2-4-应用示例" aria-label="Permalink to &quot;5.2.4 应用示例&quot;"></a></h3><ul><li><p>需求:输出所有的水仙花数,所谓水仙花数是指一个 3 位数,其各个位上数字立方和等于其本身,例如:<code>153 = 1×1×1 + 3×3×3 + 5×5×5</code></p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> count </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 100</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 999</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 获取三位数</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ge </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> shi </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> %</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> bai </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 100</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 判定是否为水仙花数</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (ge </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ge </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ge </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> shi </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> shi </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> shi </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> bai </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> bai </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> bai </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">==</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;水仙花数:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, i);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> count</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;水仙花数总个数:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, count);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br></div></div><h3 id="_5-2-5-应用示例" tabindex="-1">5.2.5 应用示例 <a class="header-anchor" href="#_5-2-5-应用示例" aria-label="Permalink to &quot;5.2.5 应用示例&quot;"></a></h3><ul><li><p>需求:将 1 ~ 10 倒序输出10 、9 、8 ...</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">--</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, i);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><h3 id="_5-2-6-应用示例" tabindex="-1">5.2.6 应用示例 <a class="header-anchor" href="#_5-2-6-应用示例" aria-label="Permalink to &quot;5.2.6 应用示例&quot;"></a></h3><ul><li>需求:输入两个正整数 m 和 n 求其最大公约数和最小公倍数例如12 和 20 的最大公约数是 4 ,最小公倍数是 60 。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>如果数 a 能被数 b 整除,且结果是整数,那么 a 就叫做 b 的倍数b 就叫做 a 的约数(因数)。</li><li>如果一个整数同时是几个整数的约数,则称该整数为这些整数的公约数;其中,数值最大的称为最大公约数。</li><li>如果一个整数同时为两个或多个整数的倍数的数,则称该整数为这些整数的公倍数;其中,数值最小的称为最小公倍数。</li></ul></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> m </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, n </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 20</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 取出两个数中的较小值</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> min </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (m </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> n) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">?</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> m </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> n;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> min; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">--</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (m </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &amp;&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> n </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;最大公约数是:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, i);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 公约数</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> //跳出当前循环结构</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 取出两个数中的较大值</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> max </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (m </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> n) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">?</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> m </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> n;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> max; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> m </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> n; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> m </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &amp;&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> n </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;最小公倍数是:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, i);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 公倍数</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br></div></div><h2 id="_5-3-while-循环" tabindex="-1">5.3 while 循环 <a class="header-anchor" href="#_5-3-while-循环" aria-label="Permalink to &quot;5.3 while 循环&quot;"></a></h2><h3 id="_5-3-1-概述" tabindex="-1">5.3.1 概述 <a class="header-anchor" href="#_5-3-1-概述" aria-label="Permalink to &quot;5.3.1 概述&quot;"></a></h3><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">初始化条件①;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">while</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (循环条件语句②) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 循环体语句③;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 迭代语句④;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li><code>while(循环条件部分)</code> 中循环条件为<code>非0</code>值,表示 <code>true</code><code></code>;为<code>0</code>值,表示 <code>false</code><code></code></li><li>② 当循环条件表达式成立,就执行循环体语句,直到条件不成立停止循环。</li><li>③ 为避免死循环,循环条件表达式不能永远成立,且随着循环次数增加,应该越来越趋向于不成立。</li><li>④ for 循环和 while 循环<code>可以相互转换</code>,二者没有性能上的差别。</li><li>⑤ for 循环与 while 循环的区别:<code>初始化条件部分的作用域不同</code></li></ul></div><ul><li>流程图,如下所示:</li></ul><p><img src="/c/assets/8.Cw8LCRHN.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>执行过程是:① --&gt; ② --&gt; ③ --&gt; ④ --&gt; ② --&gt; ③ --&gt; ④ --&gt; ... --&gt; ② 。</p></div><h3 id="_5-3-2-应用示例" tabindex="-1">5.3.2 应用示例 <a class="header-anchor" href="#_5-3-2-应用示例" aria-label="Permalink to &quot;5.3.2 应用示例&quot;"></a></h3><ul><li><p>需求:输出 5 行 <code>Hello World!</code></p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> while</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;Hello World!</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><h3 id="_5-3-3-应用示例" tabindex="-1">5.3.3 应用示例 <a class="header-anchor" href="#_5-3-3-应用示例" aria-label="Permalink to &quot;5.3.3 应用示例&quot;"></a></h3><ul><li><p>需求:求 1 ~ 100 之内所有偶数的和,以及偶数的个数。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> sum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> count </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> while</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 100</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> sum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> count</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;1 ~ 100 中的所有偶数的和为: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, sum);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;1 ~ 100 中的所有偶数的个数为: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, count);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br></div></div><h3 id="_5-3-4-应用示例" tabindex="-1">5.3.4 应用示例 <a class="header-anchor" href="#_5-3-4-应用示例" aria-label="Permalink to &quot;5.3.4 应用示例&quot;"></a></h3><ul><li><p>需求:世界最高山峰是珠穆朗玛峰,它的高度是 8848.86 米,假如我有一张足够大的纸,它的厚度是 0.1 毫米。请问,我折叠多少次,可以折成珠穆朗玛峰的高度?</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 折叠的次数</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> count </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 珠峰的高度</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> zfHeight </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 8848860</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 每次折叠的高度</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> paperHeight </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0.1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> while</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (paperHeight </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> zfHeight) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> count</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> paperHeight </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;需要折叠 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 次,才能得到珠峰的高度。</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, count);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;折纸的高度为 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%.2f</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 米,超过了珠峰的高度&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, paperHeight </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1000</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br></div></div><h3 id="_5-3-5-应用示例" tabindex="-1">5.3.5 应用示例 <a class="header-anchor" href="#_5-3-5-应用示例" aria-label="Permalink to &quot;5.3.5 应用示例&quot;"></a></h3><ul><li>需求:给出一个整数 n ,判断该整数是否是 2 的幂次方。如果是,就输出 yes ;否则,输出 no 。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>思路:</p><ul><li>① 2^ 0 = 1 2^1 = 2 2^2 = 42^3 = 82^4 = 162^5 = 32 ...,规律:每一个数字都是前一个数字的 2 倍(任意一个数字,不断的除以 2 ,最终看结果是否是数字 1 )。</li><li>② 循环终止条件: <ul><li>结果是 1 的时候,就可以结束,输出 yes 。</li><li>如果在除以 2 的时候,无法被 2 整数,也可以结束,输出 no ,如: 100 / 2 = 5050 / 2 = 25 。</li></ul></li></ul></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 禁用 stdout 缓冲区</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> setbuf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(stdout, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">NULL</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> n </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入一个整数:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">n);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> while</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (n </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &amp;&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> n </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> n </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (n </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;yes&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;no&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br></div></div><h3 id="_5-3-6-应用示例" tabindex="-1">5.3.6 应用示例 <a class="header-anchor" href="#_5-3-6-应用示例" aria-label="Permalink to &quot;5.3.6 应用示例&quot;"></a></h3><ul><li>需求整数反转123 --&gt; 321 。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>思路:从右边开始,依次获取每一位数字,再拼接起来。</p></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 禁用 stdout 缓冲区</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> setbuf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(stdout, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">NULL</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> original </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> rev </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入一个整数:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">num);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> original </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 从右边开始,依次获取每个数字,然后拼接到 rev 中</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> /**</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * 第 1 次123 % 10 = 3rev = 0 * 10 + 3 = 3</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * 第 2 次12 % 10 = 2rev = 3 * 10 + 2 = 32</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * 第 3 次1 % 10 = 1rev = 32 * 10 + 1 = 321</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> */</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 循环结束的条件是 num == 0</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> while</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">!=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 获取 num 右边的第一位数字</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> temp </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 去掉最后一位数字</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 将 temp 拼接到 rev 的后面</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> rev </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> rev </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> +</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> temp;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 的反转是 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, original, rev);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br></div></div><h2 id="_5-4-do-while-循环" tabindex="-1">5.4 do-while 循环 <a class="header-anchor" href="#_5-4-do-while-循环" aria-label="Permalink to &quot;5.4 do-while 循环&quot;"></a></h2><h3 id="_5-4-1-概述" tabindex="-1">5.4.1 概述 <a class="header-anchor" href="#_5-4-1-概述" aria-label="Permalink to &quot;5.4.1 概述&quot;"></a></h3><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">①初始化部分;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">do</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">{</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ③循环体部分</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ④迭代部分</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">while</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(②循环条件部分);</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li><code>do{} while();</code>最后有一个分号。</li><li>② do-while 结构的循环体语句是至少会执行一次,这个和 for 、while 是不一样的。</li><li>③ 循环的三个结构 for、while、do-while 三者是可以相互转换的。</li></ul></div><ul><li>流程图,如下所示:</li></ul><p><img src="/c/assets/9.TqkSPw2X.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>执行过程是:① --&gt; ③ --&gt; ④ --&gt; ② --&gt; ③ --&gt; ④ --&gt; ② --&gt; ... --&gt; ② 。</p></div><h3 id="_5-4-2-应用示例" tabindex="-1">5.4.2 应用示例 <a class="header-anchor" href="#_5-4-2-应用示例" aria-label="Permalink to &quot;5.4.2 应用示例&quot;"></a></h3><ul><li>需求:求 1 ~ 100 之内所有偶数的和,以及偶数的个数。</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> sum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> count </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> do</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> sum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> count</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">while</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 100</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;1 ~ 100 中的所有偶数的和为: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, sum);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;1 ~ 100 中的所有偶数的个数为: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, count);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br></div></div><h3 id="_5-4-3-应用示例" tabindex="-1">5.4.3 应用示例 <a class="header-anchor" href="#_5-4-3-应用示例" aria-label="Permalink to &quot;5.4.3 应用示例&quot;"></a></h3><ul><li><p>需求:实现 ATM 取款机功能。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 账户余额</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> balance </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0.0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 客户选择</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> selection;</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 存款金额</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> addMoney;</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 取款金额</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> minusMoney;</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 退出标识</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> bool</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> exitFlag </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> false</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> do</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;=========ATM========</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\t</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">1、存款</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\t</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">2、取款</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\t</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">3、显示余额</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\t</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">4、退出</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请选择(1-4)&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">selection);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> switch</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (selection) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;您当前的余额是: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%.2f\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, balance);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入存款金额:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%lf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">addMoney</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> balance </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> addMoney;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;存款成功,您当前的余额是:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%.2f\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, balance);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;您当前的余额是: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%.2f\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, balance);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入取款金额:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%lf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">minusMoney</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (minusMoney </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> balance) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;余额不足,取款失败。</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> balance </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> minusMoney;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;取款成功,您的余额为:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%.2f\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, balance);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;您的账户余额为:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%.2f\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, balance);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> exitFlag </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> true</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;欢迎下次再来。</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> default</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;输入有误,请重新输入。</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">while</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">!</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">exitFlag);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br><span class="line-number">45</span><br><span class="line-number">46</span><br><span class="line-number">47</span><br><span class="line-number">48</span><br><span class="line-number">49</span><br><span class="line-number">50</span><br><span class="line-number">51</span><br><span class="line-number">52</span><br><span class="line-number">53</span><br><span class="line-number">54</span><br><span class="line-number">55</span><br><span class="line-number">56</span><br><span class="line-number">57</span><br><span class="line-number">58</span><br></div></div><h2 id="_5-5-嵌套循环" tabindex="-1">5.5 嵌套循环 <a class="header-anchor" href="#_5-5-嵌套循环" aria-label="Permalink to &quot;5.5 嵌套循环&quot;"></a></h2><h3 id="_5-5-1-概述" tabindex="-1">5.5.1 概述 <a class="header-anchor" href="#_5-5-1-概述" aria-label="Permalink to &quot;5.5.1 概述&quot;"></a></h3><ul><li>所谓的嵌套循环,是指一个循环结构 A 的循环体是另一个循环结构 B 。例如for 循环里面还有一个for 循环,就是嵌套循环。</li><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(初始化语句①; 循环条件语句②; 迭代语句⑦) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(初始化语句③; 循环条件语句④; 迭代语句⑥) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 循环体语句⑤;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><ul><li>其中for 、while 、do-while 均可以作为外层循环或内层循环。 <ul><li>外层循环:循环结构 A</li><li>内层循环:循环结构 B</li></ul></li></ul><p><img src="/c/assets/10.DJkVOkw7.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 实际上,嵌套循环就是将内层循环当成外层循环的循环体。当只有内层循环的循环条件为 false ,才会完全跳出内层循环,才可结束外层的当次循环,开始下一次循环。</li><li>② 假设外层循环次数为 m 次,内层循环次数为 n 次,则内层循环体实际上需要执行 m × n 次。</li><li>③ 从二维图形的角度看,外层循环控制<code>行数</code>,内层循环控制<code>列数</code></li><li>④ 实际开发中,我们最多见到的嵌套循环是两层,一般不会出现超过三层的嵌套循环。如果将要出现,一定要停下来重新梳理业务逻辑,重新思考算法的实现,控制在三层以内;否则,可读性会很差。</li></ul></div><h3 id="_5-5-2-应用示例" tabindex="-1">5.5.2 应用示例 <a class="header-anchor" href="#_5-5-2-应用示例" aria-label="Permalink to &quot;5.5.2 应用示例&quot;"></a></h3><ul><li><p>需求:打印 5 行 <code>*</code> ,要求每行 6 个 <code>*</code></p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">i) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 6</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">j) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;* &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><h3 id="_5-5-3-应用示例" tabindex="-1">5.5.3 应用示例 <a class="header-anchor" href="#_5-5-3-应用示例" aria-label="Permalink to &quot;5.5.3 应用示例&quot;"></a></h3><ul><li><p>需求:打印 5 行直角三角形。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">i) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">j) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;* &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><h3 id="_5-5-4-应用示例" tabindex="-1">5.5.4 应用示例 <a class="header-anchor" href="#_5-5-4-应用示例" aria-label="Permalink to &quot;5.5.4 应用示例&quot;"></a></h3><ul><li><p>需求:打印 5 行倒直角三角形。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">i) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 6</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> -</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">j) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;* &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><h3 id="_5-5-5-应用示例" tabindex="-1">5.5.5 应用示例 <a class="header-anchor" href="#_5-5-5-应用示例" aria-label="Permalink to &quot;5.5.5 应用示例&quot;"></a></h3><ul><li><p>需求:打印 9 <code>×</code> 9 乘法表。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 9</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">i) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">j) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> × </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, i, j, i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> j);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><h2 id="_5-6-无限循环" tabindex="-1">5.6 无限循环 <a class="header-anchor" href="#_5-6-无限循环" aria-label="Permalink to &quot;5.6 无限循环&quot;"></a></h2><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">while</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">){</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ...</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(;;){</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ...</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 在开发中有的时候并不确定需要循环多少次就需要根据循环体内部的某些条件来控制循环的结束break</li><li>② 如果上述的循环结构不能终止,就会构成死循环;所以,在实际开发中,要避免出现死循环!!!</li></ul></div><ul><li>示例:从键盘读入个数不确定的整数,并判断读入的正数和负数的个数,输入为 0 时结束程序</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 记录输入的整数</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 记录正数个数</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> positiveCount </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 记录负数个数</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> negativeCount </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> while</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">true</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入一个整数:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">num);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> positiveCount</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> negativeCount</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;程序结束!</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;正数的个数:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, positiveCount);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;负数的个数:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, negativeCount);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br></div></div><h2 id="_5-7-跳转控制语句" tabindex="-1">5.7 跳转控制语句 <a class="header-anchor" href="#_5-7-跳转控制语句" aria-label="Permalink to &quot;5.7 跳转控制语句&quot;"></a></h2><h3 id="_5-7-1-break" tabindex="-1">5.7.1 break <a class="header-anchor" href="#_5-7-1-break" aria-label="Permalink to &quot;5.7.1 break&quot;"></a></h3><ul><li>break 的使用场景break 语句用于终止某个语句块的执行用在switch语句或者循环语句中。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>break 一旦执行,就结束(或跳出)当前循环结构;并且,此关键字的后面,不能声明其它语句。</p></div><ul><li>流程图,如下所示:</li></ul><p><img src="/c/assets/11.Bkdbe2NL.png" alt="" loading="lazy"></p><ul><li>示例:打印 0 ~ 10 ,如果遇到 <code>3</code> ,就停止打印</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">i) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, i);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;程序结束!</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><ul><li>示例:编写程序,要求输入一个数字,判断该数字是否是质数</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> bool</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> isFlag </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> false</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> do</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入一个整数(必须大于 1 &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">num);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;输入的数字不是合法,请重新输入!!!</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> isFlag </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> true</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> isFlag </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> false</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">while</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (isFlag);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> bool</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> isPrime </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> true</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> isPrime </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> false</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (isPrime) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 是一个质数</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 不是一个质数</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;程序结束!</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br></div></div><h3 id="_5-7-2-continue" tabindex="-1">5.7.2 continue <a class="header-anchor" href="#_5-7-2-continue" aria-label="Permalink to &quot;5.7.2 continue&quot;"></a></h3><ul><li>continue 的使用场景continue 语句用于结束本次循环,继续执行下一次循环。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>continue 一旦执行,就结束(或跳出)当次循环结构;并且,此关键字的后面,不能声明其它语句。</p></div><ul><li>流程图,如下所示:</li></ul><p><img src="/c/assets/12.D2yeCvfw.png" alt="" loading="lazy"></p><ul><li>示例:打印 0 ~ 10 ,如果遇到 <code>3</code> ,就继续下一次打印</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">i) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> continue</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, i);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;程序结束!</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><ul><li>示例:输出 100 以内(包括 100的数字跳过那些 7 的倍数或包含 7 的数字</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 100</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 7</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ||</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 7</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ||</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 7</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> continue</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, i);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;程序结束!</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><h3 id="_5-7-3-return" tabindex="-1">5.7.3 return <a class="header-anchor" href="#_5-7-3-return" aria-label="Permalink to &quot;5.7.3 return&quot;"></a></h3><ul><li>return :并非专门用于结束循环的,它的功能是结束一个方法。当一个方法执行到一个 return 语句的时候,这个方法将被结束。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>和 break 和 continue 不同的是return 直接结束整个方法,不管这个 return 处于多少层循环之内。</p></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 100</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 7</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ||</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 7</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ||</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 7</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 结束整个函数或方法</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, i);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;程序结束!</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div></div></div></main><footer class="VPDocFooter" data-v-39a288b8 data-v-e257564d><!--[--><!--]--><div class="edit-info" data-v-e257564d><!----><div class="last-updated" data-v-e257564d><p class="VPLastUpdated" data-v-e257564d data-v-e98dd255>上次更新: <time datetime="2024-08-06T08:32:38.000Z" data-v-e98dd255></time></p></div></div><nav class="prev-next" aria-labelledby="doc-footer-aria-label" data-v-e257564d><span class="visually-hidden" id="doc-footer-aria-label" data-v-e257564d>Pager</span><div class="pager" data-v-e257564d><a class="VPLink link pager-link prev" href="/c/notes/01_c-basic/03_xdx/" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>上一篇</span><span class="title" data-v-e257564d>数据类型和运算符</span><!--]--></a></div><div class="pager" data-v-e257564d><a class="VPLink link pager-link next" href="/c/notes/01_c-basic/05_xdx/" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>下一篇</span><span class="title" data-v-e257564d>数组</span><!--]--></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><footer class="VPFooter has-sidebar" data-v-5d98c3a5 data-v-e315a0ad><div class="container" data-v-e315a0ad><p class="message" data-v-e315a0ad>Released under the MIT License.</p><p class="copyright" data-v-e315a0ad>Copyright © 2024 许大仙</p></div></footer><!--[--><!--]--></div></div>
<script>window.__VP_HASH_MAP__=JSON.parse("{\"index.md\":\"Dga0tMF5\",\"notes_01_c-basic_00_xdx_index.md\":\"BRC7slaL\",\"notes_01_c-basic_01_xdx_index.md\":\"DvCUr2L0\",\"notes_01_c-basic_02_xdx_index.md\":\"CC2Mg9VD\",\"notes_01_c-basic_03_xdx_index.md\":\"CcATnhKW\",\"notes_01_c-basic_04_xdx_index.md\":\"DABEMZSO\",\"notes_01_c-basic_05_xdx_index.md\":\"CGbN5wss\",\"notes_01_c-basic_06_xdx_index.md\":\"CIGNaKYV\",\"notes_04_linux_01_xdx_index.md\":\"C9IatKsj\",\"notes_about_index.md\":\"DLuQgC_8\",\"notes_index.md\":\"CeV-uJ5V\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"zh-CN\",\"dir\":\"ltr\",\"title\":\"许大仙\",\"titleTemplate\":\"Hi终于等到你\",\"description\":\"许大仙前端、Java、大数据、云原生\",\"base\":\"/c/\",\"head\":[],\"router\":{\"prefetchLinks\":true},\"appearance\":true,\"themeConfig\":{\"lastUpdatedText\":\"上次更新\",\"returnToTopLabel\":\"返回顶部\",\"search\":{\"provider\":\"local\"},\"logo\":\"/logo.svg\",\"nav\":[{\"text\":\"首页\",\"link\":\"https://aexiar.github.io/\"},{\"text\":\"计组6件套\",\"link\":\"https://aexiar.github.io/coa6/notes/\"},{\"text\":\"编程语言\",\"items\":[{\"text\":\"c/c++\",\"link\":\"/notes/\"},{\"text\":\"前端\",\"link\":\"https://aexiar.github.io/web-design/notes/\"},{\"text\":\"Java\",\"link\":\"https://aexiar.github.io/java/notes/\"},{\"text\":\"大数据\",\"link\":\"https://aexiar.github.io/big-data/notes/\"},{\"text\":\"云原生\",\"link\":\"https://aexiar.github.io/linux/notes/\"},{\"text\":\"Go\",\"link\":\"https://aexiar.github.io/go/notes/\"},{\"text\":\"Python\",\"link\":\"https://aexiar.github.io/python/notes/\"}]},{\"text\":\"数据库\",\"link\":\"https://aexiar.github.io/db/notes/\"},{\"text\":\"开源软件\",\"link\":\"https://aexiar.github.io/open-software/notes/\"},{\"text\":\"关于我\",\"link\":\"/notes/about/\"}],\"sidebar\":{\"/notes/\":[{\"text\":\"C 语言基础\",\"collapsed\":true,\"items\":[{\"text\":\"编程基础\",\"link\":\"/notes/01_c-basic/00_xdx/\"},{\"text\":\"C 语言入门\",\"link\":\"/notes/01_c-basic/01_xdx/\"},{\"text\":\"变量和进制\",\"link\":\"/notes/01_c-basic/02_xdx/\"},{\"text\":\"数据类型和运算符\",\"link\":\"/notes/01_c-basic/03_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/01_c-basic/04_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/01_c-basic/05_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/01_c-basic/06_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/01_c-basic/07_xdx/\"},{\"text\":\"预处理器\",\"link\":\"/notes/01_c-basic/08_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/01_c-basic/09_xdx/\"},{\"text\":\"内存管理\",\"link\":\"/notes/01_c-basic/10_xdx/\"},{\"text\":\"文件操作\",\"link\":\"/notes/01_c-basic/11_xdx/\"},{\"text\":\"调试工具和调试技巧gdb和make\",\"link\":\"/notes/02_c-basic/13_xdx/\"},{\"text\":\"常用库函数\",\"link\":\"/notes/01_c-basic/13_xdx/\"}]},{\"text\":\"C 语言高级\",\"collapsed\":true,\"items\":[{\"text\":\"变量和内存分布\",\"link\":\"/notes/02_c-advance/01_xdx/\"},{\"text\":\"指针强化\",\"link\":\"/notes/02_c-advance/02_xdx/\"},{\"text\":\"结构体和文件的高级用法\",\"link\":\"/notes/02_c-advance/03_xdx/\"},{\"text\":\"链表和回调函数\",\"link\":\"/notes/02_c-advance/04_xdx/\"},{\"text\":\"编译过程和面向接口\",\"link\":\"/notes/02_c-advance/05_xdx/\"}]},{\"text\":\"项目构建工具\",\"collapsed\":true,\"items\":[{\"text\":\"meson\",\"collapsed\":true,\"items\":[{\"text\":\"meson 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Cmake\",\"collapsed\":true,\"items\":[{\"text\":\"Cmake 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Conan \",\"link\":\"/notes/03_build/01_${commonDirectoryName}/\"},{\"text\":\"Gradle\",\"collapsed\":true,\"items\":[{\"text\":\"Gradle 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]}]},{\"text\":\"Linux\",\"collapsed\":true,\"items\":[{\"text\":\"Linux 初识和安装\",\"link\":\"/notes/04_linux/01_xdx/\"}]},{\"text\":\"C++ 基础\",\"collapsed\":true,\"items\":[{\"text\":\"C++ 入门\",\"link\":\"/notes/05_cpp/01_xdx/\"},{\"text\":\"变量、数据类型、运算符\",\"link\":\"/notes/05_cpp/02_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/05_cpp/03_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/05_cpp/04_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/05_cpp/05_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/05_cpp/06_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/05_cpp/07_xdx/\"},{\"text\":\"类和对象\",\"link\":\"/notes/05_cpp/08_xdx/\"},{\"text\":\"C++ 引用\",\"link\":\"/notes/05_cpp/09_xdx/\"},{\"text\":\"继承和派生\",\"link\":\"/notes/05_cpp/10_xdx/\"},{\"text\":\"C++ 多态和虚函数\",\"link\":\"/notes/05_cpp/11_xdx/\"},{\"text\":\"运算符重载\",\"link\":\"/notes/05_cpp/12_xdx/\"},{\"text\":\"模板\",\"link\":\"/notes/05_cpp/13_xdx/\"},{\"text\":\"C++ 异常\",\"link\":\"/notes/05_cpp/14_xdx/\"},{\"text\":\"面向对象进阶\",\"link\":\"/notes/05_cpp/15_xdx/\"},{\"text\":\"文件操作和 IO 流\",\"link\":\"/notes/05_cpp/16_xdx/\"},{\"text\":\"STL标准模板库\",\"link\":\"/notes/05_cpp/17_xdx/\"}]},{\"text\":\"C++ 高级\",\"collapsed\":true,\"items\":[]},{\"text\":\"QT 桌面开发\",\"collapsed\":true,\"items\":[]},{\"text\":\"Linux 高并发服务器开发\",\"collapsed\":true,\"items\":[]}]},\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/Aurorxa\"}],\"docFooter\":{\"prev\":\"上一篇\",\"next\":\"下一篇\"},\"darkModeSwitchLabel\":\"深浅模式\",\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2024 许大仙\"},\"outline\":{\"level\":[1,6],\"label\":\"目录\"},\"outlineTitle\":\"当前页大纲\"},\"locales\":{},\"scrollOffset\":134,\"cleanUrls\":false}");</script>
<div id="app"><div class="Layout" data-v-5d98c3a5><!--[--><!--]--><!--[--><span tabindex="-1" data-v-0f60ec36></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-0f60ec36> Skip to content </a><!--]--><!----><header class="VPNav" data-v-5d98c3a5 data-v-ae24b3ad><div class="VPNavBar has-sidebar top" data-v-ae24b3ad data-v-6aa21345><div class="wrapper" data-v-6aa21345><div class="container" data-v-6aa21345><div class="title" data-v-6aa21345><div class="VPNavBarTitle has-sidebar" data-v-6aa21345 data-v-ab179fa1><a class="title" href="/c/" data-v-ab179fa1><!--[--><!--]--><!--[--><img class="VPImage logo" src="/c/logo.svg" alt data-v-8426fc1a><!--]--><span data-v-ab179fa1>许大仙</span><!--[--><!--]--></a></div></div><div class="content" data-v-6aa21345><div class="content-body" data-v-6aa21345><!--[--><!--]--><div class="VPNavBarSearch search" data-v-6aa21345><!--[--><!----><div id="local-search"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><span class="vp-icon DocSearch-Search-Icon"></span><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key">K</kbd></span></button></div><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-6aa21345 data-v-dc692963><span id="main-nav-aria-label" class="visually-hidden" data-v-dc692963> Main Navigation </span><!--[--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>首页</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/coa6/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>计组6件套</span><!--]--></a><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-dc692963 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-b6c34ac9><span class="text" data-v-b6c34ac9><!----><span data-v-b6c34ac9>编程语言</span><span class="vpi-chevron-down text-icon" data-v-b6c34ac9></span></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><div class="items" data-v-b98bc113><!--[--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link" href="/c/notes/" data-v-43f1e123><!--[-->c/c++<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/web-design/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->前端<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/java/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Java<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/big-data/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->大数据<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/linux/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->云原生<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/go/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Go<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/python/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Python<!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/db/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>数据库</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/open-software/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>开源软件</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/c/notes/about/" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>关于我</span><!--]--></a><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-6aa21345 data-v-6c893767><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-6c893767 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-6aa21345 data-v-0394ad82 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-6aa21345 data-v-bb2aa2f0 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-b6c34ac9><span class="vpi-more-horizontal icon" data-v-b6c34ac9></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><!----><!--[--><!--[--><!----><div class="group" data-v-bb2aa2f0><div class="item appearance" data-v-bb2aa2f0><p class="label" data-v-bb2aa2f0>深浅模式</p><div class="appearance-action" data-v-bb2aa2f0><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-bb2aa2f0 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div></div></div><div class="group" data-v-bb2aa2f0><div class="item social-links" data-v-bb2aa2f0><div class="VPSocialLinks social-links-list" data-v-bb2aa2f0 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div></div></div><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-6aa21345 data-v-e5dd9c1c><span class="container" data-v-e5dd9c1c><span class="top" data-v-e5dd9c1c></span><span class="middle" data-v-e5dd9c1c></span><span class="bottom" data-v-e5dd9c1c></span></span></button></div></div></div></div><div class="divider" data-v-6aa21345><div class="divider-line" data-v-6aa21345></div></div></div><!----></header><div class="VPLocalNav has-sidebar empty" data-v-5d98c3a5 data-v-a6f0e41e><div class="container" data-v-a6f0e41e><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-a6f0e41e><span class="vpi-align-left menu-icon" data-v-a6f0e41e></span><span class="menu-text" data-v-a6f0e41e>Menu</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-a6f0e41e data-v-17a5e62e><button data-v-17a5e62e>返回顶部</button><!----></div></div></div><aside class="VPSidebar" data-v-5d98c3a5 data-v-319d5ca6><div class="curtain" data-v-319d5ca6></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-319d5ca6><span class="visually-hidden" id="sidebar-aria-label" data-v-319d5ca6> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible has-active" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/00_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编程基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C 语言入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和进制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数据类型和运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>大话小数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>预处理器</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>内存管理</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/12_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-basic/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>调试工具和调试技巧gdb和make</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/14_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>常用库函数</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言高级</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和内存分布</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针强化</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>结构体和文件的高级用法</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>链表和回调函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编译过程和面向接口</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>项目构建工具</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>meson</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>meson 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Cmake</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Cmake 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_${commonDirectoryName}/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Conan </p><!--]--></a><!----></div><!----></div><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Gradle</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Gradle 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>Linux</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/04_linux/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Linux 初识和安装</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C++ 基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量、数据类型、运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>类和对象</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 引用</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>继承和派生</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 多态和虚函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/12_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>运算符重载</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>模板</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/14_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 异常</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/15_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>面向对象进阶</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/16_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作和 IO 流</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/17_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>STL标准模板库</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>C++ 高级</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>QT 桌面开发</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>Linux 高并发服务器开发</p><!----></div><!----></div></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-5d98c3a5 data-v-1428d186><div class="VPDoc has-sidebar has-aside" data-v-1428d186 data-v-39a288b8><!--[--><!--]--><div class="container" data-v-39a288b8><div class="aside" data-v-39a288b8><div class="aside-curtain" data-v-39a288b8></div><div class="aside-container" data-v-39a288b8><div class="aside-content" data-v-39a288b8><div class="VPDocAside" data-v-39a288b8 data-v-3f215769><!--[--><!--]--><!--[--><!--]--><nav aria-labelledby="doc-outline-aria-label" class="VPDocAsideOutline" data-v-3f215769 data-v-a5bbad30><div class="content" data-v-a5bbad30><div class="outline-marker" data-v-a5bbad30></div><div aria-level="2" class="outline-title" id="doc-outline-aria-label" role="heading" data-v-a5bbad30>目录</div><ul class="VPDocOutlineItem root" data-v-a5bbad30 data-v-b933a997><!--[--><!--]--></ul></div></nav><!--[--><!--]--><div class="spacer" data-v-3f215769></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-39a288b8><div class="content-container" data-v-39a288b8><!--[--><!--]--><main class="main" data-v-39a288b8><div style="position:relative;" class="vp-doc _c_notes_01_c-basic_04_xdx_" data-v-39a288b8><div></div></div></main><footer class="VPDocFooter" data-v-39a288b8 data-v-e257564d><!--[--><!--]--><div class="edit-info" data-v-e257564d><!----><div class="last-updated" data-v-e257564d><p class="VPLastUpdated" data-v-e257564d data-v-e98dd255>上次更新: <time datetime="2024-08-27T03:11:14.000Z" data-v-e98dd255></time></p></div></div><nav class="prev-next" aria-labelledby="doc-footer-aria-label" data-v-e257564d><span class="visually-hidden" id="doc-footer-aria-label" data-v-e257564d>Pager</span><div class="pager" data-v-e257564d><a class="VPLink link pager-link prev" href="/c/notes/01_c-basic/03_xdx/" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>上一篇</span><span class="title" data-v-e257564d>数据类型和运算符</span><!--]--></a></div><div class="pager" data-v-e257564d><a class="VPLink link pager-link next" href="/c/notes/01_c-basic/05_xdx/" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>下一篇</span><span class="title" data-v-e257564d>流程控制</span><!--]--></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><footer class="VPFooter has-sidebar" data-v-5d98c3a5 data-v-e315a0ad><div class="container" data-v-e315a0ad><p class="message" data-v-e315a0ad>Released under the MIT License.</p><p class="copyright" data-v-e315a0ad>Copyright © 2024 许大仙</p></div></footer><!--[--><!--]--></div></div>
<script>window.__VP_HASH_MAP__=JSON.parse("{\"index.md\":\"Dga0tMF5\",\"notes_01_c-basic_00_xdx_index.md\":\"BRC7slaL\",\"notes_01_c-basic_01_xdx_index.md\":\"Fg4OXydV\",\"notes_01_c-basic_02_xdx_index.md\":\"CC2Mg9VD\",\"notes_01_c-basic_03_xdx_index.md\":\"Cw3Z19MO\",\"notes_01_c-basic_04_xdx_index.md\":\"ySxH8sG-\",\"notes_01_c-basic_05_xdx_index.md\":\"DUbOwEts\",\"notes_01_c-basic_06_xdx_index.md\":\"CV_r2WNu\",\"notes_01_c-basic_07_xdx_index.md\":\"CE9q5cmu\",\"notes_04_linux_01_xdx_index.md\":\"C9IatKsj\",\"notes_about_index.md\":\"DLuQgC_8\",\"notes_index.md\":\"CeV-uJ5V\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"zh-CN\",\"dir\":\"ltr\",\"title\":\"许大仙\",\"titleTemplate\":\"Hi终于等到你\",\"description\":\"许大仙前端、Java、大数据、云原生\",\"base\":\"/c/\",\"head\":[],\"router\":{\"prefetchLinks\":true},\"appearance\":true,\"themeConfig\":{\"lastUpdatedText\":\"上次更新\",\"returnToTopLabel\":\"返回顶部\",\"search\":{\"provider\":\"local\"},\"logo\":\"/logo.svg\",\"nav\":[{\"text\":\"首页\",\"link\":\"https://aexiar.github.io/\"},{\"text\":\"计组6件套\",\"link\":\"https://aexiar.github.io/coa6/notes/\"},{\"text\":\"编程语言\",\"items\":[{\"text\":\"c/c++\",\"link\":\"/notes/\"},{\"text\":\"前端\",\"link\":\"https://aexiar.github.io/web-design/notes/\"},{\"text\":\"Java\",\"link\":\"https://aexiar.github.io/java/notes/\"},{\"text\":\"大数据\",\"link\":\"https://aexiar.github.io/big-data/notes/\"},{\"text\":\"云原生\",\"link\":\"https://aexiar.github.io/linux/notes/\"},{\"text\":\"Go\",\"link\":\"https://aexiar.github.io/go/notes/\"},{\"text\":\"Python\",\"link\":\"https://aexiar.github.io/python/notes/\"}]},{\"text\":\"数据库\",\"link\":\"https://aexiar.github.io/db/notes/\"},{\"text\":\"开源软件\",\"link\":\"https://aexiar.github.io/open-software/notes/\"},{\"text\":\"关于我\",\"link\":\"/notes/about/\"}],\"sidebar\":{\"/notes/\":[{\"text\":\"C 语言基础\",\"collapsed\":true,\"items\":[{\"text\":\"编程基础\",\"link\":\"/notes/01_c-basic/00_xdx/\"},{\"text\":\"C 语言入门\",\"link\":\"/notes/01_c-basic/01_xdx/\"},{\"text\":\"变量和进制\",\"link\":\"/notes/01_c-basic/02_xdx/\"},{\"text\":\"数据类型和运算符\",\"link\":\"/notes/01_c-basic/03_xdx/\"},{\"text\":\"大话小数\",\"link\":\"/notes/01_c-basic/04_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/01_c-basic/05_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/01_c-basic/06_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/01_c-basic/07_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/01_c-basic/08_xdx/\"},{\"text\":\"预处理器\",\"link\":\"/notes/01_c-basic/09_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/01_c-basic/10_xdx/\"},{\"text\":\"内存管理\",\"link\":\"/notes/01_c-basic/11_xdx/\"},{\"text\":\"文件操作\",\"link\":\"/notes/01_c-basic/12_xdx/\"},{\"text\":\"调试工具和调试技巧gdb和make\",\"link\":\"/notes/02_c-basic/13_xdx/\"},{\"text\":\"常用库函数\",\"link\":\"/notes/01_c-basic/14_xdx/\"}]},{\"text\":\"C 语言高级\",\"collapsed\":true,\"items\":[{\"text\":\"变量和内存分布\",\"link\":\"/notes/02_c-advance/01_xdx/\"},{\"text\":\"指针强化\",\"link\":\"/notes/02_c-advance/02_xdx/\"},{\"text\":\"结构体和文件的高级用法\",\"link\":\"/notes/02_c-advance/03_xdx/\"},{\"text\":\"链表和回调函数\",\"link\":\"/notes/02_c-advance/04_xdx/\"},{\"text\":\"编译过程和面向接口\",\"link\":\"/notes/02_c-advance/05_xdx/\"}]},{\"text\":\"项目构建工具\",\"collapsed\":true,\"items\":[{\"text\":\"meson\",\"collapsed\":true,\"items\":[{\"text\":\"meson 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Cmake\",\"collapsed\":true,\"items\":[{\"text\":\"Cmake 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Conan \",\"link\":\"/notes/03_build/01_${commonDirectoryName}/\"},{\"text\":\"Gradle\",\"collapsed\":true,\"items\":[{\"text\":\"Gradle 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]}]},{\"text\":\"Linux\",\"collapsed\":true,\"items\":[{\"text\":\"Linux 初识和安装\",\"link\":\"/notes/04_linux/01_xdx/\"}]},{\"text\":\"C++ 基础\",\"collapsed\":true,\"items\":[{\"text\":\"C++ 入门\",\"link\":\"/notes/05_cpp/01_xdx/\"},{\"text\":\"变量、数据类型、运算符\",\"link\":\"/notes/05_cpp/02_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/05_cpp/03_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/05_cpp/04_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/05_cpp/05_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/05_cpp/06_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/05_cpp/07_xdx/\"},{\"text\":\"类和对象\",\"link\":\"/notes/05_cpp/08_xdx/\"},{\"text\":\"C++ 引用\",\"link\":\"/notes/05_cpp/09_xdx/\"},{\"text\":\"继承和派生\",\"link\":\"/notes/05_cpp/10_xdx/\"},{\"text\":\"C++ 多态和虚函数\",\"link\":\"/notes/05_cpp/11_xdx/\"},{\"text\":\"运算符重载\",\"link\":\"/notes/05_cpp/12_xdx/\"},{\"text\":\"模板\",\"link\":\"/notes/05_cpp/13_xdx/\"},{\"text\":\"C++ 异常\",\"link\":\"/notes/05_cpp/14_xdx/\"},{\"text\":\"面向对象进阶\",\"link\":\"/notes/05_cpp/15_xdx/\"},{\"text\":\"文件操作和 IO 流\",\"link\":\"/notes/05_cpp/16_xdx/\"},{\"text\":\"STL标准模板库\",\"link\":\"/notes/05_cpp/17_xdx/\"}]},{\"text\":\"C++ 高级\",\"collapsed\":true,\"items\":[]},{\"text\":\"QT 桌面开发\",\"collapsed\":true,\"items\":[]},{\"text\":\"Linux 高并发服务器开发\",\"collapsed\":true,\"items\":[]}]},\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/Aurorxa\"}],\"docFooter\":{\"prev\":\"上一篇\",\"next\":\"下一篇\"},\"darkModeSwitchLabel\":\"深浅模式\",\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2024 许大仙\"},\"outline\":{\"level\":[1,6],\"label\":\"目录\"},\"outlineTitle\":\"当前页大纲\"},\"locales\":{},\"scrollOffset\":134,\"cleanUrls\":false}");</script>
</body>
</html>

View File

@ -3,16 +3,16 @@
<head>
<meta charset="utf-8">
<title>第一章:数组的概念 | Hi终于等到你</title>
<title>第一章:概述 | Hi终于等到你</title>
<meta name="description" content="许大仙前端、Java、大数据、云原生">
<meta name="generator" content="VitePress v1.3.3">
<link rel="preload stylesheet" href="/c/assets/style.zDJ0OJGU.css" as="style">
<script type="module" src="/c/assets/app.Ca2FOFw4.js"></script>
<script type="module" src="/c/assets/app.1a4d5P-6.js"></script>
<link rel="preload" href="/c/assets/inter-roman-latin.Di8DUHzh.woff2" as="font" type="font/woff2" crossorigin="">
<link rel="modulepreload" href="/c/assets/chunks/theme.C6fZfLtk.js">
<link rel="modulepreload" href="/c/assets/chunks/theme.Ddh-lpYV.js">
<link rel="modulepreload" href="/c/assets/chunks/framework.hMCIpNYY.js">
<link rel="modulepreload" href="/c/assets/notes_01_c-basic_05_xdx_index.md.CGbN5wss.lean.js">
<link rel="modulepreload" href="/c/assets/notes_01_c-basic_05_xdx_index.md.DUbOwEts.lean.js">
<link rel="shortcut icon" href="/c//logo.svg">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="">
<script id="register-sw">"serviceWorker"in navigator&&navigator.serviceWorker.register("/sw.js");</script>
@ -22,707 +22,759 @@
<script id="check-mac-os">document.documentElement.classList.toggle("mac",/Mac|iPhone|iPod|iPad/i.test(navigator.platform));</script>
</head>
<body>
<div id="app"><div class="Layout" data-v-5d98c3a5><!--[--><!--]--><!--[--><span tabindex="-1" data-v-0f60ec36></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-0f60ec36> Skip to content </a><!--]--><!----><header class="VPNav" data-v-5d98c3a5 data-v-ae24b3ad><div class="VPNavBar has-sidebar top" data-v-ae24b3ad data-v-6aa21345><div class="wrapper" data-v-6aa21345><div class="container" data-v-6aa21345><div class="title" data-v-6aa21345><div class="VPNavBarTitle has-sidebar" data-v-6aa21345 data-v-ab179fa1><a class="title" href="/c/" data-v-ab179fa1><!--[--><!--]--><!--[--><img class="VPImage logo" src="/c/logo.svg" alt data-v-8426fc1a><!--]--><span data-v-ab179fa1>许大仙</span><!--[--><!--]--></a></div></div><div class="content" data-v-6aa21345><div class="content-body" data-v-6aa21345><!--[--><!--]--><div class="VPNavBarSearch search" data-v-6aa21345><!--[--><!----><div id="local-search"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><span class="vp-icon DocSearch-Search-Icon"></span><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key">K</kbd></span></button></div><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-6aa21345 data-v-dc692963><span id="main-nav-aria-label" class="visually-hidden" data-v-dc692963> Main Navigation </span><!--[--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>首页</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/coa6/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>计组6件套</span><!--]--></a><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-dc692963 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-b6c34ac9><span class="text" data-v-b6c34ac9><!----><span data-v-b6c34ac9>编程语言</span><span class="vpi-chevron-down text-icon" data-v-b6c34ac9></span></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><div class="items" data-v-b98bc113><!--[--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link" href="/c/notes/" data-v-43f1e123><!--[-->c/c++<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/web-design/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->前端<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/java/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Java<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/big-data/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->大数据<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/linux/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->云原生<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/go/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Go<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/python/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Python<!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/db/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>数据库</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/open-software/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>开源软件</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/c/notes/about/" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>关于我</span><!--]--></a><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-6aa21345 data-v-6c893767><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-6c893767 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-6aa21345 data-v-0394ad82 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-6aa21345 data-v-bb2aa2f0 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-b6c34ac9><span class="vpi-more-horizontal icon" data-v-b6c34ac9></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><!----><!--[--><!--[--><!----><div class="group" data-v-bb2aa2f0><div class="item appearance" data-v-bb2aa2f0><p class="label" data-v-bb2aa2f0>深浅模式</p><div class="appearance-action" data-v-bb2aa2f0><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-bb2aa2f0 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div></div></div><div class="group" data-v-bb2aa2f0><div class="item social-links" data-v-bb2aa2f0><div class="VPSocialLinks social-links-list" data-v-bb2aa2f0 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div></div></div><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-6aa21345 data-v-e5dd9c1c><span class="container" data-v-e5dd9c1c><span class="top" data-v-e5dd9c1c></span><span class="middle" data-v-e5dd9c1c></span><span class="bottom" data-v-e5dd9c1c></span></span></button></div></div></div></div><div class="divider" data-v-6aa21345><div class="divider-line" data-v-6aa21345></div></div></div><!----></header><div class="VPLocalNav has-sidebar empty" data-v-5d98c3a5 data-v-a6f0e41e><div class="container" data-v-a6f0e41e><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-a6f0e41e><span class="vpi-align-left menu-icon" data-v-a6f0e41e></span><span class="menu-text" data-v-a6f0e41e>Menu</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-a6f0e41e data-v-17a5e62e><button data-v-17a5e62e>返回顶部</button><!----></div></div></div><aside class="VPSidebar" data-v-5d98c3a5 data-v-319d5ca6><div class="curtain" data-v-319d5ca6></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-319d5ca6><span class="visually-hidden" id="sidebar-aria-label" data-v-319d5ca6> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible has-active" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/00_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编程基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C 语言入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和进制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数据类型和运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>预处理器</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>内存管理</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-basic/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>调试工具和调试技巧gdb和make</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>常用库函数</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言高级</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和内存分布</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针强化</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>结构体和文件的高级用法</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>链表和回调函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编译过程和面向接口</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>项目构建工具</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>meson</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>meson 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Cmake</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Cmake 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_${commonDirectoryName}/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Conan </p><!--]--></a><!----></div><!----></div><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Gradle</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Gradle 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>Linux</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/04_linux/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Linux 初识和安装</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C++ 基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量、数据类型、运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>类和对象</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 引用</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>继承和派生</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 多态和虚函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/12_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>运算符重载</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>模板</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/14_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 异常</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/15_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>面向对象进阶</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/16_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作和 IO 流</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/17_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>STL标准模板库</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>C++ 高级</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>QT 桌面开发</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>Linux 高并发服务器开发</p><!----></div><!----></div></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-5d98c3a5 data-v-1428d186><div class="VPDoc has-sidebar has-aside" data-v-1428d186 data-v-39a288b8><!--[--><!--]--><div class="container" data-v-39a288b8><div class="aside" data-v-39a288b8><div class="aside-curtain" data-v-39a288b8></div><div class="aside-container" data-v-39a288b8><div class="aside-content" data-v-39a288b8><div class="VPDocAside" data-v-39a288b8 data-v-3f215769><!--[--><!--]--><!--[--><!--]--><nav aria-labelledby="doc-outline-aria-label" class="VPDocAsideOutline" data-v-3f215769 data-v-a5bbad30><div class="content" data-v-a5bbad30><div class="outline-marker" data-v-a5bbad30></div><div aria-level="2" class="outline-title" id="doc-outline-aria-label" role="heading" data-v-a5bbad30>目录</div><ul class="VPDocOutlineItem root" data-v-a5bbad30 data-v-b933a997><!--[--><!--]--></ul></div></nav><!--[--><!--]--><div class="spacer" data-v-3f215769></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-39a288b8><div class="content-container" data-v-39a288b8><!--[--><!--]--><main class="main" data-v-39a288b8><div style="position:relative;" class="vp-doc _c_notes_01_c-basic_05_xdx_" data-v-39a288b8><div><h1 id="第一章-数组的概念" tabindex="-1">第一章:数组的概念 <a class="header-anchor" href="#第一章-数组的概念" aria-label="Permalink to &quot;第一章:数组的概念&quot;"></a></h1><h2 id="_1-1-为什么需要数组" tabindex="-1">1.1 为什么需要数组? <a class="header-anchor" href="#_1-1-为什么需要数组" aria-label="Permalink to &quot;1.1 为什么需要数组?&quot;"></a></h2><h3 id="_1-1-1-需求分析-1" tabindex="-1">1.1.1 需求分析 1 <a class="header-anchor" href="#_1-1-1-需求分析-1" aria-label="Permalink to &quot;1.1.1 需求分析 1&quot;"></a></h3><ul><li>需要统计某公司 50 个员工的工资情况,例如:计算平均工资、最高工资等。如果使用之前的知识,我们需要声明 50 个变量来分别记录每位员工的工资,即:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(){</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num1 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num2 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num3 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ...</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入第 1 个员工的工资:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%lf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">num1);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入第 2 个员工的工资:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%lf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">num2);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入第 3 个员工的工资:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%lf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">num3);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ... </span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div><ul><li>这样会感觉特别机械和麻烦全是复制Ctrl + c和粘贴Ctrl + vCV 大法);此时,我们就可以将所有的<code>数据</code>全部存储到一个<code>容器(数组)</code>中进行统一管理,并进行其它的操作,如:求最值、求平均值等,如下所示:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(){</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 声明数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> double</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> nums</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">50</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 数组的长度</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(nums) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 使用 for 循环向数组中添加值</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length;i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">){</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入第 &amp;d 个员工的工资:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,i);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%lf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">num</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 其它操作,如:求最值,求平均值等</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ... </span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><h3 id="_1-1-2-需求分析-2" tabindex="-1">1.1.2 需求分析 2 <a class="header-anchor" href="#_1-1-2-需求分析-2" aria-label="Permalink to &quot;1.1.2 需求分析 2&quot;"></a></h3><ul><li>在现实生活中,我们会使用很多 APP 或微信小程序等,即:</li></ul><p><img src="/c/assets/1.CvTjP5jN.png" alt="" loading="lazy"></p><ul><li>同样的道理,如果我们使用变量来存储每个商品信息,那么就需要非常多的变量;但是,如果我们将这些<code>商品信息</code>都存储到一个<code>容器(数组)</code>中,进行统一管理;那么,之后的数据处理将会非常方便。</li></ul><h3 id="_1-1-3-容器的概念" tabindex="-1">1.1.3 容器的概念 <a class="header-anchor" href="#_1-1-3-容器的概念" aria-label="Permalink to &quot;1.1.3 容器的概念&quot;"></a></h3><ul><li><code>生活中的容器</code>:水杯(装水、饮料的容器)、衣柜(装衣服等物品的容器)、集装箱(装货物等物品的容器)。</li><li><code>程序中的容器</code>:将多个数据存储到一起,并且每个数据称为该容器中的元素。</li></ul><h2 id="_1-2-什么是数组" tabindex="-1">1.2 什么是数组? <a class="header-anchor" href="#_1-2-什么是数组" aria-label="Permalink to &quot;1.2 什么是数组?&quot;"></a></h2><ul><li>数组Array是将多个<code>相同数据类型</code><code>数据</code>按照一定的顺序排序的<code>集合</code>,并使用一个<code>标识符</code>命名,以及通过<code>编号(索引,亦称为下标)</code>的方式对这些数据进行统一管理。</li></ul><p><img src="/c/assets/2.BR4TvWzU.png" alt="" loading="lazy"></p><h2 id="_1-3-数组的相关概念" tabindex="-1">1.3 数组的相关概念 <a class="header-anchor" href="#_1-3-数组的相关概念" aria-label="Permalink to &quot;1.3 数组的相关概念&quot;"></a></h2><ul><li><code>数组名</code>:本质上是一个标识符常量,命名需要符合标识符规则和规范。</li><li><code>元素</code>:同一个数组中的元素必须是相同的数据类型。</li><li><code>索引(下标)</code>:从 0 开始的连续数字。</li><li><code>数组的长度</code>:就是元素的个数。</li></ul><h2 id="_1-4-数组的特点" tabindex="-1">1.4 数组的特点 <a class="header-anchor" href="#_1-4-数组的特点" aria-label="Permalink to &quot;1.4 数组的特点&quot;"></a></h2><ul><li>① 创建数组的时候,会在内存中开辟一整块<code>连续的空间</code>,占据空间的大小,取决于数组的长度和数组中元素的类型。</li><li>② 数组中的元素在内存中是依次紧密排列且有序的。</li><li>③ 数组一旦初始化完成,且长度就确定的,并且<code>数组的长度一旦确定,就不能更改</code></li><li>④ 我们可以直接通过索引(下标)来获取指定位置的元素,速度很快。</li><li>⑤ 数组名中引用的是这块连续空间的首地址。</li></ul><h1 id="第二章-数组的操作-⭐" tabindex="-1">第二章:数组的操作(⭐) <a class="header-anchor" href="#第二章-数组的操作-⭐" aria-label="Permalink to &quot;第二章:数组的操作(⭐)&quot;"></a></h1><h2 id="_2-1-数组的定义" tabindex="-1">2.1 数组的定义 <a class="header-anchor" href="#_2-1-数组的定义" aria-label="Permalink to &quot;2.1 数组的定义&quot;"></a></h2><h3 id="_2-1-1-动态初始化" tabindex="-1">2.1.1 动态初始化 <a class="header-anchor" href="#_2-1-1-动态初始化" aria-label="Permalink to &quot;2.1.1 动态初始化&quot;"></a></h3><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">数据类型 数组名[元素个数</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">|</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">长度];</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 数据类型:表示的是数组中每一个元素的数据类型。</li><li>② 数组名:必须符合标识符规则和规范。</li><li>③ 元素个数或长度:表示的是数组中最多可以容纳多少个元素(不能是负数、也不能是 0 )。</li></ul></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<div id="app"><div class="Layout" data-v-5d98c3a5><!--[--><!--]--><!--[--><span tabindex="-1" data-v-0f60ec36></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-0f60ec36> Skip to content </a><!--]--><!----><header class="VPNav" data-v-5d98c3a5 data-v-ae24b3ad><div class="VPNavBar has-sidebar top" data-v-ae24b3ad data-v-6aa21345><div class="wrapper" data-v-6aa21345><div class="container" data-v-6aa21345><div class="title" data-v-6aa21345><div class="VPNavBarTitle has-sidebar" data-v-6aa21345 data-v-ab179fa1><a class="title" href="/c/" data-v-ab179fa1><!--[--><!--]--><!--[--><img class="VPImage logo" src="/c/logo.svg" alt data-v-8426fc1a><!--]--><span data-v-ab179fa1>许大仙</span><!--[--><!--]--></a></div></div><div class="content" data-v-6aa21345><div class="content-body" data-v-6aa21345><!--[--><!--]--><div class="VPNavBarSearch search" data-v-6aa21345><!--[--><!----><div id="local-search"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><span class="vp-icon DocSearch-Search-Icon"></span><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key">K</kbd></span></button></div><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-6aa21345 data-v-dc692963><span id="main-nav-aria-label" class="visually-hidden" data-v-dc692963> Main Navigation </span><!--[--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>首页</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/coa6/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>计组6件套</span><!--]--></a><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-dc692963 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-b6c34ac9><span class="text" data-v-b6c34ac9><!----><span data-v-b6c34ac9>编程语言</span><span class="vpi-chevron-down text-icon" data-v-b6c34ac9></span></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><div class="items" data-v-b98bc113><!--[--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link" href="/c/notes/" data-v-43f1e123><!--[-->c/c++<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/web-design/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->前端<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/java/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Java<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/big-data/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->大数据<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/linux/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->云原生<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/go/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Go<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/python/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Python<!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/db/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>数据库</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/open-software/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>开源软件</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/c/notes/about/" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>关于我</span><!--]--></a><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-6aa21345 data-v-6c893767><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-6c893767 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-6aa21345 data-v-0394ad82 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-6aa21345 data-v-bb2aa2f0 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-b6c34ac9><span class="vpi-more-horizontal icon" data-v-b6c34ac9></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><!----><!--[--><!--[--><!----><div class="group" data-v-bb2aa2f0><div class="item appearance" data-v-bb2aa2f0><p class="label" data-v-bb2aa2f0>深浅模式</p><div class="appearance-action" data-v-bb2aa2f0><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-bb2aa2f0 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div></div></div><div class="group" data-v-bb2aa2f0><div class="item social-links" data-v-bb2aa2f0><div class="VPSocialLinks social-links-list" data-v-bb2aa2f0 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div></div></div><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-6aa21345 data-v-e5dd9c1c><span class="container" data-v-e5dd9c1c><span class="top" data-v-e5dd9c1c></span><span class="middle" data-v-e5dd9c1c></span><span class="bottom" data-v-e5dd9c1c></span></span></button></div></div></div></div><div class="divider" data-v-6aa21345><div class="divider-line" data-v-6aa21345></div></div></div><!----></header><div class="VPLocalNav has-sidebar empty" data-v-5d98c3a5 data-v-a6f0e41e><div class="container" data-v-a6f0e41e><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-a6f0e41e><span class="vpi-align-left menu-icon" data-v-a6f0e41e></span><span class="menu-text" data-v-a6f0e41e>Menu</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-a6f0e41e data-v-17a5e62e><button data-v-17a5e62e>返回顶部</button><!----></div></div></div><aside class="VPSidebar" data-v-5d98c3a5 data-v-319d5ca6><div class="curtain" data-v-319d5ca6></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-319d5ca6><span class="visually-hidden" id="sidebar-aria-label" data-v-319d5ca6> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible has-active" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/00_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编程基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C 语言入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和进制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数据类型和运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>大话小数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>预处理器</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>内存管理</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/12_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-basic/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>调试工具和调试技巧gdb和make</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/14_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>常用库函数</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言高级</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和内存分布</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针强化</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>结构体和文件的高级用法</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>链表和回调函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编译过程和面向接口</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>项目构建工具</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>meson</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>meson 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Cmake</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Cmake 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_${commonDirectoryName}/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Conan </p><!--]--></a><!----></div><!----></div><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Gradle</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Gradle 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>Linux</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/04_linux/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Linux 初识和安装</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C++ 基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量、数据类型、运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>类和对象</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 引用</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>继承和派生</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 多态和虚函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/12_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>运算符重载</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>模板</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/14_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 异常</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/15_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>面向对象进阶</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/16_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作和 IO 流</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/17_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>STL标准模板库</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>C++ 高级</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>QT 桌面开发</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>Linux 高并发服务器开发</p><!----></div><!----></div></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-5d98c3a5 data-v-1428d186><div class="VPDoc has-sidebar has-aside" data-v-1428d186 data-v-39a288b8><!--[--><!--]--><div class="container" data-v-39a288b8><div class="aside" data-v-39a288b8><div class="aside-curtain" data-v-39a288b8></div><div class="aside-container" data-v-39a288b8><div class="aside-content" data-v-39a288b8><div class="VPDocAside" data-v-39a288b8 data-v-3f215769><!--[--><!--]--><!--[--><!--]--><nav aria-labelledby="doc-outline-aria-label" class="VPDocAsideOutline" data-v-3f215769 data-v-a5bbad30><div class="content" data-v-a5bbad30><div class="outline-marker" data-v-a5bbad30></div><div aria-level="2" class="outline-title" id="doc-outline-aria-label" role="heading" data-v-a5bbad30>目录</div><ul class="VPDocOutlineItem root" data-v-a5bbad30 data-v-b933a997><!--[--><!--]--></ul></div></nav><!--[--><!--]--><div class="spacer" data-v-3f215769></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-39a288b8><div class="content-container" data-v-39a288b8><!--[--><!--]--><main class="main" data-v-39a288b8><div style="position:relative;" class="vp-doc _c_notes_01_c-basic_05_xdx_" data-v-39a288b8><div><h1 id="第一章-概述" tabindex="-1">第一章:概述 <a class="header-anchor" href="#第一章-概述" aria-label="Permalink to &quot;第一章:概述&quot;"></a></h1><ul><li><p><code>流程控制结构</code>是用来控制程序中<code>各语句执行顺序</code>的语句,并且可以将语句组合成能<code>完成一定功能</code><code>小逻辑模块</code></p></li><li><p>在程序设计中规定了<code>三种</code>流程结构,如下所示:</p><ul><li><code>顺序结构</code>:程序从上到下逐行执行,中间没有任何判断和跳转。</li><li><code>分支结构</code>:根据条件,有选择的执行某段代码。在 C 语言中,有 <code>if...else</code><code>switch...case</code> 两种分支语句。</li><li><code>循环结构</code>:根据循环条件,重复性的执行某段代码。在 C 语言中,有 <code>for</code><code>while</code><code>do...while</code> 三种循环结构。</li></ul></li><li><p>在生活中的<code>洗衣工厂</code>,就包含了上述的三种流程结构,如下所示:</p></li></ul><p><img src="/c/assets/1.CTMA-Poz.jpg" alt="" loading="lazy"></p><h1 id="第二章-顺序结构" tabindex="-1">第二章:顺序结构 <a class="header-anchor" href="#第二章-顺序结构" aria-label="Permalink to &quot;第二章:顺序结构&quot;"></a></h1><h2 id="_2-1-概述" tabindex="-1">2.1 概述 <a class="header-anchor" href="#_2-1-概述" aria-label="Permalink to &quot;2.1 概述&quot;"></a></h2><ul><li>程序从上到下逐行地执行,表达式语句都是顺序执行的,并且上一行对某个变量的修改对下一行会产生影响。</li></ul><p><img src="/c/assets/2.B2g4y1OY.png" alt="" loading="lazy"></p><h2 id="_2-2-应用示例" tabindex="-1">2.2 应用示例 <a class="header-anchor" href="#_2-2-应用示例" aria-label="Permalink to &quot;2.2 应用示例&quot;"></a></h2><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 先指定元素的个数和类型,再进行初始化</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> x </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> y </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;x = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, x);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // x = 1</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;y = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, y);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // y = 2</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 对 x 和 y 的值进行修改</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> x</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> y </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> x </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> y;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> x </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> x </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 给数组元素赋值</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 20</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 30</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;x = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, x);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // x = 20</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;y = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, y);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // y = 6</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><h3 id="_2-1-2-静态初始化-1" tabindex="-1">2.1.2 静态初始化 1 <a class="header-anchor" href="#_2-1-2-静态初始化-1" aria-label="Permalink to &quot;2.1.2 静态初始化 1&quot;"></a></h3><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">数据类型 数组名[元素个数</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">|</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">长度] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {元素1,元素2,...}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 静态部分初始化:如果数组初始化的元素个数<code>小于</code>数组声明的长度,那么就会从数组开始位置依次赋值,不够的就补 0 。</li><li>② 静态全部初始化:数组初始化的元素个数<code>等于</code>数组的长度。</li></ul></div><ul><li><p>技巧:</p><ul><li>在 CLion 中可以开启<code>聚合初始化</code>功能,即:</li></ul><p><img src="/c/assets/3.hr3pCY5b.png" alt="" loading="lazy"></p><ul><li>这样,在 CLion 中,将会显示数组初始化中的元素索引,即:</li></ul><p><img src="/c/assets/4.CgvWfxq4.png" alt="" loading="lazy"></p></li><li><p>示例:静态部分初识化</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br></div></div><h1 id="第三章-分支结构-⭐" tabindex="-1">第三章:分支结构(⭐) <a class="header-anchor" href="#第三章-分支结构-⭐" aria-label="Permalink to &quot;第三章:分支结构(⭐)&quot;"></a></h1><h2 id="_3-1-概述" tabindex="-1">3.1 概述 <a class="header-anchor" href="#_3-1-概述" aria-label="Permalink to &quot;3.1 概述&quot;"></a></h2><ul><li>根据特定条件执行不同的代码块,从而实现灵活的程序控制和更复杂的逻辑。</li></ul><h2 id="_3-2-单分支结构" tabindex="-1">3.2 单分支结构 <a class="header-anchor" href="#_3-2-单分支结构" aria-label="Permalink to &quot;3.2 单分支结构&quot;"></a></h2><h3 id="_3-2-1-概述" tabindex="-1">3.2.1 概述 <a class="header-anchor" href="#_3-2-1-概述" aria-label="Permalink to &quot;3.2.1 概述&quot;"></a></h3><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(条件表达式){</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 语句;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 在 C 语言中,严格意义上是没有 boolean 类型的,使用<code>非0</code> 表示<code>true</code><code>0</code> 表示<code>false</code></li><li>② 当条件表达式为真(<code>非0</code> ),就会执行代码块中的语句;否则,就不会执行代码块中的语句。</li></ul></div><ul><li>流程图,如下所示:</li></ul><p><img src="/c/assets/3.DEoM0p3m.png" alt="" loading="lazy"></p><h3 id="_3-2-2-应用示例" tabindex="-1">3.2.2 应用示例 <a class="header-anchor" href="#_3-2-2-应用示例" aria-label="Permalink to &quot;3.2.2 应用示例&quot;"></a></h3><ul><li><p>需求:成年人心率的正常范围是每分钟 60~100 次。体检时,如果心率不在此范围内,则提示需要做进一步的检查。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义数组和部分初始化:</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 会将给定的值从数组的开始位置一个个的赋值,没有赋值的地方,用 0 填充</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> heartBeats </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入您的心率:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">heartBeats);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><ul><li>示例:静态全部初始化</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义数组和全部初始化:数组初始化的元素个数等于数组的长度。</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><h3 id="_2-1-3-静态初始化-2" tabindex="-1">2.1.3 静态初始化 2 <a class="header-anchor" href="#_2-1-3-静态初始化-2" aria-label="Permalink to &quot;2.1.3 静态初始化 2&quot;"></a></h3><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">数据类型 数组名</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {元素1,元素2,...}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>没有给出数组中元素的个数,将由系统根据初始化的元素,自动推断出数组中元素的个数。</p></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 指定元素的类型,不指定元素个数,同时进行初始化</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><h2 id="_2-2-访问数组元素" tabindex="-1">2.2 访问数组元素 <a class="header-anchor" href="#_2-2-访问数组元素" aria-label="Permalink to &quot;2.2 访问数组元素&quot;"></a></h2><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">数组名[索引</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">|</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">下标];</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>假设数组 <code>arr</code> 有 n 个元素,如果使用的数组的下标 <code>&lt; 0</code><code>&gt; n-1</code> ,那么将会产生数组越界访问,即超出了数组合法空间的访问;那么,数组的索引范围是 <code>[0,arr.length - 1]</code></p></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 先指定元素的个数和类型,再进行初始化</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 给数组元素赋值</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 20</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 30</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 访问数组元素</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[0] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[0] = 10</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[1] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[1] = 20</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[2] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[2] = 30</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br></div></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义数组和部分初始化:</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 会将给定的值从数组的开始位置一个个的赋值,没有赋值的地方,用 0 填充</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 访问数组元素</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[0] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[0] = 1</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[1] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[1] = 2</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[2] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[2] = 0</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[3] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[3] = 0</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[4] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[4] = 0</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 指定元素的类型,不指定元素个数,同时进行初始化</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 访问数组元素</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[0] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[0] = 1</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[1] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[1] = 2</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[2] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[2] = 3</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[3] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[3] = 4</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[4] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[4] = 5</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义数组和全部初始化:数组初始化的元素个数等于数组的长度。</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 访问数组元素</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[0] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[0] = 1</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[1] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[1] = 2</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[2] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[2] = 3</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[3] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[3] = 4</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[4] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[4] = 5</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><h2 id="_2-3-数组越界" tabindex="-1">2.3 数组越界 <a class="header-anchor" href="#_2-3-数组越界" aria-label="Permalink to &quot;2.3 数组越界&quot;"></a></h2><ul><li>数组下标必须在指定范围内使用,超出范围视为越界。</li></ul><p><img src="/c/assets/5.DSekQATc.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① C 语言是不会做数组下标越界的检查,并且编译器也不会报错;但是,编译器不报错,并不意味着程序就是正确!</li><li>② 在其它高级编程语言Java、JavaScript、Rust 等中,如果数组越界访问,编译器是会直接报错的!!!</li></ul></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义数组和全部初始化:数组初始化的元素个数等于数组的长度。</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 访问数组元素</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[0] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[0] = 1</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[1] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[1] = 2</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[2] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[2] = 3</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[3] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[3] = 4</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[4] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[4] = 5</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[-1] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 得到的是不确定的结果</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[5] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 得到的是不确定的结果</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br></div></div><h2 id="_2-4-计算数组的长度" tabindex="-1">2.4 计算数组的长度 <a class="header-anchor" href="#_2-4-计算数组的长度" aria-label="Permalink to &quot;2.4 计算数组的长度&quot;"></a></h2><ul><li>数组长度(元素个数)是在数组定义的时候明确指定且固定的,我们不能在运行的时候直接获取数组长度;但是,我们可以通过 sizeof 运算符间接计算出数组的长度。</li><li>计算步骤,如下所示: <ul><li>① 使用 sizeof 运算符计算出整个数组的字节长度。</li><li>② 由于数组成员是同一数据类型;那么,每个元素的字节长度一定相等,那么<code>数组的长度 = 整个数组的字节长度 ÷ 单个元素的字节长度 </code></li></ul></li></ul><p><img src="/c/assets/6.DjtEKfCa.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 在很多编程语言中都内置了获取数组的长度的属性或方法Java 中的 arr.length 或 Rust 的 arr.len()。</li><li>② 但是C 语言没有内置的获取数组长度的属性或方法,只能通过 sizeof 运算符间接来计算得到。</li><li>③ 数组一旦<code>声明</code><code>定义</code>,其<code>长度</code><code>固定</code>了,<code>不能动态变化</code></li></ul></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义数组和全部初始化:数组初始化的元素个数等于数组的长度。</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 计算数组的长度</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> size_t</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(arr) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 遍历数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i]);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (heartBeats </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 60</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ||</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> heartBeats </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 100</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;您的心率不在正常范围内,请做进一步的检查。</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;体检结束!!!&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div><h2 id="_2-5-遍历数组" tabindex="-1">2.5 遍历数组 <a class="header-anchor" href="#_2-5-遍历数组" aria-label="Permalink to &quot;2.5 遍历数组&quot;"></a></h2><ul><li><p>遍历数组是指按顺序访问数组中的每个元素,以便读取或修改它们,编程中一般使用循环结构对数组进行遍历。</p></li><li><p>示例:声明一个存储有 12、2、31、24、15、36、67、108、29、51 的数组,并遍历数组所有元素</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><h3 id="_3-2-3-应用示例" tabindex="-1">3.2.3 应用示例 <a class="header-anchor" href="#_3-2-3-应用示例" aria-label="Permalink to &quot;3.2.3 应用示例&quot;"></a></h3><ul><li><p>需求:根据年龄判断,如果是未成年人,则提示 &quot;未成年人请在家长陪同下访问!&quot;</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义数组并初始化</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">31</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">24</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">15</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">36</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">67</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">108</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">29</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">51</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> age </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入你的年龄:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">age);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 计算数组的长度</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> size_t</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(arr) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 遍历数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i]);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (age </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 18</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;未成年人请在家长陪同下访问!</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;欢迎继续访问!&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div><ul><li>示例:声明长度为 10 的 int 类型数组,给数组元素依次赋值为 0 ~ 9 ,并遍历数组所有元素</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><h2 id="_3-3-双分支结构" tabindex="-1">3.3 双分支结构 <a class="header-anchor" href="#_3-3-双分支结构" aria-label="Permalink to &quot;3.3 双分支结构&quot;"></a></h2><h3 id="_3-3-1-概述" tabindex="-1">3.3.1 概述 <a class="header-anchor" href="#_3-3-1-概述" aria-label="Permalink to &quot;3.3.1 概述&quot;"></a></h3><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(条件表达式) { </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 语句块1;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 语句块2;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 在 C 语言中,严格意义上是没有 boolean 类型的,使用<code>非0</code> 表示<code>true</code><code>0</code> 表示<code>false</code></li><li>② 当条件表达式为真(<code>非0</code> ),就会执行代码块 1 中的语句;否则,执行代码块 2 中的语句。</li></ul></div><ul><li>流程图,如下所示:</li></ul><p><img src="/c/assets/4.DxEoA7Ht.png" alt="" loading="lazy"></p><h3 id="_3-3-2-应用示例" tabindex="-1">3.3.2 应用示例 <a class="header-anchor" href="#_3-3-2-应用示例" aria-label="Permalink to &quot;3.3.2 应用示例&quot;"></a></h3><ul><li><p>需求:判断一个整数,是奇数还是偶数。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 计算数组的长度</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> size_t</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(arr) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 给数组的每个元素赋值</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 遍历数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br></div></div><h2 id="_2-6-一维数组的内存分析" tabindex="-1">2.6 一维数组的内存分析 <a class="header-anchor" href="#_2-6-一维数组的内存分析" aria-label="Permalink to &quot;2.6 一维数组的内存分析&quot;"></a></h2><h3 id="_2-6-1-数组内存图" tabindex="-1">2.6.1 数组内存图 <a class="header-anchor" href="#_2-6-1-数组内存图" aria-label="Permalink to &quot;2.6.1 数组内存图&quot;"></a></h3><ul><li>假设数组是如下的定义:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><ul><li>那么,对应的内存结构,如下所示:</li></ul><p><img src="/c/assets/7.BTWPdsCm.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 数组名 <code>arr</code> 就是记录该数组的首地址,即 <code>arr[0]</code> 的地址。</li><li>② 数组中的各个元素是连续分布的,假设 <code>arr[0]</code> 的地址是 <code>0xdea7bff880</code>,则 <code>arr[1] 的地址 = arr[0] 的地址 + int 字节数4 = 0xdea7bff880 + 4 = 0xdea7bff884</code> ,依次类推...</li></ul></div><ul><li>在 C 语言中,我们可以通过 <code>&amp;arr</code><code>&amp;arr[0]</code> 等形式获取数组或数组元素的地址,即:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 计算数组的长度</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> size_t</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(arr) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 给数组的每个元素赋值</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;数组的地址是 = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%p\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, arr);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 遍历数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;数组元素 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 的地址是 = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%p\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i], </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br></div></div><h3 id="_2-6-2-数组的注意事项" tabindex="-1">2.6.2 数组的注意事项 <a class="header-anchor" href="#_2-6-2-数组的注意事项" aria-label="Permalink to &quot;2.6.2 数组的注意事项&quot;"></a></h3><ul><li><code>C 语言规定,数组一旦声明,数组名指向的地址将不可更改</code>。因为在声明数组的时候,编译器会自动会数组分配内存地址,这个地址和数组名是绑定的,不可更改。</li></ul><div class="warning custom-block github-alert"><p class="custom-block-title">WARNING</p><p></p><p>如果之后试图更改数组名对应的地址,编译器就会报错。</p></div><ul><li>示例:错误演示</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> num</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 声明数组</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 使用大括号重新赋值是不允许的,必须在数组声明的时候赋值,否则编译将会报错</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">} ;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 报错</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><ul><li>示例:错误演示</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 使用大括号重新赋值是不允许的,必须在数组声明的时候赋值,否则编译将会报错</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">6</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 报错</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><ul><li>示例:错误演示</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> num</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> NULL</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 报错,需要和 Java 区别一下,在 C 中不可以</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><ul><li>示例:错误演示</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> a</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">} </span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> b</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> a ;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 报错,需要和 Java 区别一下,在 C 中不可以</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h2 id="_2-7-数组应用案例" tabindex="-1">2.7 数组应用案例 <a class="header-anchor" href="#_2-7-数组应用案例" aria-label="Permalink to &quot;2.7 数组应用案例&quot;"></a></h2><h3 id="_2-7-1-应用示例" tabindex="-1">2.7.1 应用示例 <a class="header-anchor" href="#_2-7-1-应用示例" aria-label="Permalink to &quot;2.7.1 应用示例&quot;"></a></h3><ul><li><p>需求:计算数组中所有元素的和以及平均数。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义数组并初始化</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">31</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">24</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">15</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">36</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">67</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">108</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">29</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">51</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 计算数组的长度</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> size_t</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(arr) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 变量保存总和</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> sum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 遍历数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> sum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i];</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> avg </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)sum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;数组的和为:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, sum);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 数组的和为375</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;数组的平均值为:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%.2lf\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, avg);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> //数组的平均值为37.50</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br></div></div><h3 id="_2-7-2-应用示例" tabindex="-1">2.7.2 应用示例 <a class="header-anchor" href="#_2-7-2-应用示例" aria-label="Permalink to &quot;2.7.2 应用示例&quot;"></a></h3><ul><li>需求:计算数组的最值(最大值和最小值)。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>思路:</p><ul><li>① 假设数组中的第一个元素是最大值或最小值,并使用变量 max 或 min 保存。</li><li>② 遍历数组中的每个元素: <ul><li>如果有元素比最大值还要大,就让变量 max 保存最大值。</li><li>如果有元素比最小值还要小,就让变量 min 保存最小值。</li></ul></li></ul></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义数组并初始化</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">31</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">24</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">15</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">36</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">67</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">108</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">29</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">51</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 计算数组的长度</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> size_t</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(arr) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义最大值</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> max </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义最小值</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> min </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 遍历数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> max) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> max </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i];</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> min) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> min </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i];</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;数组的最大值为:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, max);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 数组的最大值为108</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;数组的最小值为:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, min);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 数组的最小值为:-36</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br></div></div><h3 id="_2-7-3-应用示例" tabindex="-1">2.7.3 应用示例 <a class="header-anchor" href="#_2-7-3-应用示例" aria-label="Permalink to &quot;2.7.3 应用示例&quot;"></a></h3><ul><li><p>需求:统计数组中某个元素出现的次数,要求:使用无限循环,如果输入的数字是 0 ,就退出。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义数组并初始化</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">31</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">24</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">36</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">67</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">108</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">29</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">51</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 计算数组的长度</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> size_t</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(arr) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 遍历数组</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;当前数组中的元素是:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 无限循环</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> while</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">true</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 统计的数字</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num;</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 统计数字出现的次数</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> count </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 输入数字</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入要统计的数字:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入一个整数:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">num);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 0 作为结束条件</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 是偶数</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 是奇数</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><h3 id="_3-3-2-应用示例-1" tabindex="-1">3.3.2 应用示例 <a class="header-anchor" href="#_3-3-2-应用示例-1" aria-label="Permalink to &quot;3.3.2 应用示例&quot;"></a></h3><ul><li><p>需求输入年龄如果大于18岁则输出 &quot;你年龄大于18要对自己的行为负责!&quot;;否则,输出 &quot;你的年龄不大这次放过你了。&quot;</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> age </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入年龄:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">age);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (age </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 18</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;你年龄大于18要对自己的行为负责!</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;你的年龄不大,这次放过你了!</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><h3 id="_3-3-3-应用示例" tabindex="-1">3.3.3 应用示例 <a class="header-anchor" href="#_3-3-3-应用示例" aria-label="Permalink to &quot;3.3.3 应用示例&quot;"></a></h3><ul><li>需求:判定某个年份是否为闰年?</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① year 是 400 的整倍数: year%400==0</li><li>② 能被 4 整除,但不能被 100 整除year % 4 == 0 &amp;&amp; year % 100 != 0</li></ul></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> year </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入年份:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">year);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (year </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 400</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ||</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (year </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 4</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &amp;&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> year </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 100</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> !=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 是闰年</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, year);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 不是闰年</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, year);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><h2 id="_3-4-多重分支结构" tabindex="-1">3.4 多重分支结构 <a class="header-anchor" href="#_3-4-多重分支结构" aria-label="Permalink to &quot;3.4 多重分支结构&quot;"></a></h2><h3 id="_3-4-1-概述" tabindex="-1">3.4.1 概述 <a class="header-anchor" href="#_3-4-1-概述" aria-label="Permalink to &quot;3.4.1 概述&quot;"></a></h3><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (条件表达式1) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 语句块1;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">} </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (条件表达式2) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 语句块2;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">...</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">} </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (条件表达式n) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 语句块n;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">} </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 语句块n</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 在 C 语言中,严格意义上是没有 boolean 类型的,使用<code>非0</code> 表示<code>true</code><code>0</code> 表示<code>false</code></li><li>② 首先判断关系表达式 1 的结果是真(值为 <code>非0</code>)还是假(值为 <code>0</code> <ul><li>如果为真,就执行语句块 1然后结束当前多分支。</li><li>如果是假,就继续判断条件表达式 2看其结果是真还是假。</li><li>如果是真,就执行语句块 2然后结束当前多分支。</li><li>如果是假,就继续判断条件表达式…看其结果是真还是假。</li><li>...</li><li>如果没有任何关系表达式为真,就执行语句块 n+1然后结束当前多分支。</li></ul></li><li>③ 当条件表达式之间是<code>互斥</code>(彼此之间没有交集)关系时,条件判断语句及执行语句间顺序无所谓。</li><li>④ 当条件表达式之间是<code>包含</code>关系时,必须<code>小上大下 / 子上父下</code>,否则范围小的条件表达式将不可能被执行。</li><li>⑤ 当 if-else 结构是多选一的时候,最后的 else 是可选的,可以根据需要省略。</li><li>⑥ 如果语句块中只有一条执行语句的时候,<code>{}</code>是可以省略的;但是,强烈建议保留!!!</li></ul></div><ul><li>流程图,如下所示:</li></ul><p><img src="/c/assets/5.DtY5Pf6u.png" alt="image-20240722075241253" loading="lazy"></p><h3 id="_3-4-1-应用示例" tabindex="-1">3.4.1 应用示例 <a class="header-anchor" href="#_3-4-1-应用示例" aria-label="Permalink to &quot;3.4.1 应用示例&quot;"></a></h3><ul><li><p>需求:张三参加考试,他和父亲达成协议,如果成绩不到 60 分没有任何奖励;如果成绩 60分到 80 分,奖励一个肉夹馍;如果成绩 80 分(含)到 90 分,奖励一个 ipad如果成绩 90 分及以上,奖励一部华为 mate60 pro 。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> score </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入分数:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">score);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 容错:分数不可能小于 0 或大于 100</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (score </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ||</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> score </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 100</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;输入的分数有误!</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (score </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 90</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;奖励你一部华为 mate60 pro</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (score </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 80</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;奖励你一个 ipad</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (score </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 60</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;奖励你一个肉夹馍</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;你的成绩不及格,没有任何奖励!&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br></div></div><h3 id="_3-4-2-应用示例" tabindex="-1">3.4.2 应用示例 <a class="header-anchor" href="#_3-4-2-应用示例" aria-label="Permalink to &quot;3.4.2 应用示例&quot;"></a></h3><ul><li><p>需求:判断水的温度,如果大于 95℃则打印 &quot;开水&quot;;如果大于 70℃ 且小于等于 95℃则打印 &quot;热水&quot;;如果大于 40℃ 且小于等于 70℃则打印 &quot;温水&quot;;如果小于等于 40℃则打印 &quot;凉水&quot;</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> temperature </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入水的温度:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">temperature);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (temperature </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 95</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;开水 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (temperature </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 70</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &amp;&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> temperature </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 95</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;热水 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (temperature </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 40</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &amp;&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> temperature </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 70</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;温水 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;凉水 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br></div></div><h2 id="_3-5-多重分支结构-switch" tabindex="-1">3.5 多重分支结构 switch <a class="header-anchor" href="#_3-5-多重分支结构-switch" aria-label="Permalink to &quot;3.5 多重分支结构 switch&quot;"></a></h2><h3 id="_3-5-1-概述" tabindex="-1">3.5.1 概述 <a class="header-anchor" href="#_3-5-1-概述" aria-label="Permalink to &quot;3.5.1 概述&quot;"></a></h3><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">switch</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(表达式){</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 常量值1: </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 语句块1;</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> //break;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 常量值2: </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 语句块2;</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> //break;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ...</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 常量值n: </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 语句块n; </span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> //break;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> [default: </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 语句块n</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ]</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① switch 后面表达式的值必须是一个整型char、short、int、long 等)或枚举类型。</li><li>② case 后面的值必须是常量,不能是变量。</li><li>③ default 是可选的,当没有匹配的 case 的时候,就执行 default 。</li><li>④ break 语句可以使程序跳出 switch 语句块,如果没有 break会执行下一个 case 语句块,直到遇到 break 或者执行到 switch 结尾,这个现象称为穿透。</li></ul></div><ul><li>流程图,如下所示:</li></ul><p><img src="/c/assets/6.CButBugT.png" alt="" loading="lazy"></p><h3 id="_3-5-2-应用示例" tabindex="-1">3.5.2 应用示例 <a class="header-anchor" href="#_3-5-2-应用示例" aria-label="Permalink to &quot;3.5.2 应用示例&quot;"></a></h3><ul><li><p>需求编写一个程序该程序可以接收一个字符比如a、b、c、d其中 a 表示星期一b 表示星期二…,根据用户的输入显示相应的信息,要求使用 switch 语句。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> chs;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入一个字符a、b、c、d&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%c</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">chs);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> switch</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (chs) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;a&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;今天是星期一 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;窗前明月光 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;b&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;今天是星期二 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;疑是地上霜 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;c&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;今天是星期三 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;举头望明月 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;d&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;今天是星期四 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;低头思故乡 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> default</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;输入错误!&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 遍历数组,并计数</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">==</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br></div></div><h3 id="_3-5-3-应用示例" tabindex="-1">3.5.3 应用示例 <a class="header-anchor" href="#_3-5-3-应用示例" aria-label="Permalink to &quot;3.5.3 应用示例&quot;"></a></h3><ul><li><p>需求编写程序输入月份输出该月份有多少天。说明1 月、3 月、5 月、7月、8 月、10 月、12 月有 31 天4 月、6 月、9 月、11 月有 30 天2 月有 28 天或 29 天。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> month;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入月份 (1-12)&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">month);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> switch</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (month) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 7</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 8</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 月有 31 天</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, month);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 6</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 9</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 11</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 月有 30 天</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, month);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 月有 28 天或 29 天</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, month);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> default</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;输入错误!&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br></div></div><h3 id="_3-5-4-switch-和-if-else-if-的比较" tabindex="-1">3.5.4 switch 和 if else if 的比较 <a class="header-anchor" href="#_3-5-4-switch-和-if-else-if-的比较" aria-label="Permalink to &quot;3.5.4 switch 和 if else if 的比较&quot;"></a></h3><ul><li>① 如果判断条件是判等,而且符合整型、枚举类型,虽然两个语句都可以使用,建议使用 swtich 语句。</li><li>② 如果判断条件是区间判断,大小判断等,使用 if...else...if。</li></ul><h2 id="_3-6-嵌套分支" tabindex="-1">3.6 嵌套分支 <a class="header-anchor" href="#_3-6-嵌套分支" aria-label="Permalink to &quot;3.6 嵌套分支&quot;"></a></h2><h3 id="_3-6-1-概述" tabindex="-1">3.6.1 概述 <a class="header-anchor" href="#_3-6-1-概述" aria-label="Permalink to &quot;3.6.1 概述&quot;"></a></h3><ul><li>嵌套分支是指,在一个分支结构中又嵌套了另一个分支结构,里面的分支的结构称为内层分支,外面的分支结构称为外层分支。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>嵌套分支层数不宜过多,建议最多不要超过 3 层。</p></div><h3 id="_3-6-2-应用示例" tabindex="-1">3.6.2 应用示例 <a class="header-anchor" href="#_3-6-2-应用示例" aria-label="Permalink to &quot;3.6.2 应用示例&quot;"></a></h3><ul><li>需求:根据淡旺季的月份和年龄,打印票价。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 4 -10 是旺季: <ul><li>成人18-6060 。</li><li>儿童(&lt;18半价。</li><li>老人(&gt;601/3 。</li></ul></li><li>② 其余是淡季: <ul><li>成人40。</li><li>其他20。</li></ul></li></ul></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> month;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> age;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> price </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 60</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入月份 (1-12)&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">month);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入年龄:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">age);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 旺季</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (month </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 4</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &amp;&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> month </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (age </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 18</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> price </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (age </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 60</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> price </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (age </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 18</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> price </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 40</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> price </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 20</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;票价: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%.2lf\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, price);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br></div></div><h1 id="第四章-随机数" tabindex="-1">第四章:随机数 <a class="header-anchor" href="#第四章-随机数" aria-label="Permalink to &quot;第四章:随机数&quot;"></a></h1><h2 id="_4-1-概述" tabindex="-1">4.1 概述 <a class="header-anchor" href="#_4-1-概述" aria-label="Permalink to &quot;4.1 概述&quot;"></a></h2><ul><li>所谓的随机数就是没有规则,并且不能预测的一些数字,也称为真随机数。</li><li>程序中也是可以产生随机数的,但是是通过一些固定规则产生的,称为伪随机数。</li><li>常见的伪随机数线性同余方程LCG的公式如下所示</li></ul><p><mjx-container class="MathJax" jax="SVG" style="direction:ltr;position:relative;"><svg style="overflow:visible;min-height:1px;min-width:1px;vertical-align:-0.566ex;" xmlns="http://www.w3.org/2000/svg" width="28.71ex" height="2.262ex" role="img" focusable="false" viewBox="0 -750 12690 1000" aria-hidden="true"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(1,-1)"><g data-mml-node="math"><g data-mml-node="msub"><g data-mml-node="mi"><path data-c="1D44B" d="M42 0H40Q26 0 26 11Q26 15 29 27Q33 41 36 43T55 46Q141 49 190 98Q200 108 306 224T411 342Q302 620 297 625Q288 636 234 637H206Q200 643 200 645T202 664Q206 677 212 683H226Q260 681 347 681Q380 681 408 681T453 682T473 682Q490 682 490 671Q490 670 488 658Q484 643 481 640T465 637Q434 634 411 620L488 426L541 485Q646 598 646 610Q646 628 622 635Q617 635 609 637Q594 637 594 648Q594 650 596 664Q600 677 606 683H618Q619 683 643 683T697 681T738 680Q828 680 837 683H845Q852 676 852 672Q850 647 840 637H824Q790 636 763 628T722 611T698 593L687 584Q687 585 592 480L505 384Q505 383 536 304T601 142T638 56Q648 47 699 46Q734 46 734 37Q734 35 732 23Q728 7 725 4T711 1Q708 1 678 1T589 2Q528 2 496 2T461 1Q444 1 444 10Q444 11 446 25Q448 35 450 39T455 44T464 46T480 47T506 54Q523 62 523 64Q522 64 476 181L429 299Q241 95 236 84Q232 76 232 72Q232 53 261 47Q262 47 267 47T273 46Q276 46 277 46T280 45T283 42T284 35Q284 26 282 19Q279 6 276 4T261 1Q258 1 243 1T201 2T142 2Q64 2 42 0Z" style="stroke-width:3;"></path></g><g data-mml-node="TeXAtom" transform="translate(861,-150) scale(0.707)" data-mjx-texclass="ORD"><g data-mml-node="mi"><path data-c="1D45B" d="M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z" style="stroke-width:3;"></path></g><g data-mml-node="mo" transform="translate(600,0)"><path data-c="2B" d="M56 237T56 250T70 270H369V420L370 570Q380 583 389 583Q402 583 409 568V270H707Q722 262 722 250T707 230H409V-68Q401 -82 391 -82H389H387Q375 -82 369 -68V230H70Q56 237 56 250Z" style="stroke-width:3;"></path></g><g data-mml-node="mn" transform="translate(1378,0)"><path data-c="31" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z" style="stroke-width:3;"></path></g></g></g><g data-mml-node="mo" transform="translate(2516.7,0)"><path data-c="3D" d="M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z" style="stroke-width:3;"></path></g><g data-mml-node="mo" transform="translate(3572.5,0)"><path data-c="28" d="M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z" style="stroke-width:3;"></path></g><g data-mml-node="mi" transform="translate(3961.5,0)"><path data-c="1D44E" d="M33 157Q33 258 109 349T280 441Q331 441 370 392Q386 422 416 422Q429 422 439 414T449 394Q449 381 412 234T374 68Q374 43 381 35T402 26Q411 27 422 35Q443 55 463 131Q469 151 473 152Q475 153 483 153H487Q506 153 506 144Q506 138 501 117T481 63T449 13Q436 0 417 -8Q409 -10 393 -10Q359 -10 336 5T306 36L300 51Q299 52 296 50Q294 48 292 46Q233 -10 172 -10Q117 -10 75 30T33 157ZM351 328Q351 334 346 350T323 385T277 405Q242 405 210 374T160 293Q131 214 119 129Q119 126 119 118T118 106Q118 61 136 44T179 26Q217 26 254 59T298 110Q300 114 325 217T351 328Z" style="stroke-width:3;"></path></g><g data-mml-node="mo" transform="translate(4712.7,0)"><path data-c="22C5" d="M78 250Q78 274 95 292T138 310Q162 310 180 294T199 251Q199 226 182 208T139 190T96 207T78 250Z" style="stroke-width:3;"></path></g><g data-mml-node="msub" transform="translate(5212.9,0)"><g data-mml-node="mi"><path data-c="1D44B" d="M42 0H40Q26 0 26 11Q26 15 29 27Q33 41 36 43T55 46Q141 49 190 98Q200 108 306 224T411 342Q302 620 297 625Q288 636 234 637H206Q200 643 200 645T202 664Q206 677 212 683H226Q260 681 347 681Q380 681 408 681T453 682T473 682Q490 682 490 671Q490 670 488 658Q484 643 481 640T465 637Q434 634 411 620L488 426L541 485Q646 598 646 610Q646 628 622 635Q617 635 609 637Q594 637 594 648Q594 650 596 664Q600 677 606 683H618Q619 683 643 683T697 681T738 680Q828 680 837 683H845Q852 676 852 672Q850 647 840 637H824Q790 636 763 628T722 611T698 593L687 584Q687 585 592 480L505 384Q505 383 536 304T601 142T638 56Q648 47 699 46Q734 46 734 37Q734 35 732 23Q728 7 725 4T711 1Q708 1 678 1T589 2Q528 2 496 2T461 1Q444 1 444 10Q444 11 446 25Q448 35 450 39T455 44T464 46T480 47T506 54Q523 62 523 64Q522 64 476 181L429 299Q241 95 236 84Q232 76 232 72Q232 53 261 47Q262 47 267 47T273 46Q276 46 277 46T280 45T283 42T284 35Q284 26 282 19Q279 6 276 4T261 1Q258 1 243 1T201 2T142 2Q64 2 42 0Z" style="stroke-width:3;"></path></g><g data-mml-node="mi" transform="translate(861,-150) scale(0.707)"><path data-c="1D45B" d="M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z" style="stroke-width:3;"></path></g></g><g data-mml-node="mo" transform="translate(6770.4,0)"><path data-c="2B" d="M56 237T56 250T70 270H369V420L370 570Q380 583 389 583Q402 583 409 568V270H707Q722 262 722 250T707 230H409V-68Q401 -82 391 -82H389H387Q375 -82 369 -68V230H70Q56 237 56 250Z" style="stroke-width:3;"></path></g><g data-mml-node="mi" transform="translate(7770.7,0)"><path data-c="1D44F" d="M73 647Q73 657 77 670T89 683Q90 683 161 688T234 694Q246 694 246 685T212 542Q204 508 195 472T180 418L176 399Q176 396 182 402Q231 442 283 442Q345 442 383 396T422 280Q422 169 343 79T173 -11Q123 -11 82 27T40 150V159Q40 180 48 217T97 414Q147 611 147 623T109 637Q104 637 101 637H96Q86 637 83 637T76 640T73 647ZM336 325V331Q336 405 275 405Q258 405 240 397T207 376T181 352T163 330L157 322L136 236Q114 150 114 114Q114 66 138 42Q154 26 178 26Q211 26 245 58Q270 81 285 114T318 219Q336 291 336 325Z" style="stroke-width:3;"></path></g><g data-mml-node="mo" transform="translate(8199.7,0)"><path data-c="29" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z" style="stroke-width:3;"></path></g><g data-mml-node="mspace" transform="translate(8588.7,0)"></g><g data-mml-node="mi" transform="translate(9422.3,0)"><path data-c="6D" d="M41 46H55Q94 46 102 60V68Q102 77 102 91T102 122T103 161T103 203Q103 234 103 269T102 328V351Q99 370 88 376T43 385H25V408Q25 431 27 431L37 432Q47 433 65 434T102 436Q119 437 138 438T167 441T178 442H181V402Q181 364 182 364T187 369T199 384T218 402T247 421T285 437Q305 442 336 442Q351 442 364 440T387 434T406 426T421 417T432 406T441 395T448 384T452 374T455 366L457 361L460 365Q463 369 466 373T475 384T488 397T503 410T523 422T546 432T572 439T603 442Q729 442 740 329Q741 322 741 190V104Q741 66 743 59T754 49Q775 46 803 46H819V0H811L788 1Q764 2 737 2T699 3Q596 3 587 0H579V46H595Q656 46 656 62Q657 64 657 200Q656 335 655 343Q649 371 635 385T611 402T585 404Q540 404 506 370Q479 343 472 315T464 232V168V108Q464 78 465 68T468 55T477 49Q498 46 526 46H542V0H534L510 1Q487 2 460 2T422 3Q319 3 310 0H302V46H318Q379 46 379 62Q380 64 380 200Q379 335 378 343Q372 371 358 385T334 402T308 404Q263 404 229 370Q202 343 195 315T187 232V168V108Q187 78 188 68T191 55T200 49Q221 46 249 46H265V0H257L234 1Q210 2 183 2T145 3Q42 3 33 0H25V46H41Z" style="stroke-width:3;"></path><path data-c="6F" d="M28 214Q28 309 93 378T250 448Q340 448 405 380T471 215Q471 120 407 55T250 -10Q153 -10 91 57T28 214ZM250 30Q372 30 372 193V225V250Q372 272 371 288T364 326T348 362T317 390T268 410Q263 411 252 411Q222 411 195 399Q152 377 139 338T126 246V226Q126 130 145 91Q177 30 250 30Z" transform="translate(833,0)" style="stroke-width:3;"></path><path data-c="64" d="M376 495Q376 511 376 535T377 568Q377 613 367 624T316 637H298V660Q298 683 300 683L310 684Q320 685 339 686T376 688Q393 689 413 690T443 693T454 694H457V390Q457 84 458 81Q461 61 472 55T517 46H535V0Q533 0 459 -5T380 -11H373V44L365 37Q307 -11 235 -11Q158 -11 96 50T34 215Q34 315 97 378T244 442Q319 442 376 393V495ZM373 342Q328 405 260 405Q211 405 173 369Q146 341 139 305T131 211Q131 155 138 120T173 59Q203 26 251 26Q322 26 373 103V342Z" transform="translate(1333,0)" style="stroke-width:3;"></path></g><g data-mml-node="mstyle" transform="translate(11311.3,0)"><g data-mml-node="mspace"></g></g><g data-mml-node="mstyle" transform="translate(11478.3,0)"><g data-mml-node="mspace"></g></g><g data-mml-node="mi" transform="translate(11812,0)"><path data-c="1D45A" d="M21 287Q22 293 24 303T36 341T56 388T88 425T132 442T175 435T205 417T221 395T229 376L231 369Q231 367 232 367L243 378Q303 442 384 442Q401 442 415 440T441 433T460 423T475 411T485 398T493 385T497 373T500 364T502 357L510 367Q573 442 659 442Q713 442 746 415T780 336Q780 285 742 178T704 50Q705 36 709 31T724 26Q752 26 776 56T815 138Q818 149 821 151T837 153Q857 153 857 145Q857 144 853 130Q845 101 831 73T785 17T716 -10Q669 -10 648 17T627 73Q627 92 663 193T700 345Q700 404 656 404H651Q565 404 506 303L499 291L466 157Q433 26 428 16Q415 -11 385 -11Q372 -11 364 -4T353 8T350 18Q350 29 384 161L420 307Q423 322 423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 181Q151 335 151 342Q154 357 154 369Q154 405 129 405Q107 405 92 377T69 316T57 280Q55 278 41 278H27Q21 284 21 287Z" style="stroke-width:3;"></path></g></g></g></svg><mjx-assistive-mml unselectable="on" display="inline" style="top:0px;left:0px;clip:rect(1px, 1px, 1px, 1px);-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;position:absolute;padding:1px 0px 0px 0px;border:0px;display:block;width:auto;overflow:hidden;"><math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>X</mi><mrow data-mjx-texclass="ORD"><mi>n</mi><mo>+</mo><mn>1</mn></mrow></msub><mo>=</mo><mo stretchy="false">(</mo><mi>a</mi><mo></mo><msub><mi>X</mi><mi>n</mi></msub><mo>+</mo><mi>b</mi><mo stretchy="false">)</mo><mspace width="0.667em"></mspace><mi>mod</mi><mstyle scriptlevel="0"><mspace width="0.167em"></mspace></mstyle><mstyle scriptlevel="0"><mspace width="0.167em"></mspace></mstyle><mi>m</mi></math></mjx-assistive-mml></mjx-container></p><ul><li>其中X 是伪随机序列a 是乘数(通常选择一个大于 0 的常数,典型值有 1664525b 是增量(选择一个大于 0 的常数,典型值有 1013904223 m 是模数( 通常选择一个大的常数,常见值有 ( 2^{32} ) ,即 4294967296</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>假设 a = 31 b = 13 m = 100 ;那么,伪随机数的公式就是 <code>X_{n+1} = (31 × X_n + 13) % 100 </code></p><ul><li>如果 <code>X_{n}</code> = 1 ,那么 <code>X_{n+1}</code> = 44 。</li><li>如果 <code>X_{n}</code> = 44 ,那么 <code>X_{n+1}</code> = 77 。</li><li>如果 <code>X_{n}</code> = 77 ,那么 <code>X_{n+1}</code> = 0 。</li><li>...</li></ul><p>最后,将得到 44、77、0、13、16、9 、92、65、28 ... ,其中 1 也称为初始种子(随机数种子)。</p></div><ul><li>工作原理: <ul><li>① 设置初始种子X_0 <ul><li>种子值是算法生成随机数序列的起点。</li><li>不同的种子值会产生不同的随机数序列。</li></ul></li><li>② 递归生成随机数: <ul><li>从初始种子开始,通过公式不断生成新的随机数。</li><li>每次迭代都使用前一次生成的随机数作为输入。</li></ul></li></ul></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>如果种子的值相同,那么每次生成的随机数将相同,解决方案就是将种子的值设置为当前的时间戳。</p></div><h2 id="_4-2-c-语言中随机数的产生" tabindex="-1">4.2 C 语言中随机数的产生 <a class="header-anchor" href="#_4-2-c-语言中随机数的产生" aria-label="Permalink to &quot;4.2 C 语言中随机数的产生&quot;"></a></h2><ul><li>① 设置随机数种子:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">srand</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // seed 种⼦ rand random 随机</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>随机数函数在 <code>#include &lt;stdlib.h&gt;</code> 中声明。</p></div><ul><li>② 根据随机数种⼦计算出⼀个伪随机数:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 根据种⼦值产⽣⼀个 0-32767 范围的随机数</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> result </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> rand</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">();</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><ul><li>③ 产生一个指定范围内的随机数:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> random_in_range</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> min</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> max</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> rand</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (max </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> min </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> min;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdlib.h&gt;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;time.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 生成指定范围的随机数的函数</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> randomInRange</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> min</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> max</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> rand</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (max </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> min </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> min;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 使用当前时间作为种子</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> srand</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">time</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">));</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义范围</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> min </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> max </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 100</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 生成并打印随机数</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">i) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> random </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> randomInRange</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(min, max);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, random);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br></div></div><h1 id="第五章-循环结构-⭐" tabindex="-1">第五章:循环结构(⭐) <a class="header-anchor" href="#第五章-循环结构-⭐" aria-label="Permalink to &quot;第五章:循环结构(⭐)&quot;"></a></h1><h2 id="_5-1-概述" tabindex="-1">5.1 概述 <a class="header-anchor" href="#_5-1-概述" aria-label="Permalink to &quot;5.1 概述&quot;"></a></h2><ul><li>循环结构:在某些条件满足的情况下,反复执行特定代码的功能。</li></ul><h2 id="_5-2-for-循环" tabindex="-1">5.2 for 循环 <a class="header-anchor" href="#_5-2-for-循环" aria-label="Permalink to &quot;5.2 for 循环&quot;"></a></h2><h3 id="_5-2-1-概述" tabindex="-1">5.2.1 概述 <a class="header-anchor" href="#_5-2-1-概述" aria-label="Permalink to &quot;5.2.1 概述&quot;"></a></h3><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(初始化条件①;循环条件表达式②;迭代语句④){</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 循环体语句③</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 初始化条件,用于初始化循环变量,只会执行一次,且循环开始前就执行(可以声明多个变量,但是必须是同一类型,用逗号 <code>,</code> 隔开)。</li><li>② 循环条件表达式每次循环都执行,同 while 循环一样,每次先判断后执行循环体语句。</li><li>③ 迭代语句每次循环都执行,在大括号中循环体语句之后执行(如果有多个变量更新,用逗号 <code>,</code> 隔开)。</li></ul></div><ul><li>流程图,如下所示:</li></ul><p><img src="/c/assets/7.DG_I9X5w.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>执行过程是:① --&gt; ② --&gt; ③ --&gt; ④ --&gt; ② --&gt; ③ --&gt; ④ --&gt; ... --&gt; ② 。</p></div><h3 id="_5-2-2-应用示例" tabindex="-1">5.2.2 应用示例 <a class="header-anchor" href="#_5-2-2-应用示例" aria-label="Permalink to &quot;5.2.2 应用示例&quot;"></a></h3><ul><li><p>需求:输出 5 行 <code>Hello World!</code></p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">i) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;Hello World!</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><h3 id="_5-2-3-应用示例" tabindex="-1">5.2.3 应用示例 <a class="header-anchor" href="#_5-2-3-应用示例" aria-label="Permalink to &quot;5.2.3 应用示例&quot;"></a></h3><ul><li><p>需求:求 1 ~ 100 之内所有偶数的和,以及偶数的个数。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> sum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> count </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 100</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> sum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> count</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;您输入的数字 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 在数组中出现了 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"></span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num, count);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;1 ~ 100 中的所有偶数的和为: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, sum);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;1 ~ 100 中的所有偶数的个数为: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, count);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br><span class="line-number">45</span><br></div></div><h3 id="_2-7-4-应用示例" tabindex="-1">2.7.4 应用示例 <a class="header-anchor" href="#_2-7-4-应用示例" aria-label="Permalink to &quot;2.7.4 应用示例&quot;"></a></h3><ul><li><p>需求:将数组 a 中的全部元素复制到数组 b 中。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#define</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> SIZE</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br></div></div><h3 id="_5-2-4-应用示例" tabindex="-1">5.2.4 应用示例 <a class="header-anchor" href="#_5-2-4-应用示例" aria-label="Permalink to &quot;5.2.4 应用示例&quot;"></a></h3><ul><li><p>需求:输出所有的水仙花数,所谓水仙花数是指一个 3 位数,其各个位上数字立方和等于其本身,例如:<code>153 = 1×1×1 + 3×3×3 + 5×5×5</code></p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义数组并初始化</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> a</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">31</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">24</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">15</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">36</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">67</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">108</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">29</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">51</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> b</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[SIZE];</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> count </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 复制数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> SIZE; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> b</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> a</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i];</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 100</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 999</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 获取三位数</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ge </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> shi </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> %</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> bai </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 100</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 判定是否为水仙花数</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (ge </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ge </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ge </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> shi </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> shi </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> shi </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> bai </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> bai </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> bai </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">==</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;水仙花数:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, i);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> count</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 打印数组 b 中的全部元素</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> SIZE; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">b</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;水仙花数总个数:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, count);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br></div></div><h3 id="_2-7-5-应用示例" tabindex="-1">2.7.5 应用示例 <a class="header-anchor" href="#_2-7-5-应用示例" aria-label="Permalink to &quot;2.7.5 应用示例&quot;"></a></h3><ul><li>需求:数组对称位置的元素互换。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>思路:假设数组一共有 10 个元素,那么:</p><ul><li>a[0] 和 a[9] 互换。</li><li>a[1] 和 a[8] 互换。</li><li>...</li></ul><p>规律就是 <code>a[i] &lt;--互换--&gt; arr[arr.length -1 -i]</code></p></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br></div></div><h3 id="_5-2-5-应用示例" tabindex="-1">5.2.5 应用示例 <a class="header-anchor" href="#_5-2-5-应用示例" aria-label="Permalink to &quot;5.2.5 应用示例&quot;"></a></h3><ul><li><p>需求:将 1 ~ 10 倒序输出10 、9 、8 ...</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 原始数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">31</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">24</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">15</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">36</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">67</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">108</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">29</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">51</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 计算数组的长度</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> size_t</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> SIZE </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(arr) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 打印原始数组中的全部元素</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;原始数组:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> SIZE; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 交换数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> SIZE </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> temp </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i];</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[SIZE </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> -</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i];</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[SIZE </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> -</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> temp;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 打印交换后的数组</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;交换后数组:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> SIZE; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br></div></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 原始数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">31</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">24</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">15</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">36</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">67</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">108</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">29</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">51</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 计算数组的长度</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> size_t</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> SIZE </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(arr) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 打印原始数组中的全部元素</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;原始数组:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> SIZE; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 交换数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> SIZE </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> -</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> SIZE </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, j</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">--</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> temp </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i];</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[j];</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[j] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> temp;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 打印交换后的数组</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;交换后数组:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> SIZE; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br></div></div><h3 id="_2-7-6-应用示例" tabindex="-1">2.7.6 应用示例 <a class="header-anchor" href="#_2-7-6-应用示例" aria-label="Permalink to &quot;2.7.6 应用示例&quot;"></a></h3><ul><li>需求:将数组中的最大值移动到数组的最末尾。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>思路:从数组的下标 <code>0</code> 开始依次遍历到 <code>length - 1</code> ,如果 <code>i</code> 下标当前的值比 <code>i+1</code> 下标的值大,则交换;否则,就不交换。</p></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 原始数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">31</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">24</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">15</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">36</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">67</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">891</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">29</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">51</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 计算数组的长度</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> size_t</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(arr) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 打印原始数组中的全部元素</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;原始数组:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 移动最大值到数组的最后一个位置</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> temp </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i];</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> temp;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 打印移动之后的数组</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;移动之后的数组:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br></div></div><h3 id="_2-7-7-应用示例" tabindex="-1">2.7.7 应用示例 <a class="header-anchor" href="#_2-7-7-应用示例" aria-label="Permalink to &quot;2.7.7 应用示例&quot;"></a></h3><ul><li>需求:实现冒泡排序,即将数组的元素从小到大排列。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>思路:一层循环,能实现最大值移动到数组的最后;那么,二层循环(控制内部循环数组的长度)就能实现将数组的元素从小到大排序。</p></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 原始数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">31</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">24</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">15</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">36</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">67</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">891</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">29</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">51</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 计算数组的长度</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> size_t</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(arr) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 打印原始数组中的全部元素</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;原始数组:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; j</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> -</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> j; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> temp </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i];</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> temp;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 打印移动之后的数组</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;移动之后的数组:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br></div></div><h1 id="第三章-多维数组-⭐" tabindex="-1">第三章:多维数组(⭐) <a class="header-anchor" href="#第三章-多维数组-⭐" aria-label="Permalink to &quot;第三章:多维数组(⭐)&quot;"></a></h1><h2 id="_3-1-概述" tabindex="-1">3.1 概述 <a class="header-anchor" href="#_3-1-概述" aria-label="Permalink to &quot;3.1 概述&quot;"></a></h2><h3 id="_3-1-1-引入" tabindex="-1">3.1.1 引入 <a class="header-anchor" href="#_3-1-1-引入" aria-label="Permalink to &quot;3.1.1 引入&quot;"></a></h3><ul><li><p>我们在数学、物理和计算机科学等学科中学习过<code>一维坐标</code><code>二维坐标</code>以及<code>三维坐标</code></p></li><li><p>其中,<code>一维坐标</code>通常用于描述在线段或直线上的点的位置,主要应用有:</p><ul><li><strong>数轴</strong>:一维坐标可以用来表示数轴上的数值位置,这在基础数学和初等代数中非常常见。</li></ul><p><img src="/c/assets/8.EoNXwZXz.png" alt="" loading="lazy"></p><ul><li><strong>时间轴</strong>:时间可以看作是一维的,它可以用一维坐标表示,例如:秒、分钟、小时等。</li></ul><p><img src="/c/assets/9.iU-LaFqX.png" alt="" loading="lazy"></p><ul><li><strong>统计数据</strong>:一维坐标常用于表示单变量的数据集,如:测量身高、体重、温度等。</li></ul><p><img src="/c/assets/10.DYoXU9E6.jpg" alt="" loading="lazy"></p></li><li><p>其中,<code>二维坐标</code>用于描述平面上的点的位置。主要应用包括:</p><ul><li><strong>几何学</strong>:在几何学中,二维坐标用于表示平面图形的顶点、边和面积等。</li></ul><p><img src="/c/assets/11.DWDH3yqc.png" alt="" loading="lazy"></p><ul><li><strong>地图和导航</strong>:地理坐标系统(经纬度)使用二维坐标来表示地球表面的任意位置。</li></ul><p><img src="/c/assets/12.BvBjpbbE.png" alt="image-20240724112326592" loading="lazy"></p><ul><li><strong>图形设计和计算机图形学</strong>:二维坐标在绘制图形、设计图案和用户界面中非常重要。</li></ul><p><img src="/c/assets/13.CmPe90qp.png" alt="" loading="lazy"></p><ul><li><strong>物理学</strong>:二维运动和场,例如:在描述物体在平面上的运动轨迹时使用二维坐标。</li></ul><p><img src="/c/assets/14.MepLJvOt.jpg" alt="" loading="lazy"></p></li><li><p>其中,三维坐标用于描述空间中点的位置。主要应用包括:</p><ul><li><strong>几何学</strong>:三维坐标在空间几何中用于表示立体图形的顶点、边、面和体积。</li></ul><p><img src="/c/assets/15.CZUo3kuI.png" alt="" loading="lazy"></p><ul><li><strong>计算机图形学</strong>:三维建模和动画需要使用三维坐标来创建和操控虚拟对象。</li></ul><p><img src="/c/assets/16.t7xuKRuB.png" alt="" loading="lazy"></p><ul><li><strong>工程和建筑设计</strong>:在设计建筑物、机械部件和其他工程项目时,使用三维坐标来精确定位和规划。</li></ul><p><img src="/c/assets/17.Bkm40EoU.png" alt="" loading="lazy"></p><ul><li><strong>物理学</strong>:三维空间中的力、运动和场,例如:描述物体在空间中的位置和运动轨迹。</li></ul><p><img src="/c/assets/18.D0Mtsawg.png" alt="" loading="lazy"></p></li><li><p>总而言之,一维、二维和三维坐标系统在不同的领域中各有其重要的应用,从基础数学到高级科学和工程技术,它们帮助我们更好地理解和描述世界的结构和行为。</p></li></ul><h3 id="_3-1-2-多维数组" tabindex="-1">3.1.2 多维数组 <a class="header-anchor" href="#_3-1-2-多维数组" aria-label="Permalink to &quot;3.1.2 多维数组&quot;"></a></h3><ul><li>在 C 语言中,多维数组就是数组嵌套,即:在数组中包含数组,数组中的每一个元素还是一个数组类型,如下所示:</li></ul><p><img src="/c/assets/19.C-mmUOKp.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 如果数组中嵌套的每一个元素是一个常量值,那么该数组就是一维数组。</li><li>② 如果数组中嵌套的每一个元素是一个一维数组,那么该数组就是二维数组。</li><li>③ 如果数组中前台的每一个元素是一个二维数组,那么该数组就是三维数组.</li><li>④ 依次类推...</li></ul></div><ul><li>一维数组和多维数组的理解: <ul><li>从内存角度看:一维数组或多维数组都是占用的一整块连续的内存空间。</li><li>从数据操作角度看: <ul><li>一维数组可以直接通过<code>下标</code>访问到数组中的某个元素0、1、...</li><li>二维数组要想访问某个元素,先要获取某个一维数组,然后在一维数组中获取对应的数据。</li></ul></li></ul></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① C 语言中的一维数组或多维数组都是占用的一整块连续的内存空间其它编程语言可不是这样的Java 等。</li><li>② 在实际开发中,最为常用的就是二维数组或三维数组了,以二维数组居多!!!</li></ul></div><h2 id="_3-2-二维数组的定义" tabindex="-1">3.2 二维数组的定义 <a class="header-anchor" href="#_3-2-二维数组的定义" aria-label="Permalink to &quot;3.2 二维数组的定义&quot;"></a></h2><h3 id="_3-2-1-动态初始化" tabindex="-1">3.2.1 动态初始化 <a class="header-anchor" href="#_3-2-1-动态初始化" aria-label="Permalink to &quot;3.2.1 动态初始化&quot;"></a></h3><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">数据类型 数组名[几个⼀维数组元素][每个⼀维数组中有几个具体的数据元素];</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 二维数组在实际开发中,最为常见的应用场景就是表格或矩阵了。</li><li>② 几个一维数组元素 = 行数。</li><li>③ 每个⼀维数组中有几个具体的数据元素 = 列数。</li></ul></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义二维数组并初始化</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {{</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}, {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">6</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">7</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">8</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}, {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">9</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">11</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 输出二维数组中的元素</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br></div></div><h3 id="_3-2-2-静态初始化-1" tabindex="-1">3.2.2 静态初始化 1 <a class="header-anchor" href="#_3-2-2-静态初始化-1" aria-label="Permalink to &quot;3.2.2 静态初始化 1&quot;"></a></h3><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">数据类型 数组名[行数][列数] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {{元素1,元素2,...},{元素3,...},...}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 行数 = 几个一维数组元素。</li><li>② 列数 = 每个⼀维数组中有几个具体的数据元素。</li></ul></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义二维数组并初始化</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {{</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}, {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">6</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">7</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">8</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}, {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">9</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">11</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 输出二维数组中的元素</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br></div></div><h3 id="_3-2-3-静态初始化-2" tabindex="-1">3.2.3 静态初始化 2 <a class="header-anchor" href="#_3-2-3-静态初始化-2" aria-label="Permalink to &quot;3.2.3 静态初始化 2&quot;"></a></h3><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">数据类型 数组名</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[列数] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {{元素1,元素2,...},{元素3,...},...}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 列数 = 每个⼀维数组中有几个具体的数据元素。</li><li>② 可以不指定行数,必须指定列数,编译器会根据元素的个数和列的个数,自动推断出行数!!!</li></ul></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义二维数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {{</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}, {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">6</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}, {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">9</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">11</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 输出二维数组中的元素</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br></div></div><h2 id="_3-3-二维数组的理解" tabindex="-1">3.3 二维数组的理解 <a class="header-anchor" href="#_3-3-二维数组的理解" aria-label="Permalink to &quot;3.3 二维数组的理解&quot;"></a></h2><ul><li>如果二维数组是这么定义的,即:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><ul><li>那么,这个二维数组 <code>arr</code> 可以看做是 <code>3</code> 个一维数组组成,它们分别是 <code>arr[0]</code><code>arr[1]</code><code>arr[2]</code>。这 <code>3</code> 个一维数组都各有 4 个元素,如:一维数组 <code>arr[0]</code> 中的元素是 <code>arr[0][0]</code><code>arr[0][1]</code><code>arr[0][2]</code><code>arr[0][3]</code>,即:</li></ul><p><img src="/c/assets/20.BvSSXPdI.png" alt="" loading="lazy"></p><h2 id="_3-4-二维数组的遍历" tabindex="-1">3.4 二维数组的遍历 <a class="header-anchor" href="#_3-4-二维数组的遍历" aria-label="Permalink to &quot;3.4 二维数组的遍历&quot;"></a></h2><ul><li>访问二维数组的元素,需要使用两个下标(索引),一个用于访问行(第一维),另一个用于访问列(第二维),我们通常称为行下标(行索引)或列下标(列索引)。</li><li>所以,遍历二维数组,需要使用双层循环结构。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>如果一个二维数组是这么定义的,即:<code>int arr[3][4]</code>,那么:</p><ul><li><code>行的长度 = sizeof(arr) / sizeof(arr[0])</code> ,因为 <code>arr</code> 是二维数组的<code></code>的内存空间;而 <code>arr[0]</code><code>arr[1]</code><code>arr[2]</code> 是二维数组中一维数组的内存空间 。</li><li><code>列的长度 = sizeof(arr[0]) / sizeof(arr[0][0])</code>,因为<code>arr[0]</code><code>arr[1]</code><code>arr[2]</code> 是二维数组中一维数组的内存空间 ,而 <code>arr[0][0]</code><code>arr[0][1]</code>、... 是一维数组中元素的内存空间。</li></ul></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义二维数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {{</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}, {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">6</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}, {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">9</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">11</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 获取行列数</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> row </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(arr) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> col </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 打印二维数组元素</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> row; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> col; j</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i][j]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">--</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, i);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br></div></div><h2 id="_3-5-二维数组的内存分析" tabindex="-1">3.5 二维数组的内存分析 <a class="header-anchor" href="#_3-5-二维数组的内存分析" aria-label="Permalink to &quot;3.5 二维数组的内存分析&quot;"></a></h2><ul><li><p><code>矩阵形式</code>3 行 4 列形式)表示二维数组,是<code>逻辑</code>上的概念,能形象地表示出行列关系。而在<code>内存</code>中,各元素是连续存放的,不是二维的,是<code>线性</code>的。</p></li><li><p>C 语言中,二维数组中元素排列的顺序是<code>按行存放</code>的。即:先顺序存放第一行的元素,再存放第二行的元素。例如:数组<code>a[3][4] </code>在内存中的存放,如下所示:</p></li></ul><p><img src="/c/assets/21.uaya_nVR.png" alt="" loading="lazy"></p><h2 id="_3-6-二维数组的应用案例" tabindex="-1">3.6 二维数组的应用案例 <a class="header-anchor" href="#_3-6-二维数组的应用案例" aria-label="Permalink to &quot;3.6 二维数组的应用案例&quot;"></a></h2><ul><li><p>需求:现在有三个班,每个班五名同学,用二维数组保存他们的成绩,并求出每个班级平均分、以及所有班级平均分,数据要求从控制台输入。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><h3 id="_5-2-6-应用示例" tabindex="-1">5.2.6 应用示例 <a class="header-anchor" href="#_5-2-6-应用示例" aria-label="Permalink to &quot;5.2.6 应用示例&quot;"></a></h3><ul><li>需求:输入两个正整数 m 和 n 求其最大公约数和最小公倍数例如12 和 20 的最大公约数是 4 ,最小公倍数是 60 。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>如果数 a 能被数 b 整除,且结果是整数,那么 a 就叫做 b 的倍数b 就叫做 a 的约数(因数)。</li><li>如果一个整数同时是几个整数的约数,则称该整数为这些整数的公约数;其中,数值最大的称为最大公约数。</li><li>如果一个整数同时为两个或多个整数的倍数的数,则称该整数为这些整数的公倍数;其中,数值最小的称为最小公倍数。</li></ul></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义二维数组,用于保存成绩</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> double</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> m </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, n </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 20</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 获取二维数组的行数和列数</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> row </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(arr) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> col </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 取出两个数中的较小值</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> min </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (m </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> n) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">?</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> m </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> n;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 从控制台输入成绩</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> row; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> col; j</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入第</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">个班级的第</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">个学生的成绩:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%lf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i][j]);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> min; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">--</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (m </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &amp;&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> n </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;最大公约数是:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, i);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 公约数</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> //跳出当前循环结构</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 总分</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> totalSum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 取出两个数中的较大值</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> max </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (m </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> n) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">?</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> m </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> n;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> max; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> m </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> n; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 遍历数组,求总分和各个班级的平均分</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> row; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> sum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> col; j</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> totalSum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i][j];</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> sum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i][j];</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">个班级的总分为:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%.2lf\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, sum);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">个班级的平均分为:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%.2lf\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, sum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> col);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> m </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &amp;&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> n </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;所有班级的总分为:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%.2lf\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, totalSum);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;所有班级的平均分为:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%.2lf\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, totalSum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (row </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> col));</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;最小公倍数是:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, i);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 公倍数</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br></div></div><h1 id="第四章-字符串-⭐" tabindex="-1">第四章:字符串(⭐) <a class="header-anchor" href="#第四章-字符串-⭐" aria-label="Permalink to &quot;第四章:字符串(⭐)&quot;"></a></h1><h2 id="_4-1-概述" tabindex="-1">4.1 概述 <a class="header-anchor" href="#_4-1-概述" aria-label="Permalink to &quot;4.1 概述&quot;"></a></h2><ul><li>在实际开发中,我们除了经常处理整数、浮点数、字符等,还经常和字符串打交道,如:<code>&quot;Hello World&quot;</code><code>&quot;Hi&quot;</code> 等。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>像这类<code>&quot;Hello World&quot;</code><code>&quot;Hi&quot;</code>等格式 ,使用双引号引起来的一串字符称为字符串字面值,简称字符串。</p></div><ul><li>对于整数、浮点数和字符C 语言中都提供了对应的数据类型。但是对于字符串C 语言并没有提供对应的数据类型,而是用<code>字符数组</code>来存储这类文本类型的数据,即字符串:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">char</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> str</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">32</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><ul><li>字符串不像整数、浮点数以及字符那样有固定的大小,字符串是不定长的,如:<code>&quot;Hello World&quot;</code><code>&quot;Hi&quot;</code> 等的长度就是不一样的。在 C 语言中,规定了字符串的结尾必须是 <code>\0</code> ,这种字符串也被称为 <code>C 风格的字符串</code>,如:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;Hello World&quot;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 在 C 语言中,底层存储就是 Hello World\0</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><ul><li>其对应的图示,如下所示:</li></ul><p><img src="/c/assets/22.CA2ak30R.png" alt="" loading="lazy"></p><ul><li><code>\0</code> 在 ASCII 码表中是第 0 个字符,用 NUL 表示,称为空字符,该字符既不能显示,也不是控制字符,输出该字符不会有任何效果,它在 C 语言中仅作为字符串的结束标志。</li></ul><p><img src="/c/assets/12.NlBmD7pA.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>在现代化的高级编程语言中都提供了字符串对应的类型Java 中的 StringJDK 11 之前,底层也是通过 <code>char[]</code> 数组来实现的) 。</p></div><h2 id="_4-2-字符数组-字符串-的定义" tabindex="-1">4.2 字符数组(字符串)的定义 <a class="header-anchor" href="#_4-2-字符数组-字符串-的定义" aria-label="Permalink to &quot;4.2 字符数组(字符串)的定义&quot;"></a></h2><h3 id="_4-2-1-标准写法" tabindex="-1">4.2.1 标准写法 <a class="header-anchor" href="#_4-2-1-标准写法" aria-label="Permalink to &quot;4.2.1 标准写法&quot;"></a></h3><ul><li><p>手动在字符串的结尾添加 <code>\0</code>作为字符串的结束标识。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br></div></div><h2 id="_5-3-while-循环" tabindex="-1">5.3 while 循环 <a class="header-anchor" href="#_5-3-while-循环" aria-label="Permalink to &quot;5.3 while 循环&quot;"></a></h2><h3 id="_5-3-1-概述" tabindex="-1">5.3.1 概述 <a class="header-anchor" href="#_5-3-1-概述" aria-label="Permalink to &quot;5.3.1 概述&quot;"></a></h3><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">初始化条件①;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">while</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (循环条件语句②) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 循环体语句③;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 迭代语句④;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li><code>while(循环条件部分)</code> 中循环条件为<code>非0</code>值,表示 <code>true</code><code></code>;为<code>0</code>值,表示 <code>false</code><code></code></li><li>② 当循环条件表达式成立,就执行循环体语句,直到条件不成立停止循环。</li><li>③ 为避免死循环,循环条件表达式不能永远成立,且随着循环次数增加,应该越来越趋向于不成立。</li><li>④ for 循环和 while 循环<code>可以相互转换</code>,二者没有性能上的差别。</li><li>⑤ for 循环与 while 循环的区别:<code>初始化条件部分的作用域不同</code></li></ul></div><ul><li>流程图,如下所示:</li></ul><p><img src="/c/assets/8.Cw8LCRHN.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>执行过程是:① --&gt; ② --&gt; ③ --&gt; ④ --&gt; ② --&gt; ③ --&gt; ④ --&gt; ... --&gt; ② 。</p></div><h3 id="_5-3-2-应用示例" tabindex="-1">5.3.2 应用示例 <a class="header-anchor" href="#_5-3-2-应用示例" aria-label="Permalink to &quot;5.3.2 应用示例&quot;"></a></h3><ul><li><p>需求:输出 5 行 <code>Hello World!</code></p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> while</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;Hello World!</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><h3 id="_5-3-3-应用示例" tabindex="-1">5.3.3 应用示例 <a class="header-anchor" href="#_5-3-3-应用示例" aria-label="Permalink to &quot;5.3.3 应用示例&quot;"></a></h3><ul><li><p>需求:求 1 ~ 100 之内所有偶数的和,以及偶数的个数。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> sum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> count </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> while</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 100</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> sum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> count</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;1 ~ 100 中的所有偶数的和为: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, sum);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;1 ~ 100 中的所有偶数的个数为: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, count);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br></div></div><h3 id="_5-3-4-应用示例" tabindex="-1">5.3.4 应用示例 <a class="header-anchor" href="#_5-3-4-应用示例" aria-label="Permalink to &quot;5.3.4 应用示例&quot;"></a></h3><ul><li><p>需求:世界最高山峰是珠穆朗玛峰,它的高度是 8848.86 米,假如我有一张足够大的纸,它的厚度是 0.1 毫米。请问,我折叠多少次,可以折成珠穆朗玛峰的高度?</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 折叠的次数</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> count </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 珠峰的高度</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> zfHeight </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 8848860</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 每次折叠的高度</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> paperHeight </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0.1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> while</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (paperHeight </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> zfHeight) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> count</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> paperHeight </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;需要折叠 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 次,才能得到珠峰的高度。</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, count);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;折纸的高度为 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%.2f</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 米,超过了珠峰的高度&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, paperHeight </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1000</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br></div></div><h3 id="_5-3-5-应用示例" tabindex="-1">5.3.5 应用示例 <a class="header-anchor" href="#_5-3-5-应用示例" aria-label="Permalink to &quot;5.3.5 应用示例&quot;"></a></h3><ul><li>需求:给出一个整数 n ,判断该整数是否是 2 的幂次方。如果是,就输出 yes ;否则,输出 no 。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>思路:</p><ul><li>① 2^ 0 = 1 2^1 = 2 2^2 = 42^3 = 82^4 = 162^5 = 32 ...,规律:每一个数字都是前一个数字的 2 倍(任意一个数字,不断的除以 2 ,最终看结果是否是数字 1 )。</li><li>② 循环终止条件: <ul><li>结果是 1 的时候,就可以结束,输出 yes 。</li><li>如果在除以 2 的时候,无法被 2 整数,也可以结束,输出 no ,如: 100 / 2 = 5050 / 2 = 25 。</li></ul></li></ul></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 禁用 stdout 缓冲区</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> setbuf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(stdout, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">NULL</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 字符数组,不是字符串</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> c1</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;H&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;e&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;l&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;l&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;o&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39; &#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;W&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;o&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;r&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;l&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;d&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // C 风格的字符串</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> c2</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;H&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;e&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;l&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;l&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;o&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39; &#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;W&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;o&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;r&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;l&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;d&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> n </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入一个整数:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">n);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> while</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (n </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &amp;&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> n </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> n </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (n </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;yes&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;no&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><h3 id="_4-2-2-简化写法-推荐" tabindex="-1">4.2.2 简化写法(推荐) <a class="header-anchor" href="#_4-2-2-简化写法-推荐" aria-label="Permalink to &quot;4.2.2 简化写法(推荐)&quot;"></a></h3><ul><li>字符串写成数组的形式非常麻烦。C 语言中提供了一种简化写法,即:双引号中的字符,会自动视为字符数组。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>简化写法会自动在末尾添加 <code>\0</code> 字符,强烈推荐使用。</p></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br></div></div><h3 id="_5-3-6-应用示例" tabindex="-1">5.3.6 应用示例 <a class="header-anchor" href="#_5-3-6-应用示例" aria-label="Permalink to &quot;5.3.6 应用示例&quot;"></a></h3><ul><li>需求整数反转123 --&gt; 321 。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>思路:从右边开始,依次获取每一位数字,再拼接起来。</p></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 禁用 stdout 缓冲区</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> setbuf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(stdout, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">NULL</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> c1</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;Hello World&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 注意使用双引号,非单引号</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> c2</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;Hello World&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // //可以省略一对 {} 来初始化数组元素</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> original </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> rev </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入一个整数:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">num);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> original </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 从右边开始,依次获取每个数字,然后拼接到 rev 中</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> /**</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * 第 1 次123 % 10 = 3rev = 0 * 10 + 3 = 3</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * 第 2 次12 % 10 = 2rev = 3 * 10 + 2 = 32</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * 第 3 次1 % 10 = 1rev = 32 * 10 + 1 = 321</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> */</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 循环结束的条件是 num == 0</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> while</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">!=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 获取 num 右边的第一位数字</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> temp </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 去掉最后一位数字</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 将 temp 拼接到 rev 的后面</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> rev </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> rev </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> +</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> temp;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 的反转是 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, original, rev);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><h2 id="_4-3-字符串的输入和输出" tabindex="-1">4.3 字符串的输入和输出 <a class="header-anchor" href="#_4-3-字符串的输入和输出" aria-label="Permalink to &quot;4.3 字符串的输入和输出&quot;"></a></h2><ul><li>对于字符串的输入和输出,同样可以使用 <code>scanf</code><code>printf</code> 函数来实现,并且其格式占位符是 <code>%s</code></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>之前提到,对于 scanf 函数而言,<code>%s</code> 默认是匹配到空格或 Enter 键,如果我们输入的字符串是 <code>Hello World</code>,就只能得到 <code>Hello</code> ;如果要实现匹配到换行,则可以在输入的时候,将格式占位符 <code>%s</code>替换为 <code>%[^\n]</code></p></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 禁用 stdout 缓冲区</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> setbuf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(stdout, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">NULL</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> c1</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;Hello World&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 注意使用双引号,非单引号</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> c2</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;Hello World&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // //可以省略一对 {} 来初始化数组元素</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;c1 = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%s\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, c1);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // c1 = Hello World</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;c2 = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%s\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, c2);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // c2 = Hello World</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 禁用 stdout 缓冲区</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> setbuf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(stdout, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">NULL</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> str</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">32</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入字符串:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#B31D28;--shiki-dark:#FDAEB7;--shiki-light-font-style:italic;--shiki-dark-font-style:italic;">%</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">[^</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">]&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, str);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;字符串是:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%s\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, str);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><h1 id="第五章-内存中的变量和数组-⭐" tabindex="-1">第五章:内存中的变量和数组(⭐) <a class="header-anchor" href="#第五章-内存中的变量和数组-⭐" aria-label="Permalink to &quot;第五章:内存中的变量和数组(⭐)&quot;"></a></h1><h2 id="_5-1-内存和内存地址" tabindex="-1">5.1 内存和内存地址 <a class="header-anchor" href="#_5-1-内存和内存地址" aria-label="Permalink to &quot;5.1 内存和内存地址&quot;"></a></h2><h3 id="_5-1-1-内存" tabindex="-1">5.1.1 内存 <a class="header-anchor" href="#_5-1-1-内存" aria-label="Permalink to &quot;5.1.1 内存&quot;"></a></h3><ul><li><p><code>内存</code>是一种<code>计算机硬件</code>,是<code>软件</code><code>运行过程</code>中,用来<code>临时存储数据</code>的。在生活中,最为常见的<code>内存</code>就是<code>随机存取存储器RAM内存条</code>),其特点如下所示:</p><ul><li>① 生活中最常见的内存类型,用于存储当前运行的程序和数据。</li><li>② 内存是易失性存储器,这意味着断电后数据会丢失。</li><li>③ 它具有高速读写特性,适用于需要快速访问的操作。</li></ul></li><li><p>内存条的外观,如下所示:</p></li></ul><p><img src="/c/assets/24.QdyrLkbx.jpeg" alt="" loading="lazy"></p><ul><li>像我们平常使用<code>记事本</code>软件一样,当我们输入一些文字的时候,其实是将数据<code>临时</code>保存在内存中的,如下所示:</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 目前,很多软件都很智能,如果用户没有将数据到保存文件中,将显示红色,以警告用户还没有保存数据,提醒用户需要尽快保存数据!!!</li><li>② 但是也有很多软件提供了自动保存数据的功能其原理就是定时1s、3s、5s将内存中的数据刷新到文件中以防止数据丢失</li><li>③ 将数据从内存存储到文件中,专业的说法是落盘(落在磁盘上)。</li></ul></div><p><img src="/c/assets/25.wg7a3XFP.gif" alt="" loading="lazy"></p><ul><li>此时,如果我们在没有保存的过程下,将<code>记事本</code>软件关闭,那么刚才输入的文字将丢失;下次,再打开同样的文件(将数据从磁盘加载进内存,再交给 CPU之前输入的文字将不复存在如下所示</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 目前,很多软件都很智能,如果你没有保存,将提醒你是否保存或丢失刚才输入的文字。</li><li>② 但是也有很多软件提供了自动保存数据的功能其原理就是定时1s、3s、5s将内存中的数据刷新到文件中以防止数据丢失</li><li>③ 将数据从内存存储到文件中,专业的说法是落盘(落在磁盘上)。</li></ul></div><p><img src="/c/assets/26.M8jrrq2u.gif" alt="" loading="lazy"></p><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p>内存就是软件在运行过程中,用来临时存储数据的,最为重要的两个步骤就是:</p><ul><li>① 将数据<code>保存</code>到内存中。</li><li>② 从内存中的<code>对应位置</code>将数据<code>取出来</code></li></ul></div><h3 id="_5-1-2-内存地址" tabindex="-1">5.1.2 内存地址 <a class="header-anchor" href="#_5-1-2-内存地址" aria-label="Permalink to &quot;5.1.2 内存地址&quot;"></a></h3><ul><li>在这个计算机的内存条,动不动就 32GB、64GB 、128GB 或更高的年代,如下所示:</li></ul><p><img src="/c/assets/27.BdWdvezm.png" alt="" loading="lazy"></p><ul><li>如果有一个 int 4 个字节)类型的数据 <code>2</code> ,如何将这个数据保存到内存中?(对应上述的步骤 ①)</li></ul><p><img src="/c/assets/28.C_QI84u9.svg" alt="" loading="lazy"></p><ul><li>就算数据 <code>2</code> 已经保存到内存中,那么内存中那么多的数据,我们又该如何取出呢?(对应上述的步骤 ②)</li></ul><p><img src="/c/assets/29.BB6sjxx5.svg" alt="" loading="lazy"></p><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p>答案就是<code>内存地址</code></p></div><ul><li>操作系统为了更快的去管理内存中的数据,会将<code>内存条</code>按照<code>字节</code>划分为一个个的<code>单元格</code>,如下所示:</li></ul><p><img src="/c/assets/30.CHyA9Yy8.svg" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>计算机中存储单位的换算,如下所示:</p><ul><li>1 B = 8 bit。</li><li>1 KB = 1024 B。</li><li>1 MB = 1024 KB。</li><li>1 GB = 1024 MB。</li><li>1 TB = 1024 GB 。</li><li>……</li></ul></div><ul><li>为了方便管理,每个独立的小单元格,都有自己唯一的编号(内存地址),如下所示:</li></ul><p><img src="/c/assets/4.DqDR6Thp.svg" alt="" loading="lazy"></p><ul><li><p>之所以,加了<code>内存地址</code>,就能<code>加快</code>数据的存取速度,可以类比生活中的<code>字典</code></p><ul><li>如果没有使用<code>拼音查找法</code><code>部首查找法</code>,我们需要一页一页,一行一行的,在整个字典中去搜索我们想要了解的汉字,效率非常低(如果要搜索的汉字在最后一页,可能需要将整个字典从头到尾翻一遍,这辈子真有可能翻得完?)。</li></ul><p><img src="/c/assets/32.3t5rXZRH.gif" alt="" loading="lazy"></p><ul><li>如果使用<code>拼音查找法</code><code>部首查找法</code>,我们可以很快的定位到所要了解汉字所在的页数,加快了搜索的效率。</li></ul><p><img src="/c/assets/33.BRUArxJK.jpg" alt="" loading="lazy"></p><p><img src="/c/assets/34.DIXK93xX.jpg" alt="" loading="lazy"></p></li><li><p>同样的道理,如果<code>没有</code>内存地址,我们只能一个个的去寻找想要的数据,效率非常低下,如下所示:</p></li></ul><p><img src="/c/assets/35.Bvu6CpUv.gif" alt="" loading="lazy"></p><ul><li>如果<code>使用</code>内存地址,我们就可以直接定位到指定的数据,效率非常高,如下所示:</li></ul><p><img src="/c/assets/36.DHPPX3_T.gif" alt="" loading="lazy"></p><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li>① 内存地址是计算机中用于标识内存中某个特定位置的数值。</li><li>② 每个内存单元都有一个唯一的地址,这些地址可以用于访问和操作存储在内存中的数据。</li></ul></div><ul><li>实际中的内存地址,并不是像上面的 <code>001</code><code>002</code> 、... 之类的数字,而是有自己的规则,即:内存地址规则。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 32 位的操作系统中,内存地址以 32 位的二进制表示。</li><li>② 64 位的操作系统中,内存地址以 64 位的二进制表示。</li></ul></div><ul><li>在 32 位的操作系统中,内存地址的范围是:<code>0000 0000 0000 0000 0000 0000 0000 0000</code> ~ <code>1111 1111 1111 1111 1111 1111 1111 1111</code> 2 ^ 32 次方)。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>在 32 位的操作系统中,一共有 4,294,967,296 个内存地址,其最大支持的内存大小是 4,294,967,296 字节,即 4 GB 。</p></div><ul><li>在 64 位的操作系统中,内存地址的范围是:<code>0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000</code> ~ <code>1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111</code> 2 ^ 64 次方)。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 在 64 位的操作系统中,一共有 18,446,744,073,709,551,616 个内存地址,其最大支持的内存大小是 18,446,744,073,709,551,616 字节,即 17,179 TB 。</li><li>② 虽然,从理论上 64 位的操作系统支持的内存最大容量是 17,179 TB但是实际操作系统会有所限制win11 的 64 位支持的最大内存是 128 GB ~ 6 TBLinux 64 位支持的最大内存通常是 256 TB。</li></ul></div><ul><li>在实际开发中64 位操作系统的内存地址表现形式,如:<code>0000 0000 0000 0000 0001 0000 1111 1010 0000 0000 0010 0000 0000 0010 0000 1000</code>,实在是太长了,我们通常转换为十六进制,以方便阅读,如:<code>0x000010FA00200208</code></li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li>① 内存地址是内存中每个单元的编号。</li><li>② 内存地址的作用是操作系统用来快速管理内存空间的。</li><li>③ 在 32 位操作系统上,内存地址以 32 位的二进制数字表示,最大支持的的内存是 4 GB所以 32 位操作系统已经被淘汰。</li><li>④ 在 64 位操作系统上,内存地址以 64 位的二进制数字表示,由于表示形式太长,我们通常会转为十六进制,以方便阅读。</li></ul></div><h2 id="_5-2-内存中的变量" tabindex="-1">5.2 内存中的变量 <a class="header-anchor" href="#_5-2-内存中的变量" aria-label="Permalink to &quot;5.2 内存中的变量&quot;"></a></h2><ul><li>在 C 语言中数据类型的种类很多short、int、long、float、double、char 等。以 int 类型为例,在 32 位或 64 位操作系统中的int 类型的变量都是占 4 个字节,当我们在代码中这么定义变量,如:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(){</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义一个变量并初始化</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> a </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><ul><li>那么,编译器就会这么处理,如下所示:</li></ul><p><img src="/c/assets/37.EU7nYUIS.svg" alt="" loading="lazy"></p><ul><li>在代码中,我们可以使用 <code>&amp;变量名</code> 来获取一个变量的内存首地址,如下所示:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br></div></div><h2 id="_5-4-do-while-循环" tabindex="-1">5.4 do-while 循环 <a class="header-anchor" href="#_5-4-do-while-循环" aria-label="Permalink to &quot;5.4 do-while 循环&quot;"></a></h2><h3 id="_5-4-1-概述" tabindex="-1">5.4.1 概述 <a class="header-anchor" href="#_5-4-1-概述" aria-label="Permalink to &quot;5.4.1 概述&quot;"></a></h3><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">①初始化部分;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">do</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">{</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ③循环体部分</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ④迭代部分</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">while</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(②循环条件部分);</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li><code>do{} while();</code>最后有一个分号。</li><li>② do-while 结构的循环体语句是至少会执行一次,这个和 for 、while 是不一样的。</li><li>③ 循环的三个结构 for、while、do-while 三者是可以相互转换的。</li></ul></div><ul><li>流程图,如下所示:</li></ul><p><img src="/c/assets/9.TqkSPw2X.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>执行过程是:① --&gt; ③ --&gt; ④ --&gt; ② --&gt; ③ --&gt; ④ --&gt; ② --&gt; ... --&gt; ② 。</p></div><h3 id="_5-4-2-应用示例" tabindex="-1">5.4.2 应用示例 <a class="header-anchor" href="#_5-4-2-应用示例" aria-label="Permalink to &quot;5.4.2 应用示例&quot;"></a></h3><ul><li>需求:求 1 ~ 100 之内所有偶数的和,以及偶数的个数。</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义一个变量并初始化</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> a </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> sum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> count </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;变量 a 的首地址是: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%p\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">a);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 变量 a 的首地址是: 0000002bf1dffd0c</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;变量 a 的中保存的值是: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, a);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 变量 a 的中保存的值是: 10</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> do</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> sum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> count</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">while</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 100</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;1 ~ 100 中的所有偶数的和为: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, sum);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;1 ~ 100 中的所有偶数的个数为: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, count);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li><code>变量</code>是对程序中<code>数据</code>在内存中存储空间的抽象,如果不涉及到指针变量,那我们在编码的时候,就只需要将变量等价于内存中存储空间里面存储的数据,而不需要再去考虑编译器底层是如何转换,提高了开发效率(机器语言和汇编可不是这样的,需要关注每个细节)。</li><li>② 数据类型只在<code>定义</code>变量的时候<code>指定</code>,而且必须指定;<code>使用</code>变量的时候<code>无需</code>再声明,因为此时的数据类型已经确定了。</li></ul></div><h2 id="_5-3-内存中的数组" tabindex="-1">5.3 内存中的数组 <a class="header-anchor" href="#_5-3-内存中的数组" aria-label="Permalink to &quot;5.3 内存中的数组&quot;"></a></h2><ul><li>如果我们在代码中这么定义数组,如下所示:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br></div></div><h3 id="_5-4-3-应用示例" tabindex="-1">5.4.3 应用示例 <a class="header-anchor" href="#_5-4-3-应用示例" aria-label="Permalink to &quot;5.4.3 应用示例&quot;"></a></h3><ul><li><p>需求:实现 ATM 取款机功能。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 账户余额</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> balance </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0.0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 客户选择</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> selection;</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 存款金额</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> addMoney;</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 取款金额</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> minusMoney;</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 退出标识</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> bool</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> exitFlag </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> false</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> do</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;=========ATM========</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\t</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">1、存款</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\t</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">2、取款</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\t</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">3、显示余额</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\t</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">4、退出</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请选择(1-4)&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">selection);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> switch</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (selection) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;您当前的余额是: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%.2f\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, balance);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入存款金额:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%lf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">addMoney</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> balance </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> addMoney;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;存款成功,您当前的余额是:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%.2f\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, balance);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;您当前的余额是: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%.2f\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, balance);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入取款金额:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%lf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">minusMoney</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (minusMoney </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> balance) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;余额不足,取款失败。</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> balance </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> minusMoney;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;取款成功,您的余额为:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%.2f\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, balance);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;您的账户余额为:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%.2f\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, balance);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> exitFlag </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> true</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;欢迎下次再来。</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> default</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;输入有误,请重新输入。</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">while</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">!</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">exitFlag);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(){</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义一个数组并初始化</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><ul><li>那么,编译器就会这么处理,如下所示:</li></ul><p><img src="/c/assets/38.BMoE_Ep0.svg" alt="" loading="lazy"></p><ul><li>在代码中,我们可以直接打印数组名的内存地址,如下所示:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br><span class="line-number">45</span><br><span class="line-number">46</span><br><span class="line-number">47</span><br><span class="line-number">48</span><br><span class="line-number">49</span><br><span class="line-number">50</span><br><span class="line-number">51</span><br><span class="line-number">52</span><br><span class="line-number">53</span><br><span class="line-number">54</span><br><span class="line-number">55</span><br><span class="line-number">56</span><br><span class="line-number">57</span><br><span class="line-number">58</span><br></div></div><h2 id="_5-5-嵌套循环" tabindex="-1">5.5 嵌套循环 <a class="header-anchor" href="#_5-5-嵌套循环" aria-label="Permalink to &quot;5.5 嵌套循环&quot;"></a></h2><h3 id="_5-5-1-概述" tabindex="-1">5.5.1 概述 <a class="header-anchor" href="#_5-5-1-概述" aria-label="Permalink to &quot;5.5.1 概述&quot;"></a></h3><ul><li>所谓的嵌套循环,是指一个循环结构 A 的循环体是另一个循环结构 B 。例如for 循环里面还有一个for 循环,就是嵌套循环。</li><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(初始化语句①; 循环条件语句②; 迭代语句⑦) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(初始化语句③; 循环条件语句④; 迭代语句⑥) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 循环体语句⑤;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><ul><li>其中for 、while 、do-while 均可以作为外层循环或内层循环。 <ul><li>外层循环:循环结构 A</li><li>内层循环:循环结构 B</li></ul></li></ul><p><img src="/c/assets/10.DJkVOkw7.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 实际上,嵌套循环就是将内层循环当成外层循环的循环体。当只有内层循环的循环条件为 false ,才会完全跳出内层循环,才可结束外层的当次循环,开始下一次循环。</li><li>② 假设外层循环次数为 m 次,内层循环次数为 n 次,则内层循环体实际上需要执行 m × n 次。</li><li>③ 从二维图形的角度看,外层循环控制<code>行数</code>,内层循环控制<code>列数</code></li><li>④ 实际开发中,我们最多见到的嵌套循环是两层,一般不会出现超过三层的嵌套循环。如果将要出现,一定要停下来重新梳理业务逻辑,重新思考算法的实现,控制在三层以内;否则,可读性会很差。</li></ul></div><h3 id="_5-5-2-应用示例" tabindex="-1">5.5.2 应用示例 <a class="header-anchor" href="#_5-5-2-应用示例" aria-label="Permalink to &quot;5.5.2 应用示例&quot;"></a></h3><ul><li><p>需求:打印 5 行 <code>*</code> ,要求每行 6 个 <code>*</code></p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr 的首地址是: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%p</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, arr);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr 的首地址是: 0000003a6f7ffcd4</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr 的首地址是: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%p</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">arr);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // &amp;arr 的地址是: 0000003a6f7ffcd4</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[0] 的地址是: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%p</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[0] 的地址是: 0000003a6f7ffcd4</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[1] 的地址是: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%p</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[1] 的地址是: 0000003a6f7ffcd8</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[2] 的地址是: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%p</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[2] 的地址是: 0000003a6f7ffcdc</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">i) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 6</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">j) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;* &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><div class="warning custom-block github-alert"><p class="custom-block-title">WARNING</p><p></p><p>在上述示例中,<code>arr</code><code>&amp;arr</code> 的值是一样的,但是对应的含义是不同的。</p><ul><li><code>arr</code> 是数组名,在大多数情况下会转换为数组第一个元素的地址,即:<code>arr</code> 等价于 <code>&amp;arr[0]</code>,其数据类型是 <code>int *</code></li><li><code>&amp;arr</code>是数组名的地址,即整个数组的地址,它指向数组本身,并不是数组第一个元素的地址,<code>&amp;arr</code> 的数据类型是 <code>int(*)[3]</code></li></ul></div></div></div></main><footer class="VPDocFooter" data-v-39a288b8 data-v-e257564d><!--[--><!--]--><div class="edit-info" data-v-e257564d><!----><div class="last-updated" data-v-e257564d><p class="VPLastUpdated" data-v-e257564d data-v-e98dd255>上次更新: <time datetime="2024-08-12T02:47:17.000Z" data-v-e98dd255></time></p></div></div><nav class="prev-next" aria-labelledby="doc-footer-aria-label" data-v-e257564d><span class="visually-hidden" id="doc-footer-aria-label" data-v-e257564d>Pager</span><div class="pager" data-v-e257564d><a class="VPLink link pager-link prev" href="/c/notes/01_c-basic/04_xdx/" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>上一篇</span><span class="title" data-v-e257564d>流程控制</span><!--]--></a></div><div class="pager" data-v-e257564d><a class="VPLink link pager-link next" href="/c/notes/01_c-basic/06_xdx/" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>下一篇</span><span class="title" data-v-e257564d>指针</span><!--]--></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><footer class="VPFooter has-sidebar" data-v-5d98c3a5 data-v-e315a0ad><div class="container" data-v-e315a0ad><p class="message" data-v-e315a0ad>Released under the MIT License.</p><p class="copyright" data-v-e315a0ad>Copyright © 2024 许大仙</p></div></footer><!--[--><!--]--></div></div>
<script>window.__VP_HASH_MAP__=JSON.parse("{\"index.md\":\"Dga0tMF5\",\"notes_01_c-basic_00_xdx_index.md\":\"BRC7slaL\",\"notes_01_c-basic_01_xdx_index.md\":\"DvCUr2L0\",\"notes_01_c-basic_02_xdx_index.md\":\"CC2Mg9VD\",\"notes_01_c-basic_03_xdx_index.md\":\"CcATnhKW\",\"notes_01_c-basic_04_xdx_index.md\":\"DABEMZSO\",\"notes_01_c-basic_05_xdx_index.md\":\"CGbN5wss\",\"notes_01_c-basic_06_xdx_index.md\":\"CIGNaKYV\",\"notes_04_linux_01_xdx_index.md\":\"C9IatKsj\",\"notes_about_index.md\":\"DLuQgC_8\",\"notes_index.md\":\"CeV-uJ5V\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"zh-CN\",\"dir\":\"ltr\",\"title\":\"许大仙\",\"titleTemplate\":\"Hi终于等到你\",\"description\":\"许大仙前端、Java、大数据、云原生\",\"base\":\"/c/\",\"head\":[],\"router\":{\"prefetchLinks\":true},\"appearance\":true,\"themeConfig\":{\"lastUpdatedText\":\"上次更新\",\"returnToTopLabel\":\"返回顶部\",\"search\":{\"provider\":\"local\"},\"logo\":\"/logo.svg\",\"nav\":[{\"text\":\"首页\",\"link\":\"https://aexiar.github.io/\"},{\"text\":\"计组6件套\",\"link\":\"https://aexiar.github.io/coa6/notes/\"},{\"text\":\"编程语言\",\"items\":[{\"text\":\"c/c++\",\"link\":\"/notes/\"},{\"text\":\"前端\",\"link\":\"https://aexiar.github.io/web-design/notes/\"},{\"text\":\"Java\",\"link\":\"https://aexiar.github.io/java/notes/\"},{\"text\":\"大数据\",\"link\":\"https://aexiar.github.io/big-data/notes/\"},{\"text\":\"云原生\",\"link\":\"https://aexiar.github.io/linux/notes/\"},{\"text\":\"Go\",\"link\":\"https://aexiar.github.io/go/notes/\"},{\"text\":\"Python\",\"link\":\"https://aexiar.github.io/python/notes/\"}]},{\"text\":\"数据库\",\"link\":\"https://aexiar.github.io/db/notes/\"},{\"text\":\"开源软件\",\"link\":\"https://aexiar.github.io/open-software/notes/\"},{\"text\":\"关于我\",\"link\":\"/notes/about/\"}],\"sidebar\":{\"/notes/\":[{\"text\":\"C 语言基础\",\"collapsed\":true,\"items\":[{\"text\":\"编程基础\",\"link\":\"/notes/01_c-basic/00_xdx/\"},{\"text\":\"C 语言入门\",\"link\":\"/notes/01_c-basic/01_xdx/\"},{\"text\":\"变量和进制\",\"link\":\"/notes/01_c-basic/02_xdx/\"},{\"text\":\"数据类型和运算符\",\"link\":\"/notes/01_c-basic/03_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/01_c-basic/04_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/01_c-basic/05_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/01_c-basic/06_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/01_c-basic/07_xdx/\"},{\"text\":\"预处理器\",\"link\":\"/notes/01_c-basic/08_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/01_c-basic/09_xdx/\"},{\"text\":\"内存管理\",\"link\":\"/notes/01_c-basic/10_xdx/\"},{\"text\":\"文件操作\",\"link\":\"/notes/01_c-basic/11_xdx/\"},{\"text\":\"调试工具和调试技巧gdb和make\",\"link\":\"/notes/02_c-basic/13_xdx/\"},{\"text\":\"常用库函数\",\"link\":\"/notes/01_c-basic/13_xdx/\"}]},{\"text\":\"C 语言高级\",\"collapsed\":true,\"items\":[{\"text\":\"变量和内存分布\",\"link\":\"/notes/02_c-advance/01_xdx/\"},{\"text\":\"指针强化\",\"link\":\"/notes/02_c-advance/02_xdx/\"},{\"text\":\"结构体和文件的高级用法\",\"link\":\"/notes/02_c-advance/03_xdx/\"},{\"text\":\"链表和回调函数\",\"link\":\"/notes/02_c-advance/04_xdx/\"},{\"text\":\"编译过程和面向接口\",\"link\":\"/notes/02_c-advance/05_xdx/\"}]},{\"text\":\"项目构建工具\",\"collapsed\":true,\"items\":[{\"text\":\"meson\",\"collapsed\":true,\"items\":[{\"text\":\"meson 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Cmake\",\"collapsed\":true,\"items\":[{\"text\":\"Cmake 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Conan \",\"link\":\"/notes/03_build/01_${commonDirectoryName}/\"},{\"text\":\"Gradle\",\"collapsed\":true,\"items\":[{\"text\":\"Gradle 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]}]},{\"text\":\"Linux\",\"collapsed\":true,\"items\":[{\"text\":\"Linux 初识和安装\",\"link\":\"/notes/04_linux/01_xdx/\"}]},{\"text\":\"C++ 基础\",\"collapsed\":true,\"items\":[{\"text\":\"C++ 入门\",\"link\":\"/notes/05_cpp/01_xdx/\"},{\"text\":\"变量、数据类型、运算符\",\"link\":\"/notes/05_cpp/02_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/05_cpp/03_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/05_cpp/04_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/05_cpp/05_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/05_cpp/06_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/05_cpp/07_xdx/\"},{\"text\":\"类和对象\",\"link\":\"/notes/05_cpp/08_xdx/\"},{\"text\":\"C++ 引用\",\"link\":\"/notes/05_cpp/09_xdx/\"},{\"text\":\"继承和派生\",\"link\":\"/notes/05_cpp/10_xdx/\"},{\"text\":\"C++ 多态和虚函数\",\"link\":\"/notes/05_cpp/11_xdx/\"},{\"text\":\"运算符重载\",\"link\":\"/notes/05_cpp/12_xdx/\"},{\"text\":\"模板\",\"link\":\"/notes/05_cpp/13_xdx/\"},{\"text\":\"C++ 异常\",\"link\":\"/notes/05_cpp/14_xdx/\"},{\"text\":\"面向对象进阶\",\"link\":\"/notes/05_cpp/15_xdx/\"},{\"text\":\"文件操作和 IO 流\",\"link\":\"/notes/05_cpp/16_xdx/\"},{\"text\":\"STL标准模板库\",\"link\":\"/notes/05_cpp/17_xdx/\"}]},{\"text\":\"C++ 高级\",\"collapsed\":true,\"items\":[]},{\"text\":\"QT 桌面开发\",\"collapsed\":true,\"items\":[]},{\"text\":\"Linux 高并发服务器开发\",\"collapsed\":true,\"items\":[]}]},\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/Aurorxa\"}],\"docFooter\":{\"prev\":\"上一篇\",\"next\":\"下一篇\"},\"darkModeSwitchLabel\":\"深浅模式\",\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2024 许大仙\"},\"outline\":{\"level\":[1,6],\"label\":\"目录\"},\"outlineTitle\":\"当前页大纲\"},\"locales\":{},\"scrollOffset\":134,\"cleanUrls\":false}");</script>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><h3 id="_5-5-3-应用示例" tabindex="-1">5.5.3 应用示例 <a class="header-anchor" href="#_5-5-3-应用示例" aria-label="Permalink to &quot;5.5.3 应用示例&quot;"></a></h3><ul><li><p>需求:打印 5 行直角三角形。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">i) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">j) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;* &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><h3 id="_5-5-4-应用示例" tabindex="-1">5.5.4 应用示例 <a class="header-anchor" href="#_5-5-4-应用示例" aria-label="Permalink to &quot;5.5.4 应用示例&quot;"></a></h3><ul><li><p>需求:打印 5 行倒直角三角形。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">i) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 6</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> -</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">j) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;* &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><h3 id="_5-5-5-应用示例" tabindex="-1">5.5.5 应用示例 <a class="header-anchor" href="#_5-5-5-应用示例" aria-label="Permalink to &quot;5.5.5 应用示例&quot;"></a></h3><ul><li><p>需求:打印 9 <code>×</code> 9 乘法表。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 9</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">i) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">j) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> × </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, i, j, i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> j);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><h2 id="_5-6-无限循环" tabindex="-1">5.6 无限循环 <a class="header-anchor" href="#_5-6-无限循环" aria-label="Permalink to &quot;5.6 无限循环&quot;"></a></h2><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">while</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">){</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ...</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(;;){</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ...</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 在开发中有的时候并不确定需要循环多少次就需要根据循环体内部的某些条件来控制循环的结束break</li><li>② 如果上述的循环结构不能终止,就会构成死循环;所以,在实际开发中,要避免出现死循环!!!</li></ul></div><ul><li>示例:从键盘读入个数不确定的整数,并判断读入的正数和负数的个数,输入为 0 时结束程序</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 记录输入的整数</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 记录正数个数</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> positiveCount </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 记录负数个数</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> negativeCount </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> while</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">true</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入一个整数:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">num);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> positiveCount</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> negativeCount</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;程序结束!</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;正数的个数:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, positiveCount);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;负数的个数:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, negativeCount);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br></div></div><h2 id="_5-7-跳转控制语句" tabindex="-1">5.7 跳转控制语句 <a class="header-anchor" href="#_5-7-跳转控制语句" aria-label="Permalink to &quot;5.7 跳转控制语句&quot;"></a></h2><h3 id="_5-7-1-break" tabindex="-1">5.7.1 break <a class="header-anchor" href="#_5-7-1-break" aria-label="Permalink to &quot;5.7.1 break&quot;"></a></h3><ul><li>break 的使用场景break 语句用于终止某个语句块的执行用在switch语句或者循环语句中。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>break 一旦执行,就结束(或跳出)当前循环结构;并且,此关键字的后面,不能声明其它语句。</p></div><ul><li>流程图,如下所示:</li></ul><p><img src="/c/assets/11.Bkdbe2NL.png" alt="" loading="lazy"></p><ul><li>示例:打印 0 ~ 10 ,如果遇到 <code>3</code> ,就停止打印</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">i) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, i);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;程序结束!</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><ul><li>示例:编写程序,要求输入一个数字,判断该数字是否是质数</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> bool</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> isFlag </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> false</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> do</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入一个整数(必须大于 1 &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">num);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;输入的数字不是合法,请重新输入!!!</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> isFlag </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> true</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> isFlag </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> false</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">while</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (isFlag);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> bool</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> isPrime </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> true</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> isPrime </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> false</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (isPrime) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 是一个质数</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 不是一个质数</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;程序结束!</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br></div></div><h3 id="_5-7-2-continue" tabindex="-1">5.7.2 continue <a class="header-anchor" href="#_5-7-2-continue" aria-label="Permalink to &quot;5.7.2 continue&quot;"></a></h3><ul><li>continue 的使用场景continue 语句用于结束本次循环,继续执行下一次循环。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>continue 一旦执行,就结束(或跳出)当次循环结构;并且,此关键字的后面,不能声明其它语句。</p></div><ul><li>流程图,如下所示:</li></ul><p><img src="/c/assets/12.D2yeCvfw.png" alt="" loading="lazy"></p><ul><li>示例:打印 0 ~ 10 ,如果遇到 <code>3</code> ,就继续下一次打印</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">i) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> continue</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, i);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;程序结束!</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><ul><li>示例:输出 100 以内(包括 100的数字跳过那些 7 的倍数或包含 7 的数字</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 100</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 7</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ||</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 7</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ||</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 7</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> continue</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, i);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;程序结束!</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><h3 id="_5-7-3-return" tabindex="-1">5.7.3 return <a class="header-anchor" href="#_5-7-3-return" aria-label="Permalink to &quot;5.7.3 return&quot;"></a></h3><ul><li>return :并非专门用于结束循环的,它的功能是结束一个方法。当一个方法执行到一个 return 语句的时候,这个方法将被结束。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>和 break 和 continue 不同的是return 直接结束整个方法,不管这个 return 处于多少层循环之内。</p></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 100</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 7</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ||</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 7</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ||</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 7</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 结束整个函数或方法</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, i);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;程序结束!</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div></div></div></main><footer class="VPDocFooter" data-v-39a288b8 data-v-e257564d><!--[--><!--]--><div class="edit-info" data-v-e257564d><!----><div class="last-updated" data-v-e257564d><p class="VPLastUpdated" data-v-e257564d data-v-e98dd255>上次更新: <time datetime="2024-08-27T03:11:14.000Z" data-v-e98dd255></time></p></div></div><nav class="prev-next" aria-labelledby="doc-footer-aria-label" data-v-e257564d><span class="visually-hidden" id="doc-footer-aria-label" data-v-e257564d>Pager</span><div class="pager" data-v-e257564d><a class="VPLink link pager-link prev" href="/c/notes/01_c-basic/04_xdx/" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>上一篇</span><span class="title" data-v-e257564d>大话小数</span><!--]--></a></div><div class="pager" data-v-e257564d><a class="VPLink link pager-link next" href="/c/notes/01_c-basic/06_xdx/" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>下一篇</span><span class="title" data-v-e257564d>数组</span><!--]--></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><footer class="VPFooter has-sidebar" data-v-5d98c3a5 data-v-e315a0ad><div class="container" data-v-e315a0ad><p class="message" data-v-e315a0ad>Released under the MIT License.</p><p class="copyright" data-v-e315a0ad>Copyright © 2024 许大仙</p></div></footer><!--[--><!--]--></div></div>
<script>window.__VP_HASH_MAP__=JSON.parse("{\"index.md\":\"Dga0tMF5\",\"notes_01_c-basic_00_xdx_index.md\":\"BRC7slaL\",\"notes_01_c-basic_01_xdx_index.md\":\"Fg4OXydV\",\"notes_01_c-basic_02_xdx_index.md\":\"CC2Mg9VD\",\"notes_01_c-basic_03_xdx_index.md\":\"Cw3Z19MO\",\"notes_01_c-basic_04_xdx_index.md\":\"ySxH8sG-\",\"notes_01_c-basic_05_xdx_index.md\":\"DUbOwEts\",\"notes_01_c-basic_06_xdx_index.md\":\"CV_r2WNu\",\"notes_01_c-basic_07_xdx_index.md\":\"CE9q5cmu\",\"notes_04_linux_01_xdx_index.md\":\"C9IatKsj\",\"notes_about_index.md\":\"DLuQgC_8\",\"notes_index.md\":\"CeV-uJ5V\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"zh-CN\",\"dir\":\"ltr\",\"title\":\"许大仙\",\"titleTemplate\":\"Hi终于等到你\",\"description\":\"许大仙前端、Java、大数据、云原生\",\"base\":\"/c/\",\"head\":[],\"router\":{\"prefetchLinks\":true},\"appearance\":true,\"themeConfig\":{\"lastUpdatedText\":\"上次更新\",\"returnToTopLabel\":\"返回顶部\",\"search\":{\"provider\":\"local\"},\"logo\":\"/logo.svg\",\"nav\":[{\"text\":\"首页\",\"link\":\"https://aexiar.github.io/\"},{\"text\":\"计组6件套\",\"link\":\"https://aexiar.github.io/coa6/notes/\"},{\"text\":\"编程语言\",\"items\":[{\"text\":\"c/c++\",\"link\":\"/notes/\"},{\"text\":\"前端\",\"link\":\"https://aexiar.github.io/web-design/notes/\"},{\"text\":\"Java\",\"link\":\"https://aexiar.github.io/java/notes/\"},{\"text\":\"大数据\",\"link\":\"https://aexiar.github.io/big-data/notes/\"},{\"text\":\"云原生\",\"link\":\"https://aexiar.github.io/linux/notes/\"},{\"text\":\"Go\",\"link\":\"https://aexiar.github.io/go/notes/\"},{\"text\":\"Python\",\"link\":\"https://aexiar.github.io/python/notes/\"}]},{\"text\":\"数据库\",\"link\":\"https://aexiar.github.io/db/notes/\"},{\"text\":\"开源软件\",\"link\":\"https://aexiar.github.io/open-software/notes/\"},{\"text\":\"关于我\",\"link\":\"/notes/about/\"}],\"sidebar\":{\"/notes/\":[{\"text\":\"C 语言基础\",\"collapsed\":true,\"items\":[{\"text\":\"编程基础\",\"link\":\"/notes/01_c-basic/00_xdx/\"},{\"text\":\"C 语言入门\",\"link\":\"/notes/01_c-basic/01_xdx/\"},{\"text\":\"变量和进制\",\"link\":\"/notes/01_c-basic/02_xdx/\"},{\"text\":\"数据类型和运算符\",\"link\":\"/notes/01_c-basic/03_xdx/\"},{\"text\":\"大话小数\",\"link\":\"/notes/01_c-basic/04_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/01_c-basic/05_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/01_c-basic/06_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/01_c-basic/07_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/01_c-basic/08_xdx/\"},{\"text\":\"预处理器\",\"link\":\"/notes/01_c-basic/09_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/01_c-basic/10_xdx/\"},{\"text\":\"内存管理\",\"link\":\"/notes/01_c-basic/11_xdx/\"},{\"text\":\"文件操作\",\"link\":\"/notes/01_c-basic/12_xdx/\"},{\"text\":\"调试工具和调试技巧gdb和make\",\"link\":\"/notes/02_c-basic/13_xdx/\"},{\"text\":\"常用库函数\",\"link\":\"/notes/01_c-basic/14_xdx/\"}]},{\"text\":\"C 语言高级\",\"collapsed\":true,\"items\":[{\"text\":\"变量和内存分布\",\"link\":\"/notes/02_c-advance/01_xdx/\"},{\"text\":\"指针强化\",\"link\":\"/notes/02_c-advance/02_xdx/\"},{\"text\":\"结构体和文件的高级用法\",\"link\":\"/notes/02_c-advance/03_xdx/\"},{\"text\":\"链表和回调函数\",\"link\":\"/notes/02_c-advance/04_xdx/\"},{\"text\":\"编译过程和面向接口\",\"link\":\"/notes/02_c-advance/05_xdx/\"}]},{\"text\":\"项目构建工具\",\"collapsed\":true,\"items\":[{\"text\":\"meson\",\"collapsed\":true,\"items\":[{\"text\":\"meson 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Cmake\",\"collapsed\":true,\"items\":[{\"text\":\"Cmake 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Conan \",\"link\":\"/notes/03_build/01_${commonDirectoryName}/\"},{\"text\":\"Gradle\",\"collapsed\":true,\"items\":[{\"text\":\"Gradle 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]}]},{\"text\":\"Linux\",\"collapsed\":true,\"items\":[{\"text\":\"Linux 初识和安装\",\"link\":\"/notes/04_linux/01_xdx/\"}]},{\"text\":\"C++ 基础\",\"collapsed\":true,\"items\":[{\"text\":\"C++ 入门\",\"link\":\"/notes/05_cpp/01_xdx/\"},{\"text\":\"变量、数据类型、运算符\",\"link\":\"/notes/05_cpp/02_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/05_cpp/03_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/05_cpp/04_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/05_cpp/05_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/05_cpp/06_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/05_cpp/07_xdx/\"},{\"text\":\"类和对象\",\"link\":\"/notes/05_cpp/08_xdx/\"},{\"text\":\"C++ 引用\",\"link\":\"/notes/05_cpp/09_xdx/\"},{\"text\":\"继承和派生\",\"link\":\"/notes/05_cpp/10_xdx/\"},{\"text\":\"C++ 多态和虚函数\",\"link\":\"/notes/05_cpp/11_xdx/\"},{\"text\":\"运算符重载\",\"link\":\"/notes/05_cpp/12_xdx/\"},{\"text\":\"模板\",\"link\":\"/notes/05_cpp/13_xdx/\"},{\"text\":\"C++ 异常\",\"link\":\"/notes/05_cpp/14_xdx/\"},{\"text\":\"面向对象进阶\",\"link\":\"/notes/05_cpp/15_xdx/\"},{\"text\":\"文件操作和 IO 流\",\"link\":\"/notes/05_cpp/16_xdx/\"},{\"text\":\"STL标准模板库\",\"link\":\"/notes/05_cpp/17_xdx/\"}]},{\"text\":\"C++ 高级\",\"collapsed\":true,\"items\":[]},{\"text\":\"QT 桌面开发\",\"collapsed\":true,\"items\":[]},{\"text\":\"Linux 高并发服务器开发\",\"collapsed\":true,\"items\":[]}]},\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/Aurorxa\"}],\"docFooter\":{\"prev\":\"上一篇\",\"next\":\"下一篇\"},\"darkModeSwitchLabel\":\"深浅模式\",\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2024 许大仙\"},\"outline\":{\"level\":[1,6],\"label\":\"目录\"},\"outlineTitle\":\"当前页大纲\"},\"locales\":{},\"scrollOffset\":134,\"cleanUrls\":false}");</script>
</body>
</html>

View File

@ -3,16 +3,16 @@
<head>
<meta charset="utf-8">
<title>第一章:颇具争议的指针 | Hi终于等到你</title>
<title>第一章:数组的概念 | Hi终于等到你</title>
<meta name="description" content="许大仙前端、Java、大数据、云原生">
<meta name="generator" content="VitePress v1.3.3">
<link rel="preload stylesheet" href="/c/assets/style.zDJ0OJGU.css" as="style">
<script type="module" src="/c/assets/app.Ca2FOFw4.js"></script>
<script type="module" src="/c/assets/app.1a4d5P-6.js"></script>
<link rel="preload" href="/c/assets/inter-roman-latin.Di8DUHzh.woff2" as="font" type="font/woff2" crossorigin="">
<link rel="modulepreload" href="/c/assets/chunks/theme.C6fZfLtk.js">
<link rel="modulepreload" href="/c/assets/chunks/theme.Ddh-lpYV.js">
<link rel="modulepreload" href="/c/assets/chunks/framework.hMCIpNYY.js">
<link rel="modulepreload" href="/c/assets/notes_01_c-basic_06_xdx_index.md.CIGNaKYV.lean.js">
<link rel="modulepreload" href="/c/assets/notes_01_c-basic_06_xdx_index.md.CV_r2WNu.lean.js">
<link rel="shortcut icon" href="/c//logo.svg">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="">
<script id="register-sw">"serviceWorker"in navigator&&navigator.serviceWorker.register("/sw.js");</script>
@ -22,88 +22,707 @@
<script id="check-mac-os">document.documentElement.classList.toggle("mac",/Mac|iPhone|iPod|iPad/i.test(navigator.platform));</script>
</head>
<body>
<div id="app"><div class="Layout" data-v-5d98c3a5><!--[--><!--]--><!--[--><span tabindex="-1" data-v-0f60ec36></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-0f60ec36> Skip to content </a><!--]--><!----><header class="VPNav" data-v-5d98c3a5 data-v-ae24b3ad><div class="VPNavBar has-sidebar top" data-v-ae24b3ad data-v-6aa21345><div class="wrapper" data-v-6aa21345><div class="container" data-v-6aa21345><div class="title" data-v-6aa21345><div class="VPNavBarTitle has-sidebar" data-v-6aa21345 data-v-ab179fa1><a class="title" href="/c/" data-v-ab179fa1><!--[--><!--]--><!--[--><img class="VPImage logo" src="/c/logo.svg" alt data-v-8426fc1a><!--]--><span data-v-ab179fa1>许大仙</span><!--[--><!--]--></a></div></div><div class="content" data-v-6aa21345><div class="content-body" data-v-6aa21345><!--[--><!--]--><div class="VPNavBarSearch search" data-v-6aa21345><!--[--><!----><div id="local-search"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><span class="vp-icon DocSearch-Search-Icon"></span><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key">K</kbd></span></button></div><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-6aa21345 data-v-dc692963><span id="main-nav-aria-label" class="visually-hidden" data-v-dc692963> Main Navigation </span><!--[--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>首页</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/coa6/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>计组6件套</span><!--]--></a><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-dc692963 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-b6c34ac9><span class="text" data-v-b6c34ac9><!----><span data-v-b6c34ac9>编程语言</span><span class="vpi-chevron-down text-icon" data-v-b6c34ac9></span></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><div class="items" data-v-b98bc113><!--[--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link" href="/c/notes/" data-v-43f1e123><!--[-->c/c++<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/web-design/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->前端<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/java/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Java<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/big-data/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->大数据<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/linux/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->云原生<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/go/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Go<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/python/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Python<!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/db/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>数据库</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/open-software/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>开源软件</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/c/notes/about/" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>关于我</span><!--]--></a><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-6aa21345 data-v-6c893767><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-6c893767 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-6aa21345 data-v-0394ad82 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-6aa21345 data-v-bb2aa2f0 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-b6c34ac9><span class="vpi-more-horizontal icon" data-v-b6c34ac9></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><!----><!--[--><!--[--><!----><div class="group" data-v-bb2aa2f0><div class="item appearance" data-v-bb2aa2f0><p class="label" data-v-bb2aa2f0>深浅模式</p><div class="appearance-action" data-v-bb2aa2f0><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-bb2aa2f0 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div></div></div><div class="group" data-v-bb2aa2f0><div class="item social-links" data-v-bb2aa2f0><div class="VPSocialLinks social-links-list" data-v-bb2aa2f0 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div></div></div><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-6aa21345 data-v-e5dd9c1c><span class="container" data-v-e5dd9c1c><span class="top" data-v-e5dd9c1c></span><span class="middle" data-v-e5dd9c1c></span><span class="bottom" data-v-e5dd9c1c></span></span></button></div></div></div></div><div class="divider" data-v-6aa21345><div class="divider-line" data-v-6aa21345></div></div></div><!----></header><div class="VPLocalNav has-sidebar empty" data-v-5d98c3a5 data-v-a6f0e41e><div class="container" data-v-a6f0e41e><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-a6f0e41e><span class="vpi-align-left menu-icon" data-v-a6f0e41e></span><span class="menu-text" data-v-a6f0e41e>Menu</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-a6f0e41e data-v-17a5e62e><button data-v-17a5e62e>返回顶部</button><!----></div></div></div><aside class="VPSidebar" data-v-5d98c3a5 data-v-319d5ca6><div class="curtain" data-v-319d5ca6></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-319d5ca6><span class="visually-hidden" id="sidebar-aria-label" data-v-319d5ca6> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible has-active" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/00_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编程基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C 语言入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和进制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数据类型和运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>预处理器</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>内存管理</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-basic/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>调试工具和调试技巧gdb和make</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>常用库函数</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言高级</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和内存分布</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针强化</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>结构体和文件的高级用法</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>链表和回调函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编译过程和面向接口</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>项目构建工具</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>meson</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>meson 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Cmake</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Cmake 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_${commonDirectoryName}/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Conan </p><!--]--></a><!----></div><!----></div><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Gradle</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Gradle 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>Linux</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/04_linux/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Linux 初识和安装</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C++ 基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量、数据类型、运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>类和对象</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 引用</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>继承和派生</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 多态和虚函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/12_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>运算符重载</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>模板</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/14_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 异常</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/15_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>面向对象进阶</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/16_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作和 IO 流</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/17_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>STL标准模板库</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>C++ 高级</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>QT 桌面开发</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>Linux 高并发服务器开发</p><!----></div><!----></div></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-5d98c3a5 data-v-1428d186><div class="VPDoc has-sidebar has-aside" data-v-1428d186 data-v-39a288b8><!--[--><!--]--><div class="container" data-v-39a288b8><div class="aside" data-v-39a288b8><div class="aside-curtain" data-v-39a288b8></div><div class="aside-container" data-v-39a288b8><div class="aside-content" data-v-39a288b8><div class="VPDocAside" data-v-39a288b8 data-v-3f215769><!--[--><!--]--><!--[--><!--]--><nav aria-labelledby="doc-outline-aria-label" class="VPDocAsideOutline" data-v-3f215769 data-v-a5bbad30><div class="content" data-v-a5bbad30><div class="outline-marker" data-v-a5bbad30></div><div aria-level="2" class="outline-title" id="doc-outline-aria-label" role="heading" data-v-a5bbad30>目录</div><ul class="VPDocOutlineItem root" data-v-a5bbad30 data-v-b933a997><!--[--><!--]--></ul></div></nav><!--[--><!--]--><div class="spacer" data-v-3f215769></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-39a288b8><div class="content-container" data-v-39a288b8><!--[--><!--]--><main class="main" data-v-39a288b8><div style="position:relative;" class="vp-doc _c_notes_01_c-basic_06_xdx_" data-v-39a288b8><div><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li><code>指针</code>是 C 语言中<code>最重要</code>的概念之一,也是<code>最难以理解</code>的概念之一。</li><li><code>指针</code>是 C 语言的<code>精髓</code>,要想掌握 C 语言就需要深入地了解指针。</li></ul></div><h1 id="第一章-颇具争议的指针" tabindex="-1">第一章:颇具争议的指针 <a class="header-anchor" href="#第一章-颇具争议的指针" aria-label="Permalink to &quot;第一章:颇具争议的指针&quot;"></a></h1><h2 id="_1-1-概述" tabindex="-1">1.1 概述 <a class="header-anchor" href="#_1-1-概述" aria-label="Permalink to &quot;1.1 概述&quot;"></a></h2><ul><li>目前而言,操作系统几乎都是通过 C 语言来编写和维护的;而 C 语言提供了指针的用法,其能直接操作内存地址,是个非常<code>强大</code><code>灵活</code>的工具;但是,需要开发者<code>小心谨慎的使用</code>,以确保程序的稳定性和安全性。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>之所以指针在 C 语言中颇具争议,是因为一方面其功能强大,直接操作内存地址;另一方面,又很危险,不正确的使用指针的方式,非常容易导致程序崩溃。</p></div><ul><li><p>如果没有能很好的使用指针,就会带来一系列的问题,如:</p><ul><li><code>空指针引用</code>Null Pointer Dereference当一个指针没有正确初始化或者被赋予了空NULL值时如果程序尝试访问该指针所指向的内存会导致运行时错误甚至导致程序崩溃。</li><li><code>野指针</code>Dangling Pointers指针指向的内存地址曾经分配给某个变量或对象但后来该变量或对象被释放或者移动导致指针仍指向已经无效的内存位置。对野指针进行操作可能会导致未定义的行为或程序崩溃。</li><li><code>指针算术错误</code>:在进行指针运算时,如果没有正确管理指针的偏移量或者超出了数组的边界,可能会导致指针指向错误的内存位置,从而影响程序的正确性和安全性。</li><li><code>内存泄漏</code>:如果动态分配的内存通过指针分配,但在不再需要时没有正确释放,会导致内存泄漏,长时间运行的程序可能会耗尽系统资源。</li></ul></li><li><p>为了减少指针带来的风险,开发人员可以采取以下的措施:</p><ul><li><code>良好的编程实践</code>:确保指针的初始化和使用是安全的,避免空指针引用和野指针问题。</li><li><code>边界检查</code>:在进行指针运算时,始终确保不会超出数组或内存分配的边界。</li><li><code>使用指针和引用的适当性</code>:在可能的情况下,可以考虑使用更安全的语言特性,如:引用(在 C++ 等编程语言中)或者更高级别的数据结构来代替裸指针,从而减少指针使用时的潜在风险。</li></ul></li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li>① 既然指针很危险那么通过一系列的手段将指针包装或屏蔽以达到程序安全的目的这是现代化的高级编程语言解决的思路Java、Go、Rust 等)。</li><li>② 之所以指针还需要学习是因为在嵌入式等领域其机器的资源CPU、内存等非常有限而现代化的高级编程语言虽然安全但是需要的系统资源也庞大。</li><li>③ 我们知道编译型的程序不管编译过程如何复杂至少需要两步编译和运行。通常我们也将这两步称为编译期和运行期。C 语言中的指针之所以危险就在于程序要在运行的时候才会发现问题(后知后觉);而现代化的高级编程语言中的编译器在程序编译的时候就会发现问题(提前发现问题)。</li><li>④ C 语言的编译器之所以这么设计的原因,就在于当时的内存和 CPU 是非常有限PDP-7 早期小型计算机CPU18 bit 的电子管逻辑内存4kb 和昂贵72,000 $),如果加入安全限制的功能,会远远超过整个系统的资源。</li></ul></div><h2 id="_1-2-现代化高级编程语言是如何解决指针危险的" tabindex="-1">1.2 现代化高级编程语言是如何解决指针危险的? <a class="header-anchor" href="#_1-2-现代化高级编程语言是如何解决指针危险的" aria-label="Permalink to &quot;1.2 现代化高级编程语言是如何解决指针危险的&quot;"></a></h2><ul><li><p><code>C++</code>采用了如下的策略和机制,来解决指针危险操作的:</p><ul><li><code>智能指针</code> C++ 引入了智能指针(如<code>std::shared_ptr</code><code>std::unique_ptr</code>),这些指针提供了自动资源管理和所有权的语义。<code>std::unique_ptr</code>确保只有一个指针可以访问给定的资源,从而避免了传统指针的悬空引用和内存泄漏问题。<code>std::shared_ptr</code>允许多个指针共享一个资源,并在所有引用释放后自动释放。</li><li><code>引用</code> C++ 中的引用(如:<code>&amp;</code>符号)提供了更安全的间接访问方法,与指针相比,引用不能重新绑定到不同的对象,从而减少了意外的指针错误。</li></ul></li><li><p><code>Go</code>采用了如下的策略和机制,来解决指针危险操作的:</p><ul><li><code>内存管理和垃圾回收</code> Go 语言通过自动垃圾回收器管理内存减少了手动内存管理所带来的指针操作错误。Go 的垃圾回收器定期扫描并释放不再使用的内存,避免了内存泄漏和悬空指针问题。</li><li><code>指针的安全性</code> Go 语言的指针是受限的,不支持指针运算,从而减少了指针操作可能带来的风险。</li></ul></li><li><p><code>Rust</code>采用了如下的策略和机制,来解决指针危险操作的:</p><ul><li><code>所有权和借用</code> Rust 引入了所有权和借用的概念,编译器在编译时静态分析所有权转移和引用的生命周期。这种机制避免了数据竞争和空指针解引用等运行时错误,使得在编译时就能够保证内存安全。</li><li><code>生命周期</code> Rust 的生命周期系统确保引用的有效性和安全性,防止了悬空引用和指针乱用。</li></ul></li><li><p><code>Java</code>采用了如下的策略和机制,来解决指针危险操作的:</p><ul><li><code>引用类型和自动内存管理</code> Java 中所有的对象引用都是通过引用来访问的而不是直接的指针。Java 的自动垃圾回收器负责管理内存,从而避免了手动内存管理可能导致的指针错误,如:内存泄漏和悬空指针。</li><li><code>强类型系统和异常处理</code> Java 的强类型系统和异常处理机制减少了指针操作带来的风险空指针解引用异常NullPointerException。编译器在编译时能够捕获许多潜在的类型错误进一步增强了程序的安全性和可靠性。</li></ul></li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p>总而言之,各种编程语言通过引入不同的策略和机制,如:智能指针、垃圾回收器、所有权和借用,以及强类型系统,有效地减少了指针操作所带来的各种安全性和可靠性问题,提升了程序的稳定性和开发效率。</p></div><h1 id="第二章-回顾知识" tabindex="-1">第二章:回顾知识 <a class="header-anchor" href="#第二章-回顾知识" aria-label="Permalink to &quot;第二章:回顾知识&quot;"></a></h1><h2 id="_2-1-变量" tabindex="-1">2.1 变量 <a class="header-anchor" href="#_2-1-变量" aria-label="Permalink to &quot;2.1 变量&quot;"></a></h2><ul><li>变量就是保存程序运行过程中临时产生的值,其语法如下:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">数据类型 变量名 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 值 ;</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p>变量名(标识符)需要符合命名规则和命名规范!!!</p><ul><li>强制规范: <ul><li>① 只能由<code>小写</code><code>大写英文字母</code><code>0-9</code><code>_</code> 组成。</li><li>② 不能以<code>数字</code>开头。</li><li>③ 不可以是<code>关键字</code></li><li>④ 标识符具有<code>长度</code>限制,不同编译器和平台会有所不同,一般限制在 63 个字符内。</li><li>⑤ 严格<code>区分大小写字母</code>Hello、hello 是不同的标识符。</li></ul></li><li>建议规范: <ul><li>① 为了提高阅读性使用有意义的单词见名知意sumnamemaxyear 等。</li><li>② 使用下划线连接多个单词组成的标识符max_classes_per_student 等。</li><li>③ 多个单词组成的标识符,除了使用下划线连接,也可以使用小驼峰命名法,除第一个单词外,后续单词的首字母大写,如: studentId、student_name 等。</li><li>④ 不要出现仅靠大小写区分不同的标识符name、Name 容易混淆。</li><li>⑤ 系统内部使用了一些下划线开头的标识符C99 标准添加的类型 <code>_Bool</code>,为防止冲突,建议开发者尽量避免使用下划线开头的标识符。</li></ul></li></ul></div><ul><li><code>变量名</code><code>作用</code>,如下所示: <ul><li>① 当我们<code>编写</code>代码的时候,使用<code>变量名</code><code>关联</code>某块内存的<code>地址</code></li><li>② 当 CPU <code>执行</code>的时候,会将变量名<code>替换</code>为具体的地址,再进行具体的操作。</li></ul></li></ul><h2 id="_2-2-普通变量和指针变量的区别" tabindex="-1">2.2 普通变量和指针变量的区别 <a class="header-anchor" href="#_2-2-普通变量和指针变量的区别" aria-label="Permalink to &quot;2.2 普通变量和指针变量的区别&quot;"></a></h2><ul><li>根据<code>变量</code><code>存储</code><code></code><code>不同</code>,我们可以将<code>变量</code>分为两类: <ul><li><code>普通变量</code>:变量所对应的内存中存储的是<code>普通值</code></li><li><code>指针变量</code>:变量所对应的内存中存储的是<code>另一个变量的地址</code></li></ul></li><li>如下图所示:</li></ul><p><img src="/c/assets/1.L8V3GBrc.png" alt="img" loading="lazy"></p><ul><li>普通变量和指针变量的相同点,如下所示: <ul><li>① 普通变量有内存空间,指针变量也有内存空间。</li><li>② 普通变量有内存地址,指针变量也有内存地址。</li><li>③ 普通变量所对应的内存空间中有值,指针变量所对应的内存空间中也有值。</li></ul></li><li>普通变量和指针变量的不同点: <ul><li><code>普通变量</code>所对应的内存空间<code>存储</code>的是<code>普通的值</code>,如:整数、小数、字符等;<code>指针变量</code>所对应的内存空间<code>存储</code>的是另外一个变量的<code>地址</code></li><li><code>普通变量有普通变量的运算方式</code>,而<code>指针变量有指针变量的运算方式</code>(后续讲解)。</li></ul></li></ul><h2 id="_2-3-运算符" tabindex="-1">2.3 运算符 <a class="header-anchor" href="#_2-3-运算符" aria-label="Permalink to &quot;2.3 运算符&quot;"></a></h2><h3 id="_2-3-1-概述" tabindex="-1">2.3.1 概述 <a class="header-anchor" href="#_2-3-1-概述" aria-label="Permalink to &quot;2.3.1 概述&quot;"></a></h3><ul><li>运算符是一种特殊的符号,用于数据的运算、赋值和比较等。</li><li><code>表达式</code>指的是一组运算数、运算符的组合,表达式<code>一定具有值</code>,一个变量或一个常量可以是表达式,变量、常量和运算符也可以组成表达式,如:</li></ul><p><img src="/c/assets/2.CdvhiwcU.png" alt="img" loading="lazy"></p><ul><li><code>操作数</code>指的是<code>参与运算</code><code></code>或者<code>对象</code>,如:</li></ul><p><img src="/c/assets/3.D74t3-Xt.png" alt="" loading="lazy"></p><ul><li>根据<code>操作数</code><code>个数</code>,可以将运算符分为: <ul><li>一元运算符(一目运算符)。</li><li>二元运算符(二目运算符)。</li><li>三元运算符(三目运算符)。</li></ul></li><li>根据<code>功能</code>,可以将运算符分为: <ul><li>算术运算符。</li><li>关系运算符(比较运算符)。</li><li>逻辑运算符。</li><li>赋值运算符。</li><li>逻辑运算符。</li><li>位运算符。</li><li>三元运算符。</li></ul></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>掌握一个运算符,需要关注以下几个方面:</p><ul><li>① 运算符的含义。</li><li>② 运算符操作数的个数。</li><li>③ 运算符所组成的表达式。</li><li>④ 运算符有无副作用,即:运算后是否会修改操作数的值。</li></ul></div><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p>普通变量支持上述的所有运算符;而指针变量并非支持上述的所有运算符,且支持运算符的含义和普通变量相差较大!!!</p></div><h3 id="_2-3-2-运算符的优先级" tabindex="-1">2.3.2 运算符的优先级 <a class="header-anchor" href="#_2-3-2-运算符的优先级" aria-label="Permalink to &quot;2.3.2 运算符的优先级&quot;"></a></h3><ul><li>C 语言中运算符的优先级,如下所示:</li></ul><table tabindex="0"><thead><tr><th><strong>优先级</strong></th><th><strong>运算符</strong></th><th><strong>名称或含义</strong></th><th><strong>结合方向</strong></th></tr></thead><tbody><tr><td><strong>1</strong></td><td><code>[]</code></td><td>数组下标</td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>()</code></td><td>圆括号</td><td></td></tr><tr><td></td><td><code>.</code></td><td>成员选择(对象)</td><td></td></tr><tr><td></td><td><code>-&gt;</code></td><td>成员选择(指针)</td><td></td></tr><tr><td><strong>2</strong></td><td><code>-</code></td><td>负号运算符</td><td>⬅️(从右到左)</td></tr><tr><td></td><td><code>(类型)</code></td><td>强制类型转换</td><td></td></tr><tr><td></td><td><code>++</code></td><td>自增运算符</td><td></td></tr><tr><td></td><td><code>--</code></td><td>自减运算符</td><td></td></tr><tr><td></td><td><code>*</code></td><td>取值运算符</td><td></td></tr><tr><td></td><td><code>&amp;</code></td><td>取地址运算符</td><td></td></tr><tr><td></td><td><code>!</code></td><td>逻辑非运算符</td><td></td></tr><tr><td></td><td><code>~</code></td><td>按位取反运算符</td><td></td></tr><tr><td></td><td><code>sizeof</code></td><td>长度运算符</td><td></td></tr><tr><td><strong>3</strong></td><td><code>/</code></td><td></td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>*</code></td><td></td><td></td></tr><tr><td></td><td><code>%</code></td><td>余数(取模)</td><td></td></tr><tr><td><strong>4</strong></td><td><code>+</code></td><td></td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>-</code></td><td></td><td></td></tr><tr><td><strong>5</strong></td><td><code>&lt;&lt;</code></td><td>左移</td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>&gt;&gt;</code></td><td>右移</td><td></td></tr><tr><td><strong>6</strong></td><td><code>&gt;</code></td><td>大于</td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>&gt;=</code></td><td>大于等于</td><td></td></tr><tr><td></td><td><code>&lt;</code></td><td>小于</td><td></td></tr><tr><td></td><td><code>&lt;=</code></td><td>小于等于</td><td></td></tr><tr><td><strong>7</strong></td><td><code>==</code></td><td>等于</td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>!=</code></td><td>不等于</td><td></td></tr><tr><td><strong>8</strong></td><td><code>&amp;</code></td><td>按位与</td><td>➡️(从左到右)</td></tr><tr><td><strong>9</strong></td><td><code>^</code></td><td>按位异或</td><td>➡️(从左到右)</td></tr><tr><td><strong>10</strong></td><td><code>|</code></td><td>按位或</td><td>➡️(从左到右)</td></tr><tr><td><strong>11</strong></td><td><code>&amp;&amp;</code></td><td>逻辑与</td><td>➡️(从左到右)</td></tr><tr><td><strong>12</strong></td><td><code>||</code></td><td>逻辑或</td><td>➡️(从左到右)</td></tr><tr><td><strong>13</strong></td><td><code>?:</code></td><td>条件运算符</td><td>⬅️(从右到左)</td></tr><tr><td><strong>14</strong></td><td><code>=</code></td><td>赋值运算符</td><td>⬅️(从右到左)</td></tr><tr><td></td><td><code>/=</code></td><td>除后赋值</td><td></td></tr><tr><td></td><td><code>*=</code></td><td>乘后赋值</td><td></td></tr><tr><td></td><td><code>%=</code></td><td>取模后赋值</td><td></td></tr><tr><td></td><td><code>+=</code></td><td>加后赋值</td><td></td></tr><tr><td></td><td><code>-=</code></td><td>减后赋值</td><td></td></tr><tr><td></td><td><code>&lt;&lt;=</code></td><td>左移后赋值</td><td></td></tr><tr><td></td><td><code>&gt;&gt;=</code></td><td>右移后赋值</td><td></td></tr><tr><td></td><td><code>&amp;=</code></td><td>按位与后赋值</td><td></td></tr><tr><td></td><td><code>^=</code></td><td>按位异或后赋值</td><td></td></tr><tr><td></td><td><code>|=</code></td><td>按位或后赋值</td><td></td></tr><tr><td><strong>15</strong></td><td><code>,</code></td><td>逗号运算符</td><td>➡️(从左到右)</td></tr></tbody></table><div class="warning custom-block github-alert"><p class="custom-block-title">WARNING</p><p></p><ul><li>① 不要过多的依赖运算符的优先级来控制表达式的执行顺序,这样可读性太差,尽量<code>使用小括号来控制</code>表达式的执行顺序。</li><li>② 不要把一个表达式写得过于复杂,如果一个表达式过于复杂,则把它<code>分成几步</code>来完成。</li><li>③ 运算符优先级不用刻意地去记忆,总体上:一元运算符 &gt; 算术运算符 &gt; 关系运算符 &gt; 逻辑运算符 &gt; 三元运算符 &gt; 赋值运算符。</li></ul></div><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li>① 取值运算符 <code>*</code> 和取地址运算符 <code>&amp;</code> 的优先级相同,并且运算方向都是从右向左!!!</li><li>② 逗号运算符 <code>,</code> 的优先级最低,并且运算方向是从左向右!!!</li></ul></div><h1 id="第三章-指针的理解和定义-⭐" tabindex="-1">第三章:指针的理解和定义(⭐) <a class="header-anchor" href="#第三章-指针的理解和定义-⭐" aria-label="Permalink to &quot;第三章:指针的理解和定义(⭐)&quot;"></a></h1><h2 id="_3-1-变量的访问方式" tabindex="-1">3.1 变量的访问方式 <a class="header-anchor" href="#_3-1-变量的访问方式" aria-label="Permalink to &quot;3.1 变量的访问方式&quot;"></a></h2><ul><li>计算机中程序的运行都是在内存中进行的变量也是内存中分配的空间且不同类型的变量占据的内存空间大小不同char 类型的变量是 1 个字节short 类型的变量是 2 个字节int 类型的变量是 4 个字节...</li><li>之前我们都是通过<code>变量名(普通变量)</code>访问内存中存储的数据,如下所示</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<div id="app"><div class="Layout" data-v-5d98c3a5><!--[--><!--]--><!--[--><span tabindex="-1" data-v-0f60ec36></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-0f60ec36> Skip to content </a><!--]--><!----><header class="VPNav" data-v-5d98c3a5 data-v-ae24b3ad><div class="VPNavBar has-sidebar top" data-v-ae24b3ad data-v-6aa21345><div class="wrapper" data-v-6aa21345><div class="container" data-v-6aa21345><div class="title" data-v-6aa21345><div class="VPNavBarTitle has-sidebar" data-v-6aa21345 data-v-ab179fa1><a class="title" href="/c/" data-v-ab179fa1><!--[--><!--]--><!--[--><img class="VPImage logo" src="/c/logo.svg" alt data-v-8426fc1a><!--]--><span data-v-ab179fa1>许大仙</span><!--[--><!--]--></a></div></div><div class="content" data-v-6aa21345><div class="content-body" data-v-6aa21345><!--[--><!--]--><div class="VPNavBarSearch search" data-v-6aa21345><!--[--><!----><div id="local-search"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><span class="vp-icon DocSearch-Search-Icon"></span><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key">K</kbd></span></button></div><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-6aa21345 data-v-dc692963><span id="main-nav-aria-label" class="visually-hidden" data-v-dc692963> Main Navigation </span><!--[--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>首页</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/coa6/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>计组6件套</span><!--]--></a><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-dc692963 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-b6c34ac9><span class="text" data-v-b6c34ac9><!----><span data-v-b6c34ac9>编程语言</span><span class="vpi-chevron-down text-icon" data-v-b6c34ac9></span></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><div class="items" data-v-b98bc113><!--[--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link" href="/c/notes/" data-v-43f1e123><!--[-->c/c++<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/web-design/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->前端<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/java/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Java<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/big-data/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->大数据<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/linux/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->云原生<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/go/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Go<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/python/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Python<!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/db/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>数据库</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/open-software/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>开源软件</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/c/notes/about/" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>关于我</span><!--]--></a><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-6aa21345 data-v-6c893767><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-6c893767 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-6aa21345 data-v-0394ad82 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-6aa21345 data-v-bb2aa2f0 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-b6c34ac9><span class="vpi-more-horizontal icon" data-v-b6c34ac9></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><!----><!--[--><!--[--><!----><div class="group" data-v-bb2aa2f0><div class="item appearance" data-v-bb2aa2f0><p class="label" data-v-bb2aa2f0>深浅模式</p><div class="appearance-action" data-v-bb2aa2f0><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-bb2aa2f0 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div></div></div><div class="group" data-v-bb2aa2f0><div class="item social-links" data-v-bb2aa2f0><div class="VPSocialLinks social-links-list" data-v-bb2aa2f0 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div></div></div><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-6aa21345 data-v-e5dd9c1c><span class="container" data-v-e5dd9c1c><span class="top" data-v-e5dd9c1c></span><span class="middle" data-v-e5dd9c1c></span><span class="bottom" data-v-e5dd9c1c></span></span></button></div></div></div></div><div class="divider" data-v-6aa21345><div class="divider-line" data-v-6aa21345></div></div></div><!----></header><div class="VPLocalNav has-sidebar empty" data-v-5d98c3a5 data-v-a6f0e41e><div class="container" data-v-a6f0e41e><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-a6f0e41e><span class="vpi-align-left menu-icon" data-v-a6f0e41e></span><span class="menu-text" data-v-a6f0e41e>Menu</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-a6f0e41e data-v-17a5e62e><button data-v-17a5e62e>返回顶部</button><!----></div></div></div><aside class="VPSidebar" data-v-5d98c3a5 data-v-319d5ca6><div class="curtain" data-v-319d5ca6></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-319d5ca6><span class="visually-hidden" id="sidebar-aria-label" data-v-319d5ca6> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible has-active" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/00_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编程基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C 语言入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和进制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数据类型和运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>大话小数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>预处理器</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>内存管理</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/12_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-basic/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>调试工具和调试技巧gdb和make</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/14_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>常用库函数</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言高级</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和内存分布</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针强化</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>结构体和文件的高级用法</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>链表和回调函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编译过程和面向接口</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>项目构建工具</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>meson</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>meson 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Cmake</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Cmake 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_${commonDirectoryName}/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Conan </p><!--]--></a><!----></div><!----></div><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Gradle</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Gradle 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>Linux</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/04_linux/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Linux 初识和安装</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C++ 基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量、数据类型、运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>类和对象</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 引用</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>继承和派生</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 多态和虚函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/12_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>运算符重载</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>模板</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/14_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 异常</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/15_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>面向对象进阶</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/16_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作和 IO 流</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/17_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>STL标准模板库</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>C++ 高级</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>QT 桌面开发</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>Linux 高并发服务器开发</p><!----></div><!----></div></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-5d98c3a5 data-v-1428d186><div class="VPDoc has-sidebar has-aside" data-v-1428d186 data-v-39a288b8><!--[--><!--]--><div class="container" data-v-39a288b8><div class="aside" data-v-39a288b8><div class="aside-curtain" data-v-39a288b8></div><div class="aside-container" data-v-39a288b8><div class="aside-content" data-v-39a288b8><div class="VPDocAside" data-v-39a288b8 data-v-3f215769><!--[--><!--]--><!--[--><!--]--><nav aria-labelledby="doc-outline-aria-label" class="VPDocAsideOutline" data-v-3f215769 data-v-a5bbad30><div class="content" data-v-a5bbad30><div class="outline-marker" data-v-a5bbad30></div><div aria-level="2" class="outline-title" id="doc-outline-aria-label" role="heading" data-v-a5bbad30>目录</div><ul class="VPDocOutlineItem root" data-v-a5bbad30 data-v-b933a997><!--[--><!--]--></ul></div></nav><!--[--><!--]--><div class="spacer" data-v-3f215769></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-39a288b8><div class="content-container" data-v-39a288b8><!--[--><!--]--><main class="main" data-v-39a288b8><div style="position:relative;" class="vp-doc _c_notes_01_c-basic_06_xdx_" data-v-39a288b8><div><h1 id="第一章-数组的概念" tabindex="-1">第一章:数组的概念 <a class="header-anchor" href="#第一章-数组的概念" aria-label="Permalink to &quot;第一章:数组的概念&quot;"></a></h1><h2 id="_1-1-为什么需要数组" tabindex="-1">1.1 为什么需要数组? <a class="header-anchor" href="#_1-1-为什么需要数组" aria-label="Permalink to &quot;1.1 为什么需要数组&quot;"></a></h2><h3 id="_1-1-1-需求分析-1" tabindex="-1">1.1.1 需求分析 1 <a class="header-anchor" href="#_1-1-1-需求分析-1" aria-label="Permalink to &quot;1.1.1 需求分析 1&quot;"></a></h3><ul><li>需要统计某公司 50 个员工的工资情况,例如:计算平均工资、最高工资等。如果使用之前的知识,我们需要声明 50 个变量来分别记录每位员工的工资,即</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义变量,即:开辟一块内存空间,并将初始化值存储进去</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 访问变量,即:访问变量在内存中对应的数据</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;num = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 给变量赋值,即:给变量在内存中占据的内存空间存储数据</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 100</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 访问变量,即:访问变量在内存中对应的数据</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;num = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br></div></div><ul><li>上述的这种方式也称为<code>直接访问</code>;当然,既然有<code>直接访问</code>的方式,必然有<code>间接访问</code>的方式,如:<code>指针</code></li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li>① 我们通过<code>变量名(普通变量)</code>访问内存中变量存储的数据,之所以称为<code>直接访问</code>的方式,是因为对于我们写程序而言,我们无需关心如何根据内存地址去获取内存中对应的数据,也无需关系如何根据内存地址将数据存储到对应的内存空间,这些操作步骤都是<code>编译器</code>帮助我们在底层自动完成的(自动化)。</li><li>② 但是,我们也可以通过<code>内存地址</code>去操作内存中对应的数据(手动化),这种方式就称为<code>间接访问</code>的方式了,相对于<code>直接访问</code>方式来说,要<code>理解</code><code>概念</code><code>操作</code><code>步骤</code>和之前<code>直接访问</code>的方式相比,要复杂和麻烦很多,但是效率高。</li></ul></div><h2 id="_3-2-内存地址和指针" tabindex="-1">3.2 内存地址和指针 <a class="header-anchor" href="#_3-2-内存地址和指针" aria-label="Permalink to &quot;3.2 内存地址和指针&quot;"></a></h2><ul><li>其实,在之前《数组》中,我们就已经讲解了<code>内存地址</code>的概念了,即:操作系统为了更快的去管理内存中的数据,会将<code>内存条</code>按照<code>字节</code>划分为一个个的<code>单元格</code>,并为每个独立的小的<code>单元格</code>,分配<code>唯一的编号</code>,即:<code>内存地址</code>,如下所示:</li></ul><p><img src="/c/assets/4.DqDR6Thp.svg" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>有了内存地址,就能加快数据的存取速度,可以类比生活中的<code>字典</code>,即:</p><ul><li>① 内存地址是计算机中用于标识内存中某个特定位置的数值。</li><li>② 每个内存单元都有一个唯一的地址,这些地址可以用于访问和操作存储在内存中的数据。</li></ul></div><ul><li>对于之前的代码,如下所示:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义变量,即:开辟一块内存空间,并将初始化值存储进去</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><ul><li>虽然,之前我们在程序中都是通过<code>变量名(普通变量)</code>直接操作内存中的存储单元;但是,编译器底层还是会通过<code>内存地址</code>来找到所需要的存储单元,如下所示:</li></ul><p><img src="/c/assets/5.BzSkS-4w.svg" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>通过<code>内存地址</code>找到所需要的<code>存储单元</code>,即:内存地址指向该存储单元。此时,就可以将<code>内存地址</code>形象化的描述为<code>指针👉</code>,那么:</p><ul><li><code>变量</code>:命名的内存空间,用于存放各种类型的数据。</li><li><code>变量名</code>:变量名是给内存空间取一个容易记忆的名字,方便我们编写程序。</li><li><code>变量值</code>:变量所对应的内存中的存储单元中存放的数据值。</li><li><code>变量的地址</code>:变量所对应的内存中的存储单元的内存地址(首地址),也可以称为<code>指针</code></li></ul><p>总结:内存地址 = 指针。</p></div><ul><li><code>普通变量</code>所对应的内存空间<code>存储</code>的是<code>普通的值</code>,如:整数、小数、字符等;<code>指针变量</code>所对应的内存空间<code>存储</code>的是另外一个变量的<code>地址(指针)</code>,如下所示:</li></ul><p><img src="/c/assets/6.BPY9ZGed.svg" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>有的时候,为了方便阐述,我们会将<code>指针变量</code>称为<code>指针</code>。但是,需要记住的是:</p><ul><li>指针 = 内存地址。</li><li>指针变量 = 变量中保存的是另一个变量的地址。</li></ul><p>下文中提及的<code>指针</code>都是<code>指针变量</code>,不再阐述!!!</p></div><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p>如果你观察仔细的话,你可能会发现<code>指针变量</code><code>普通变量</code>在内存中占据的存储空间是不一样的,那么到底是什么原因造成这样的结果?</p></div><h2 id="_3-3-指针变量的定义" tabindex="-1">3.3 指针变量的定义 <a class="header-anchor" href="#_3-3-指针变量的定义" aria-label="Permalink to &quot;3.3 指针变量的定义&quot;"></a></h2><h2 id="_3-4-指针的作用" tabindex="-1">3.4 指针的作用 <a class="header-anchor" href="#_3-4-指针的作用" aria-label="Permalink to &quot;3.4 指针的作用&quot;"></a></h2><ul><li>查询数据。</li><li>存储数据。</li><li>参数传递。</li><li>内存管理。</li></ul><p>在 Java 中引用数据类型的向上类型转换upcasting和向下类型转换downcasting是面向对象编程中常见的操作。这些转换是 Java 继承体系和多态性的重要部分。我们先分别介绍向上类型转换和向下类型转换,然后讨论它们在 C 语言中指针的类似操作。</p><h3 id="向上类型转换-upcasting" tabindex="-1">向上类型转换Upcasting <a class="header-anchor" href="#向上类型转换-upcasting" aria-label="Permalink to &quot;向上类型转换Upcasting&quot;"></a></h3><p>向上类型转换是将一个子类对象引用转换为父类对象引用。由于子类继承了父类的所有方法和属性,子类对象也包含父类对象的所有部分,因此这种转换是安全且隐式的。</p><p><strong>例子:</strong></p><div class="language-java vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">java</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">class</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Animal</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> void</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> makeSound</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> System.out.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">println</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;Animal sound&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">class</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Dog</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> extends</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Animal</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> void</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> makeSound</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> System.out.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">println</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;Bark&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">public</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> class</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> public</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> static</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> void</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">String</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[] </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">args</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Dog dog </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> new</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Dog</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">();</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Animal animal </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> dog; </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// Upcasting, 隐式转换</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> animal.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">makeSound</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(); </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 输出Bark</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br></div></div><p>在这个例子中,<code>Dog</code> 类型的对象 <code>dog</code> 被转换为 <code>Animal</code> 类型。尽管 <code>animal</code> 引用的实际对象是 <code>Dog</code>,但在编译时,<code>animal</code> 被视为 <code>Animal</code> 类型。</p><h3 id="向下类型转换-downcasting" tabindex="-1">向下类型转换Downcasting <a class="header-anchor" href="#向下类型转换-downcasting" aria-label="Permalink to &quot;向下类型转换Downcasting&quot;"></a></h3><p>向下类型转换是将一个父类对象引用转换为子类对象引用。由于父类对象不一定具有子类的所有方法和属性,因此这种转换需要显式进行,并且在运行时进行类型检查(使用 <code>instanceof</code> 关键字来确保安全)。</p><p><strong>例子:</strong></p><div class="language-java vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">java</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">public</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> class</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> public</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> static</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> void</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">String</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[] </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">args</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Animal animal </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> new</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Dog</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(); </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// Upcasting</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (animal </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">instanceof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Dog) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Dog dog </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (Dog) animal; </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// Downcasting, 显式转换</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> dog.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">makeSound</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(); </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 输出Bark</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><p>在这个例子中,<code>animal</code> 引用的对象实际是 <code>Dog</code> 类型,在向下转换之前使用 <code>instanceof</code> 检查以确保安全。</p><h3 id="区别" tabindex="-1">区别 <a class="header-anchor" href="#区别" aria-label="Permalink to &quot;区别&quot;"></a></h3><ul><li><strong>向上类型转换</strong>:隐式的,安全的,因为子类是父类的扩展。</li><li><strong>向下类型转换</strong>:显式的,可能不安全,需要运行时检查,因为父类不一定具有子类的特性。</li></ul><h3 id="c-语言中的指针转换" tabindex="-1">C 语言中的指针转换 <a class="header-anchor" href="#c-语言中的指针转换" aria-label="Permalink to &quot;C 语言中的指针转换&quot;"></a></h3><p>在 C 语言中,指针的转换类似于引用类型的转换,但由于 C 语言没有继承和多态的概念,其转换更多是基于内存布局。</p><p><strong>例子:</strong></p><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">void</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printInt</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">void*</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> ptr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)ptr);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> x </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> void*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> voidPtr </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">x;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // Upcasting, 隐式转换</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printInt</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(voidPtr);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 输出10</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(){</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> intPtr </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)voidPtr;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // Downcasting, 显式转换</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">intPtr);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 输出10</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num1 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num2 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num3 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ...</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入第 1 个员工的工资:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%lf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">num1);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入第 2 个员工的工资:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%lf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">num2);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入第 3 个员工的工资:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%lf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">num3);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ... </span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><p>在这个例子中,<code>void*</code> 是通用指针类型,可以指向任何类型的数据。将 <code>int*</code> 转换为 <code>void*</code> 是隐式的,而将 <code>void*</code> 转换为 <code>int*</code> 是显式的。由于 C 没有类型检查,因此这种转换需要程序员自己确保安全。</p><p>总结:</p><ul><li>Java 中的向上类型转换和向下类型转换是为了支持多态性和继承,向上转换是安全的,向下转换需要显式进行并且进行运行时检查。</li><li>C 语言中的指针转换没有多态性和继承的概念,但有类似的指针类型转换操作,程序员需要确保转换的安全性。</li></ul><h1 id="第四章-指针的运算-⭐" tabindex="-1">第四章:指针的运算(⭐) <a class="header-anchor" href="#第四章-指针的运算-⭐" aria-label="Permalink to &quot;第四章:指针的运算(⭐)&quot;"></a></h1><h2 id="_4-1-概述" tabindex="-1">4.1 概述 <a class="header-anchor" href="#_4-1-概述" aria-label="Permalink to &quot;4.1 概述&quot;"></a></h2><h2 id="_4-2-总结" tabindex="-1">4.2 总结 <a class="header-anchor" href="#_4-2-总结" aria-label="Permalink to &quot;4.2 总结&quot;"></a></h2><ul><li><p>在 C 语言中,<code>普通变量</code>是直接存储<code>数据</code><code>变量</code>。对于普通变量,支持的操作包括:</p><ul><li><strong>赋值操作</strong>:给变量赋值,如:<code>int a = 5</code></li><li><strong>算术运算</strong>:可以对数值类型的普通变量进行加、减、乘、除等运算,如:<code>a + b</code><code>a - b</code><code>a * b</code><code>a / b</code></li><li><strong>关系运算</strong>:可以进行比较运算(大于、小于、等于等),如: <code>a &gt; b</code><code>a == b</code></li><li><strong>逻辑运算</strong>:对布尔类型的值进行与、或、非运算,如: <code>a &amp;&amp; b</code><code>a || b</code><code>!a</code></li><li><strong>位运算</strong>:对整数类型的值进行位操作(与、或、异或、取反、左移、右移等),如: <code>a &amp; b</code><code>a | b</code><code>a ^ b</code><code>~a</code><code>a &lt;&lt; 2</code><code>a &gt;&gt; 2</code></li><li><strong>自增自减运算</strong><code>a++</code><code>--a</code> 等。</li></ul></li><li><p>在 C 语言中,<code>指针变量</code>存储的是<code>另一个变量</code><code>地址</code>。对于指针变量,支持的操作包括:</p><ul><li><strong>赋值操作</strong>:可以将一个地址赋值给指针,如: <code>int *p = &amp;a;</code></li><li><strong>解引用操作</strong>:通过指针访问它指向的变量,如: <code>*p = 10;</code> 修改指向变量的值。</li><li><strong>指针运算</strong> <ul><li><strong>指针和整数值的加减运算</strong>:指针可以进行整数的加减运算,用于访问数组或结构体成员,如: <code>p + 1</code></li><li><strong>指针的自增和自减运算</strong>:指的是内存地址的向前或向后移动,如:<code>p++</code><code>p--</code></li><li><strong>指针间的相减运算</strong>:两个指向同一数组的指针相减可以得到它们之间的元素个数,如: <code>ptr1 - ptr2</code></li><li><strong>指针间的比较运算</strong>:可以比较两个指针的大小,比较的是各自内存地址的大小,如: <code>p1 == p2</code><code>p1 != p2</code></li></ul></li><li><strong>数组访问</strong>:指针可以用于访问数组中的元素,通过 <code>*(p + i)</code> 访问第 <code>i</code> 个元素。</li><li><strong>指向指针的指针</strong>:可以声明指向指针的指针,即多级指针,如:<code>int **pp = &amp;p;</code></li></ul></li></ul><div class="warning custom-block github-alert"><p class="custom-block-title">WARNING</p><p></p><p>在使用指针时,务必小心避免野指针和内存泄漏等问题。</p></div><p>在C语言中同类指针相减的结果是一个整数它表示两个指针之间相隔多少个指向的对象单位而不是它们在内存中的字节偏移量。这种对象单位是指针所指向的具体类型的大小。</p><p>举个例子来说,如果你有两个指向整数数组元素的指针 <code>p</code><code>q</code>,那么 <code>p - q</code> 的结果将是 <code>p</code> 指向的数组元素的索引与 <code>q</code> 指向的数组元素索引之间的差值。这个差值代表了在数组中相隔多少个整数元素,而不是它们在内存中的字节偏移量。</p><p>这种设计的优势在于,它使得指针运算更加直观和便于理解,特别是在处理数组和其他连续存储的数据结构时。因为指针运算结果的单位是根据指针所指向的具体类型来计算的,这样可以确保不同平台上的程序行为是一致的,不会受到底层硬件架构或者字节对齐规则的影响。</p><p>在C语言中数组名和指针有很多相似之处但数组名并不是指针变量。数组名实际是一个常量它指向数组的第一个元素的地址。为了证明这一点可以通过以下几个方面来说明</p><ol><li><p><strong>数组名表示数组首地址</strong> 数组名可以作为一个指针使用,数组名本身表示的是数组首地址。</p><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">ptr </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 这句话是合法的ptr现在指向arr[0]</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%p\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, arr);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 打印数组名,会打印数组首地址</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%p\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 打印第一个元素的地址</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div></li><li><p><strong>数组名是常量指针</strong> 数组名是一个常量指针,不能改变它指向的位置,而指针变量可以改变它指向的位置。</p><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">ptr </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 合法ptr指向arr[0]</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">ptr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 合法ptr现在指向arr[1]</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div><ul><li>这样会感觉特别机械和麻烦全是复制Ctrl + c和粘贴Ctrl + vCV 大法);此时,我们就可以将所有的<code>数据</code>全部存储到一个<code>容器(数组)</code>中进行统一管理,并进行其它的操作,如:求最值、求平均值等,如下所示:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// arr++; // 非法,编译错误,因为数组名是常量,不能改变</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div></li><li><p><strong>sizeof运算符的结果不同</strong> 使用<code>sizeof</code>运算符对数组名和指针变量会得到不同的结果,数组名会返回整个数组的大小,而指针变量会返回指针本身的大小。</p><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">ptr </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(){</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 声明数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> double</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> nums</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">50</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 数组的长度</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(nums) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 使用 for 循环向数组中添加值</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length;i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">){</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入第 &amp;d 个员工的工资:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,i);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%lf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">num</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 其它操作,如:求最值,求平均值等</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ... </span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><h3 id="_1-1-2-需求分析-2" tabindex="-1">1.1.2 需求分析 2 <a class="header-anchor" href="#_1-1-2-需求分析-2" aria-label="Permalink to &quot;1.1.2 需求分析 2&quot;"></a></h3><ul><li>在现实生活中,我们会使用很多 APP 或微信小程序等,即:</li></ul><p><img src="/c/assets/1.CvTjP5jN.png" alt="" loading="lazy"></p><ul><li>同样的道理,如果我们使用变量来存储每个商品信息,那么就需要非常多的变量;但是,如果我们将这些<code>商品信息</code>都存储到一个<code>容器(数组)</code>中,进行统一管理;那么,之后的数据处理将会非常方便。</li></ul><h3 id="_1-1-3-容器的概念" tabindex="-1">1.1.3 容器的概念 <a class="header-anchor" href="#_1-1-3-容器的概念" aria-label="Permalink to &quot;1.1.3 容器的概念&quot;"></a></h3><ul><li><code>生活中的容器</code>:水杯(装水、饮料的容器)、衣柜(装衣服等物品的容器)、集装箱(装货物等物品的容器)。</li><li><code>程序中的容器</code>:将多个数据存储到一起,并且每个数据称为该容器中的元素。</li></ul><h2 id="_1-2-什么是数组" tabindex="-1">1.2 什么是数组? <a class="header-anchor" href="#_1-2-什么是数组" aria-label="Permalink to &quot;1.2 什么是数组?&quot;"></a></h2><ul><li>数组Array是将多个<code>相同数据类型</code><code>数据</code>按照一定的顺序排序的<code>集合</code>,并使用一个<code>标识符</code>命名,以及通过<code>编号(索引,亦称为下标)</code>的方式对这些数据进行统一管理。</li></ul><p><img src="/c/assets/2.BR4TvWzU.png" alt="" loading="lazy"></p><h2 id="_1-3-数组的相关概念" tabindex="-1">1.3 数组的相关概念 <a class="header-anchor" href="#_1-3-数组的相关概念" aria-label="Permalink to &quot;1.3 数组的相关概念&quot;"></a></h2><ul><li><code>数组名</code>:本质上是一个标识符常量,命名需要符合标识符规则和规范。</li><li><code>元素</code>:同一个数组中的元素必须是相同的数据类型。</li><li><code>索引(下标)</code>:从 0 开始的连续数字。</li><li><code>数组的长度</code>:就是元素的个数。</li></ul><h2 id="_1-4-数组的特点" tabindex="-1">1.4 数组的特点 <a class="header-anchor" href="#_1-4-数组的特点" aria-label="Permalink to &quot;1.4 数组的特点&quot;"></a></h2><ul><li>① 创建数组的时候,会在内存中开辟一整块<code>连续的空间</code>,占据空间的大小,取决于数组的长度和数组中元素的类型。</li><li>② 数组中的元素在内存中是依次紧密排列且有序的。</li><li>③ 数组一旦初始化完成,且长度就确定的,并且<code>数组的长度一旦确定,就不能更改</code></li><li>④ 我们可以直接通过索引(下标)来获取指定位置的元素,速度很快。</li><li>⑤ 数组名中引用的是这块连续空间的首地址。</li></ul><h1 id="第二章-数组的操作-⭐" tabindex="-1">第二章:数组的操作(⭐) <a class="header-anchor" href="#第二章-数组的操作-⭐" aria-label="Permalink to &quot;第二章:数组的操作(⭐)&quot;"></a></h1><h2 id="_2-1-数组的定义" tabindex="-1">2.1 数组的定义 <a class="header-anchor" href="#_2-1-数组的定义" aria-label="Permalink to &quot;2.1 数组的定义&quot;"></a></h2><h3 id="_2-1-1-动态初始化" tabindex="-1">2.1.1 动态初始化 <a class="header-anchor" href="#_2-1-1-动态初始化" aria-label="Permalink to &quot;2.1.1 动态初始化&quot;"></a></h3><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">数据类型 数组名[元素个数</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">|</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">长度];</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 数据类型:表示的是数组中每一个元素的数据类型。</li><li>② 数组名:必须符合标识符规则和规范。</li><li>③ 元素个数或长度:表示的是数组中最多可以容纳多少个元素(不能是负数、也不能是 0 )。</li></ul></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;sizeof(arr) = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%lu\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(arr));</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 返回数组的大小5 * sizeof(int)</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;sizeof(ptr) = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%lu\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(ptr));</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 返回指针的大小通常是4或8字节</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div></li><li><p><strong>地址运算符的结果不同</strong> 使用地址运算符<code>&amp;</code>对数组名和指针变量会得到不同的结果,对数组名使用<code>&amp;</code>会返回数组的地址,而对指针变量使用<code>&amp;</code>会返回指针变量本身的地址。</p><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">ptr </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;Address of array: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%p\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 返回整个数组的地址</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;Address of pointer: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%p\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">ptr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 返回指针变量ptr的地址</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div></li></ol><p>综上所述,通过这些示例和解释,可以看出数组名虽然在某些场合下可以像指针一样使用,但它并不是一个真正的指针变量,而是一个常量,表示数组的首地址。</p></div></div></main><footer class="VPDocFooter" data-v-39a288b8 data-v-e257564d><!--[--><!--]--><div class="edit-info" data-v-e257564d><!----><div class="last-updated" data-v-e257564d><p class="VPLastUpdated" data-v-e257564d data-v-e98dd255>上次更新: <time datetime="2024-08-13T02:39:52.000Z" data-v-e98dd255></time></p></div></div><nav class="prev-next" aria-labelledby="doc-footer-aria-label" data-v-e257564d><span class="visually-hidden" id="doc-footer-aria-label" data-v-e257564d>Pager</span><div class="pager" data-v-e257564d><a class="VPLink link pager-link prev" href="/c/notes/01_c-basic/05_xdx/" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>上一篇</span><span class="title" data-v-e257564d>数组</span><!--]--></a></div><div class="pager" data-v-e257564d><a class="VPLink link pager-link next" href="/c/notes/01_c-basic/07_xdx/" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>下一篇</span><span class="title" data-v-e257564d>函数</span><!--]--></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><footer class="VPFooter has-sidebar" data-v-5d98c3a5 data-v-e315a0ad><div class="container" data-v-e315a0ad><p class="message" data-v-e315a0ad>Released under the MIT License.</p><p class="copyright" data-v-e315a0ad>Copyright © 2024 许大仙</p></div></footer><!--[--><!--]--></div></div>
<script>window.__VP_HASH_MAP__=JSON.parse("{\"index.md\":\"Dga0tMF5\",\"notes_01_c-basic_00_xdx_index.md\":\"BRC7slaL\",\"notes_01_c-basic_01_xdx_index.md\":\"DvCUr2L0\",\"notes_01_c-basic_02_xdx_index.md\":\"CC2Mg9VD\",\"notes_01_c-basic_03_xdx_index.md\":\"CcATnhKW\",\"notes_01_c-basic_04_xdx_index.md\":\"DABEMZSO\",\"notes_01_c-basic_05_xdx_index.md\":\"CGbN5wss\",\"notes_01_c-basic_06_xdx_index.md\":\"CIGNaKYV\",\"notes_04_linux_01_xdx_index.md\":\"C9IatKsj\",\"notes_about_index.md\":\"DLuQgC_8\",\"notes_index.md\":\"CeV-uJ5V\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"zh-CN\",\"dir\":\"ltr\",\"title\":\"许大仙\",\"titleTemplate\":\"Hi终于等到你\",\"description\":\"许大仙前端、Java、大数据、云原生\",\"base\":\"/c/\",\"head\":[],\"router\":{\"prefetchLinks\":true},\"appearance\":true,\"themeConfig\":{\"lastUpdatedText\":\"上次更新\",\"returnToTopLabel\":\"返回顶部\",\"search\":{\"provider\":\"local\"},\"logo\":\"/logo.svg\",\"nav\":[{\"text\":\"首页\",\"link\":\"https://aexiar.github.io/\"},{\"text\":\"计组6件套\",\"link\":\"https://aexiar.github.io/coa6/notes/\"},{\"text\":\"编程语言\",\"items\":[{\"text\":\"c/c++\",\"link\":\"/notes/\"},{\"text\":\"前端\",\"link\":\"https://aexiar.github.io/web-design/notes/\"},{\"text\":\"Java\",\"link\":\"https://aexiar.github.io/java/notes/\"},{\"text\":\"大数据\",\"link\":\"https://aexiar.github.io/big-data/notes/\"},{\"text\":\"云原生\",\"link\":\"https://aexiar.github.io/linux/notes/\"},{\"text\":\"Go\",\"link\":\"https://aexiar.github.io/go/notes/\"},{\"text\":\"Python\",\"link\":\"https://aexiar.github.io/python/notes/\"}]},{\"text\":\"数据库\",\"link\":\"https://aexiar.github.io/db/notes/\"},{\"text\":\"开源软件\",\"link\":\"https://aexiar.github.io/open-software/notes/\"},{\"text\":\"关于我\",\"link\":\"/notes/about/\"}],\"sidebar\":{\"/notes/\":[{\"text\":\"C 语言基础\",\"collapsed\":true,\"items\":[{\"text\":\"编程基础\",\"link\":\"/notes/01_c-basic/00_xdx/\"},{\"text\":\"C 语言入门\",\"link\":\"/notes/01_c-basic/01_xdx/\"},{\"text\":\"变量和进制\",\"link\":\"/notes/01_c-basic/02_xdx/\"},{\"text\":\"数据类型和运算符\",\"link\":\"/notes/01_c-basic/03_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/01_c-basic/04_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/01_c-basic/05_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/01_c-basic/06_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/01_c-basic/07_xdx/\"},{\"text\":\"预处理器\",\"link\":\"/notes/01_c-basic/08_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/01_c-basic/09_xdx/\"},{\"text\":\"内存管理\",\"link\":\"/notes/01_c-basic/10_xdx/\"},{\"text\":\"文件操作\",\"link\":\"/notes/01_c-basic/11_xdx/\"},{\"text\":\"调试工具和调试技巧gdb和make\",\"link\":\"/notes/02_c-basic/13_xdx/\"},{\"text\":\"常用库函数\",\"link\":\"/notes/01_c-basic/13_xdx/\"}]},{\"text\":\"C 语言高级\",\"collapsed\":true,\"items\":[{\"text\":\"变量和内存分布\",\"link\":\"/notes/02_c-advance/01_xdx/\"},{\"text\":\"指针强化\",\"link\":\"/notes/02_c-advance/02_xdx/\"},{\"text\":\"结构体和文件的高级用法\",\"link\":\"/notes/02_c-advance/03_xdx/\"},{\"text\":\"链表和回调函数\",\"link\":\"/notes/02_c-advance/04_xdx/\"},{\"text\":\"编译过程和面向接口\",\"link\":\"/notes/02_c-advance/05_xdx/\"}]},{\"text\":\"项目构建工具\",\"collapsed\":true,\"items\":[{\"text\":\"meson\",\"collapsed\":true,\"items\":[{\"text\":\"meson 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Cmake\",\"collapsed\":true,\"items\":[{\"text\":\"Cmake 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Conan \",\"link\":\"/notes/03_build/01_${commonDirectoryName}/\"},{\"text\":\"Gradle\",\"collapsed\":true,\"items\":[{\"text\":\"Gradle 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]}]},{\"text\":\"Linux\",\"collapsed\":true,\"items\":[{\"text\":\"Linux 初识和安装\",\"link\":\"/notes/04_linux/01_xdx/\"}]},{\"text\":\"C++ 基础\",\"collapsed\":true,\"items\":[{\"text\":\"C++ 入门\",\"link\":\"/notes/05_cpp/01_xdx/\"},{\"text\":\"变量、数据类型、运算符\",\"link\":\"/notes/05_cpp/02_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/05_cpp/03_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/05_cpp/04_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/05_cpp/05_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/05_cpp/06_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/05_cpp/07_xdx/\"},{\"text\":\"类和对象\",\"link\":\"/notes/05_cpp/08_xdx/\"},{\"text\":\"C++ 引用\",\"link\":\"/notes/05_cpp/09_xdx/\"},{\"text\":\"继承和派生\",\"link\":\"/notes/05_cpp/10_xdx/\"},{\"text\":\"C++ 多态和虚函数\",\"link\":\"/notes/05_cpp/11_xdx/\"},{\"text\":\"运算符重载\",\"link\":\"/notes/05_cpp/12_xdx/\"},{\"text\":\"模板\",\"link\":\"/notes/05_cpp/13_xdx/\"},{\"text\":\"C++ 异常\",\"link\":\"/notes/05_cpp/14_xdx/\"},{\"text\":\"面向对象进阶\",\"link\":\"/notes/05_cpp/15_xdx/\"},{\"text\":\"文件操作和 IO 流\",\"link\":\"/notes/05_cpp/16_xdx/\"},{\"text\":\"STL标准模板库\",\"link\":\"/notes/05_cpp/17_xdx/\"}]},{\"text\":\"C++ 高级\",\"collapsed\":true,\"items\":[]},{\"text\":\"QT 桌面开发\",\"collapsed\":true,\"items\":[]},{\"text\":\"Linux 高并发服务器开发\",\"collapsed\":true,\"items\":[]}]},\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/Aurorxa\"}],\"docFooter\":{\"prev\":\"上一篇\",\"next\":\"下一篇\"},\"darkModeSwitchLabel\":\"深浅模式\",\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2024 许大仙\"},\"outline\":{\"level\":[1,6],\"label\":\"目录\"},\"outlineTitle\":\"当前页大纲\"},\"locales\":{},\"scrollOffset\":134,\"cleanUrls\":false}");</script>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 先指定元素的个数和类型,再进行初始化</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 给数组元素赋值</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 20</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 30</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><h3 id="_2-1-2-静态初始化-1" tabindex="-1">2.1.2 静态初始化 1 <a class="header-anchor" href="#_2-1-2-静态初始化-1" aria-label="Permalink to &quot;2.1.2 静态初始化 1&quot;"></a></h3><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">数据类型 数组名[元素个数</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">|</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">长度] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {元素1,元素2,...}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 静态部分初始化:如果数组初始化的元素个数<code>小于</code>数组声明的长度,那么就会从数组开始位置依次赋值,不够的就补 0 。</li><li>② 静态全部初始化:数组初始化的元素个数<code>等于</code>数组的长度。</li></ul></div><ul><li><p>技巧:</p><ul><li>在 CLion 中可以开启<code>聚合初始化</code>功能,即:</li></ul><p><img src="/c/assets/3.hr3pCY5b.png" alt="" loading="lazy"></p><ul><li>这样,在 CLion 中,将会显示数组初始化中的元素索引,即:</li></ul><p><img src="/c/assets/4.CgvWfxq4.png" alt="" loading="lazy"></p></li><li><p>示例:静态部分初识化</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义数组和部分初始化:</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 会将给定的值从数组的开始位置一个个的赋值,没有赋值的地方,用 0 填充</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><ul><li>示例:静态全部初始化</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义数组和全部初始化:数组初始化的元素个数等于数组的长度。</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><h3 id="_2-1-3-静态初始化-2" tabindex="-1">2.1.3 静态初始化 2 <a class="header-anchor" href="#_2-1-3-静态初始化-2" aria-label="Permalink to &quot;2.1.3 静态初始化 2&quot;"></a></h3><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">数据类型 数组名</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {元素1,元素2,...}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>没有给出数组中元素的个数,将由系统根据初始化的元素,自动推断出数组中元素的个数。</p></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 指定元素的类型,不指定元素个数,同时进行初始化</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><h2 id="_2-2-访问数组元素" tabindex="-1">2.2 访问数组元素 <a class="header-anchor" href="#_2-2-访问数组元素" aria-label="Permalink to &quot;2.2 访问数组元素&quot;"></a></h2><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">数组名[索引</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">|</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">下标];</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>假设数组 <code>arr</code> 有 n 个元素,如果使用的数组的下标 <code>&lt; 0</code><code>&gt; n-1</code> ,那么将会产生数组越界访问,即超出了数组合法空间的访问;那么,数组的索引范围是 <code>[0,arr.length - 1]</code></p></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 先指定元素的个数和类型,再进行初始化</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 给数组元素赋值</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 20</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 30</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 访问数组元素</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[0] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[0] = 10</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[1] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[1] = 20</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[2] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[2] = 30</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br></div></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义数组和部分初始化:</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 会将给定的值从数组的开始位置一个个的赋值,没有赋值的地方,用 0 填充</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 访问数组元素</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[0] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[0] = 1</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[1] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[1] = 2</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[2] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[2] = 0</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[3] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[3] = 0</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[4] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[4] = 0</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 指定元素的类型,不指定元素个数,同时进行初始化</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 访问数组元素</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[0] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[0] = 1</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[1] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[1] = 2</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[2] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[2] = 3</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[3] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[3] = 4</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[4] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[4] = 5</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义数组和全部初始化:数组初始化的元素个数等于数组的长度。</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 访问数组元素</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[0] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[0] = 1</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[1] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[1] = 2</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[2] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[2] = 3</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[3] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[3] = 4</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[4] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[4] = 5</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><h2 id="_2-3-数组越界" tabindex="-1">2.3 数组越界 <a class="header-anchor" href="#_2-3-数组越界" aria-label="Permalink to &quot;2.3 数组越界&quot;"></a></h2><ul><li>数组下标必须在指定范围内使用,超出范围视为越界。</li></ul><p><img src="/c/assets/5.DSekQATc.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① C 语言是不会做数组下标越界的检查,并且编译器也不会报错;但是,编译器不报错,并不意味着程序就是正确!</li><li>② 在其它高级编程语言Java、JavaScript、Rust 等中,如果数组越界访问,编译器是会直接报错的!!!</li></ul></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义数组和全部初始化:数组初始化的元素个数等于数组的长度。</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 访问数组元素</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[0] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[0] = 1</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[1] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[1] = 2</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[2] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[2] = 3</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[3] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[3] = 4</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[4] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[4] = 5</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[-1] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 得到的是不确定的结果</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[5] = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 得到的是不确定的结果</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br></div></div><h2 id="_2-4-计算数组的长度" tabindex="-1">2.4 计算数组的长度 <a class="header-anchor" href="#_2-4-计算数组的长度" aria-label="Permalink to &quot;2.4 计算数组的长度&quot;"></a></h2><ul><li>数组长度(元素个数)是在数组定义的时候明确指定且固定的,我们不能在运行的时候直接获取数组长度;但是,我们可以通过 sizeof 运算符间接计算出数组的长度。</li><li>计算步骤,如下所示: <ul><li>① 使用 sizeof 运算符计算出整个数组的字节长度。</li><li>② 由于数组成员是同一数据类型;那么,每个元素的字节长度一定相等,那么<code>数组的长度 = 整个数组的字节长度 ÷ 单个元素的字节长度 </code></li></ul></li></ul><p><img src="/c/assets/6.DjtEKfCa.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 在很多编程语言中都内置了获取数组的长度的属性或方法Java 中的 arr.length 或 Rust 的 arr.len()。</li><li>② 但是C 语言没有内置的获取数组长度的属性或方法,只能通过 sizeof 运算符间接来计算得到。</li><li>③ 数组一旦<code>声明</code><code>定义</code>,其<code>长度</code><code>固定</code>了,<code>不能动态变化</code></li></ul></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义数组和全部初始化:数组初始化的元素个数等于数组的长度。</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 计算数组的长度</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> size_t</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(arr) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 遍历数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div><h2 id="_2-5-遍历数组" tabindex="-1">2.5 遍历数组 <a class="header-anchor" href="#_2-5-遍历数组" aria-label="Permalink to &quot;2.5 遍历数组&quot;"></a></h2><ul><li><p>遍历数组是指按顺序访问数组中的每个元素,以便读取或修改它们,编程中一般使用循环结构对数组进行遍历。</p></li><li><p>示例:声明一个存储有 12、2、31、24、15、36、67、108、29、51 的数组,并遍历数组所有元素</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义数组并初始化</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">31</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">24</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">15</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">36</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">67</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">108</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">29</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">51</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 计算数组的长度</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> size_t</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(arr) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 遍历数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div><ul><li>示例:声明长度为 10 的 int 类型数组,给数组元素依次赋值为 0 ~ 9 ,并遍历数组所有元素</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 计算数组的长度</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> size_t</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(arr) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 给数组的每个元素赋值</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 遍历数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br></div></div><h2 id="_2-6-一维数组的内存分析" tabindex="-1">2.6 一维数组的内存分析 <a class="header-anchor" href="#_2-6-一维数组的内存分析" aria-label="Permalink to &quot;2.6 一维数组的内存分析&quot;"></a></h2><h3 id="_2-6-1-数组内存图" tabindex="-1">2.6.1 数组内存图 <a class="header-anchor" href="#_2-6-1-数组内存图" aria-label="Permalink to &quot;2.6.1 数组内存图&quot;"></a></h3><ul><li>假设数组是如下的定义:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><ul><li>那么,对应的内存结构,如下所示:</li></ul><p><img src="/c/assets/7.BTWPdsCm.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 数组名 <code>arr</code> 就是记录该数组的首地址,即 <code>arr[0]</code> 的地址。</li><li>② 数组中的各个元素是连续分布的,假设 <code>arr[0]</code> 的地址是 <code>0xdea7bff880</code>,则 <code>arr[1] 的地址 = arr[0] 的地址 + int 字节数4 = 0xdea7bff880 + 4 = 0xdea7bff884</code> ,依次类推...</li></ul></div><ul><li>在 C 语言中,我们可以通过 <code>&amp;arr</code><code>&amp;arr[0]</code> 等形式获取数组或数组元素的地址,即:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 计算数组的长度</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> size_t</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(arr) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 给数组的每个元素赋值</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;数组的地址是 = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%p\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, arr);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 遍历数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;数组元素 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 的地址是 = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%p\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i], </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br></div></div><h3 id="_2-6-2-数组的注意事项" tabindex="-1">2.6.2 数组的注意事项 <a class="header-anchor" href="#_2-6-2-数组的注意事项" aria-label="Permalink to &quot;2.6.2 数组的注意事项&quot;"></a></h3><ul><li><code>C 语言规定,数组一旦声明,数组名指向的地址将不可更改</code>。因为在声明数组的时候,编译器会自动会数组分配内存地址,这个地址和数组名是绑定的,不可更改。</li></ul><div class="warning custom-block github-alert"><p class="custom-block-title">WARNING</p><p></p><p>如果之后试图更改数组名对应的地址,编译器就会报错。</p></div><ul><li>示例:错误演示</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> num</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 声明数组</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 使用大括号重新赋值是不允许的,必须在数组声明的时候赋值,否则编译将会报错</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">} ;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 报错</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><ul><li>示例:错误演示</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 使用大括号重新赋值是不允许的,必须在数组声明的时候赋值,否则编译将会报错</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">6</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 报错</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><ul><li>示例:错误演示</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> num</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> NULL</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 报错,需要和 Java 区别一下,在 C 中不可以</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><ul><li>示例:错误演示</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> a</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">} </span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> b</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> a ;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 报错,需要和 Java 区别一下,在 C 中不可以</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h2 id="_2-7-数组应用案例" tabindex="-1">2.7 数组应用案例 <a class="header-anchor" href="#_2-7-数组应用案例" aria-label="Permalink to &quot;2.7 数组应用案例&quot;"></a></h2><h3 id="_2-7-1-应用示例" tabindex="-1">2.7.1 应用示例 <a class="header-anchor" href="#_2-7-1-应用示例" aria-label="Permalink to &quot;2.7.1 应用示例&quot;"></a></h3><ul><li><p>需求:计算数组中所有元素的和以及平均数。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义数组并初始化</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">31</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">24</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">15</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">36</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">67</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">108</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">29</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">51</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 计算数组的长度</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> size_t</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(arr) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 变量保存总和</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> sum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 遍历数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> sum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i];</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> avg </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)sum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;数组的和为:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, sum);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 数组的和为375</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;数组的平均值为:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%.2lf\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, avg);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> //数组的平均值为37.50</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br></div></div><h3 id="_2-7-2-应用示例" tabindex="-1">2.7.2 应用示例 <a class="header-anchor" href="#_2-7-2-应用示例" aria-label="Permalink to &quot;2.7.2 应用示例&quot;"></a></h3><ul><li>需求:计算数组的最值(最大值和最小值)。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>思路:</p><ul><li>① 假设数组中的第一个元素是最大值或最小值,并使用变量 max 或 min 保存。</li><li>② 遍历数组中的每个元素: <ul><li>如果有元素比最大值还要大,就让变量 max 保存最大值。</li><li>如果有元素比最小值还要小,就让变量 min 保存最小值。</li></ul></li></ul></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义数组并初始化</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">31</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">24</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">15</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">36</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">67</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">108</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">29</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">51</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 计算数组的长度</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> size_t</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(arr) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义最大值</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> max </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义最小值</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> min </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 遍历数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> max) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> max </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i];</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> min) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> min </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i];</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;数组的最大值为:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, max);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 数组的最大值为108</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;数组的最小值为:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, min);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 数组的最小值为:-36</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br></div></div><h3 id="_2-7-3-应用示例" tabindex="-1">2.7.3 应用示例 <a class="header-anchor" href="#_2-7-3-应用示例" aria-label="Permalink to &quot;2.7.3 应用示例&quot;"></a></h3><ul><li><p>需求:统计数组中某个元素出现的次数,要求:使用无限循环,如果输入的数字是 0 ,就退出。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义数组并初始化</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">31</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">24</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">36</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">67</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">108</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">29</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">51</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 计算数组的长度</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> size_t</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(arr) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 遍历数组</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;当前数组中的元素是:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 无限循环</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> while</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">true</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 统计的数字</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num;</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 统计数字出现的次数</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> count </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 输入数字</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入要统计的数字:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">num);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 0 作为结束条件</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 遍历数组,并计数</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">==</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> count</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;您输入的数字 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 在数组中出现了 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"></span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num, count);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br><span class="line-number">45</span><br></div></div><h3 id="_2-7-4-应用示例" tabindex="-1">2.7.4 应用示例 <a class="header-anchor" href="#_2-7-4-应用示例" aria-label="Permalink to &quot;2.7.4 应用示例&quot;"></a></h3><ul><li><p>需求:将数组 a 中的全部元素复制到数组 b 中。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#define</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> SIZE</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义数组并初始化</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> a</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">31</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">24</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">15</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">36</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">67</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">108</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">29</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">51</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> b</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[SIZE];</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 复制数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> SIZE; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> b</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> a</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i];</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 打印数组 b 中的全部元素</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> SIZE; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">b</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br></div></div><h3 id="_2-7-5-应用示例" tabindex="-1">2.7.5 应用示例 <a class="header-anchor" href="#_2-7-5-应用示例" aria-label="Permalink to &quot;2.7.5 应用示例&quot;"></a></h3><ul><li>需求:数组对称位置的元素互换。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>思路:假设数组一共有 10 个元素,那么:</p><ul><li>a[0] 和 a[9] 互换。</li><li>a[1] 和 a[8] 互换。</li><li>...</li></ul><p>规律就是 <code>a[i] &lt;--互换--&gt; arr[arr.length -1 -i]</code></p></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 原始数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">31</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">24</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">15</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">36</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">67</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">108</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">29</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">51</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 计算数组的长度</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> size_t</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> SIZE </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(arr) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 打印原始数组中的全部元素</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;原始数组:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> SIZE; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 交换数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> SIZE </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> temp </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i];</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[SIZE </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> -</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i];</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[SIZE </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> -</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> temp;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 打印交换后的数组</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;交换后数组:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> SIZE; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br></div></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 原始数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">31</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">24</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">15</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">36</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">67</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">108</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">29</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">51</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 计算数组的长度</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> size_t</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> SIZE </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(arr) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 打印原始数组中的全部元素</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;原始数组:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> SIZE; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 交换数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> SIZE </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> -</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> SIZE </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, j</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">--</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> temp </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i];</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[j];</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[j] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> temp;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 打印交换后的数组</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;交换后数组:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> SIZE; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br></div></div><h3 id="_2-7-6-应用示例" tabindex="-1">2.7.6 应用示例 <a class="header-anchor" href="#_2-7-6-应用示例" aria-label="Permalink to &quot;2.7.6 应用示例&quot;"></a></h3><ul><li>需求:将数组中的最大值移动到数组的最末尾。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>思路:从数组的下标 <code>0</code> 开始依次遍历到 <code>length - 1</code> ,如果 <code>i</code> 下标当前的值比 <code>i+1</code> 下标的值大,则交换;否则,就不交换。</p></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 原始数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">31</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">24</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">15</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">36</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">67</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">891</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">29</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">51</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 计算数组的长度</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> size_t</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(arr) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 打印原始数组中的全部元素</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;原始数组:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 移动最大值到数组的最后一个位置</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> temp </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i];</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> temp;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 打印移动之后的数组</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;移动之后的数组:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br></div></div><h3 id="_2-7-7-应用示例" tabindex="-1">2.7.7 应用示例 <a class="header-anchor" href="#_2-7-7-应用示例" aria-label="Permalink to &quot;2.7.7 应用示例&quot;"></a></h3><ul><li>需求:实现冒泡排序,即将数组的元素从小到大排列。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>思路:一层循环,能实现最大值移动到数组的最后;那么,二层循环(控制内部循环数组的长度)就能实现将数组的元素从小到大排序。</p></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 原始数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">31</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">24</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">15</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">36</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">67</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">891</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">29</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">51</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 计算数组的长度</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> size_t</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(arr) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 打印原始数组中的全部元素</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;原始数组:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; j</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> -</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> j; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> temp </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i];</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> temp;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 打印移动之后的数组</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;移动之后的数组:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> length; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br></div></div><h1 id="第三章-多维数组-⭐" tabindex="-1">第三章:多维数组(⭐) <a class="header-anchor" href="#第三章-多维数组-⭐" aria-label="Permalink to &quot;第三章:多维数组(⭐)&quot;"></a></h1><h2 id="_3-1-概述" tabindex="-1">3.1 概述 <a class="header-anchor" href="#_3-1-概述" aria-label="Permalink to &quot;3.1 概述&quot;"></a></h2><h3 id="_3-1-1-引入" tabindex="-1">3.1.1 引入 <a class="header-anchor" href="#_3-1-1-引入" aria-label="Permalink to &quot;3.1.1 引入&quot;"></a></h3><ul><li><p>我们在数学、物理和计算机科学等学科中学习过<code>一维坐标</code><code>二维坐标</code>以及<code>三维坐标</code></p></li><li><p>其中,<code>一维坐标</code>通常用于描述在线段或直线上的点的位置,主要应用有:</p><ul><li><strong>数轴</strong>:一维坐标可以用来表示数轴上的数值位置,这在基础数学和初等代数中非常常见。</li></ul><p><img src="/c/assets/8.EoNXwZXz.png" alt="" loading="lazy"></p><ul><li><strong>时间轴</strong>:时间可以看作是一维的,它可以用一维坐标表示,例如:秒、分钟、小时等。</li></ul><p><img src="/c/assets/9.iU-LaFqX.png" alt="" loading="lazy"></p><ul><li><strong>统计数据</strong>:一维坐标常用于表示单变量的数据集,如:测量身高、体重、温度等。</li></ul><p><img src="/c/assets/10.DYoXU9E6.jpg" alt="" loading="lazy"></p></li><li><p>其中,<code>二维坐标</code>用于描述平面上的点的位置。主要应用包括:</p><ul><li><strong>几何学</strong>:在几何学中,二维坐标用于表示平面图形的顶点、边和面积等。</li></ul><p><img src="/c/assets/11.DWDH3yqc.png" alt="" loading="lazy"></p><ul><li><strong>地图和导航</strong>:地理坐标系统(经纬度)使用二维坐标来表示地球表面的任意位置。</li></ul><p><img src="/c/assets/12.BvBjpbbE.png" alt="image-20240724112326592" loading="lazy"></p><ul><li><strong>图形设计和计算机图形学</strong>:二维坐标在绘制图形、设计图案和用户界面中非常重要。</li></ul><p><img src="/c/assets/13.CmPe90qp.png" alt="" loading="lazy"></p><ul><li><strong>物理学</strong>:二维运动和场,例如:在描述物体在平面上的运动轨迹时使用二维坐标。</li></ul><p><img src="/c/assets/14.MepLJvOt.jpg" alt="" loading="lazy"></p></li><li><p>其中,三维坐标用于描述空间中点的位置。主要应用包括:</p><ul><li><strong>几何学</strong>:三维坐标在空间几何中用于表示立体图形的顶点、边、面和体积。</li></ul><p><img src="/c/assets/15.CZUo3kuI.png" alt="" loading="lazy"></p><ul><li><strong>计算机图形学</strong>:三维建模和动画需要使用三维坐标来创建和操控虚拟对象。</li></ul><p><img src="/c/assets/16.t7xuKRuB.png" alt="" loading="lazy"></p><ul><li><strong>工程和建筑设计</strong>:在设计建筑物、机械部件和其他工程项目时,使用三维坐标来精确定位和规划。</li></ul><p><img src="/c/assets/17.Bkm40EoU.png" alt="" loading="lazy"></p><ul><li><strong>物理学</strong>:三维空间中的力、运动和场,例如:描述物体在空间中的位置和运动轨迹。</li></ul><p><img src="/c/assets/18.D0Mtsawg.png" alt="" loading="lazy"></p></li><li><p>总而言之,一维、二维和三维坐标系统在不同的领域中各有其重要的应用,从基础数学到高级科学和工程技术,它们帮助我们更好地理解和描述世界的结构和行为。</p></li></ul><h3 id="_3-1-2-多维数组" tabindex="-1">3.1.2 多维数组 <a class="header-anchor" href="#_3-1-2-多维数组" aria-label="Permalink to &quot;3.1.2 多维数组&quot;"></a></h3><ul><li>在 C 语言中,多维数组就是数组嵌套,即:在数组中包含数组,数组中的每一个元素还是一个数组类型,如下所示:</li></ul><p><img src="/c/assets/19.C-mmUOKp.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 如果数组中嵌套的每一个元素是一个常量值,那么该数组就是一维数组。</li><li>② 如果数组中嵌套的每一个元素是一个一维数组,那么该数组就是二维数组。</li><li>③ 如果数组中前台的每一个元素是一个二维数组,那么该数组就是三维数组.</li><li>④ 依次类推...</li></ul></div><ul><li>一维数组和多维数组的理解: <ul><li>从内存角度看:一维数组或多维数组都是占用的一整块连续的内存空间。</li><li>从数据操作角度看: <ul><li>一维数组可以直接通过<code>下标</code>访问到数组中的某个元素0、1、...</li><li>二维数组要想访问某个元素,先要获取某个一维数组,然后在一维数组中获取对应的数据。</li></ul></li></ul></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① C 语言中的一维数组或多维数组都是占用的一整块连续的内存空间其它编程语言可不是这样的Java 等。</li><li>② 在实际开发中,最为常用的就是二维数组或三维数组了,以二维数组居多!!!</li></ul></div><h2 id="_3-2-二维数组的定义" tabindex="-1">3.2 二维数组的定义 <a class="header-anchor" href="#_3-2-二维数组的定义" aria-label="Permalink to &quot;3.2 二维数组的定义&quot;"></a></h2><h3 id="_3-2-1-动态初始化" tabindex="-1">3.2.1 动态初始化 <a class="header-anchor" href="#_3-2-1-动态初始化" aria-label="Permalink to &quot;3.2.1 动态初始化&quot;"></a></h3><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">数据类型 数组名[几个⼀维数组元素][每个⼀维数组中有几个具体的数据元素];</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 二维数组在实际开发中,最为常见的应用场景就是表格或矩阵了。</li><li>② 几个一维数组元素 = 行数。</li><li>③ 每个⼀维数组中有几个具体的数据元素 = 列数。</li></ul></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义二维数组并初始化</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {{</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}, {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">6</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">7</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">8</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}, {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">9</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">11</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 输出二维数组中的元素</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br></div></div><h3 id="_3-2-2-静态初始化-1" tabindex="-1">3.2.2 静态初始化 1 <a class="header-anchor" href="#_3-2-2-静态初始化-1" aria-label="Permalink to &quot;3.2.2 静态初始化 1&quot;"></a></h3><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">数据类型 数组名[行数][列数] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {{元素1,元素2,...},{元素3,...},...}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 行数 = 几个一维数组元素。</li><li>② 列数 = 每个⼀维数组中有几个具体的数据元素。</li></ul></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义二维数组并初始化</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {{</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}, {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">6</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">7</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">8</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}, {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">9</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">11</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 输出二维数组中的元素</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br></div></div><h3 id="_3-2-3-静态初始化-2" tabindex="-1">3.2.3 静态初始化 2 <a class="header-anchor" href="#_3-2-3-静态初始化-2" aria-label="Permalink to &quot;3.2.3 静态初始化 2&quot;"></a></h3><ul><li>语法:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">数据类型 数组名</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[列数] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {{元素1,元素2,...},{元素3,...},...}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 列数 = 每个⼀维数组中有几个具体的数据元素。</li><li>② 可以不指定行数,必须指定列数,编译器会根据元素的个数和列的个数,自动推断出行数!!!</li></ul></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义二维数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {{</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}, {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">6</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}, {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">9</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">11</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 输出二维数组中的元素</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br></div></div><h2 id="_3-3-二维数组的理解" tabindex="-1">3.3 二维数组的理解 <a class="header-anchor" href="#_3-3-二维数组的理解" aria-label="Permalink to &quot;3.3 二维数组的理解&quot;"></a></h2><ul><li>如果二维数组是这么定义的,即:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><ul><li>那么,这个二维数组 <code>arr</code> 可以看做是 <code>3</code> 个一维数组组成,它们分别是 <code>arr[0]</code><code>arr[1]</code><code>arr[2]</code>。这 <code>3</code> 个一维数组都各有 4 个元素,如:一维数组 <code>arr[0]</code> 中的元素是 <code>arr[0][0]</code><code>arr[0][1]</code><code>arr[0][2]</code><code>arr[0][3]</code>,即:</li></ul><p><img src="/c/assets/20.BvSSXPdI.png" alt="" loading="lazy"></p><h2 id="_3-4-二维数组的遍历" tabindex="-1">3.4 二维数组的遍历 <a class="header-anchor" href="#_3-4-二维数组的遍历" aria-label="Permalink to &quot;3.4 二维数组的遍历&quot;"></a></h2><ul><li>访问二维数组的元素,需要使用两个下标(索引),一个用于访问行(第一维),另一个用于访问列(第二维),我们通常称为行下标(行索引)或列下标(列索引)。</li><li>所以,遍历二维数组,需要使用双层循环结构。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>如果一个二维数组是这么定义的,即:<code>int arr[3][4]</code>,那么:</p><ul><li><code>行的长度 = sizeof(arr) / sizeof(arr[0])</code> ,因为 <code>arr</code> 是二维数组的<code></code>的内存空间;而 <code>arr[0]</code><code>arr[1]</code><code>arr[2]</code> 是二维数组中一维数组的内存空间 。</li><li><code>列的长度 = sizeof(arr[0]) / sizeof(arr[0][0])</code>,因为<code>arr[0]</code><code>arr[1]</code><code>arr[2]</code> 是二维数组中一维数组的内存空间 ,而 <code>arr[0][0]</code><code>arr[0][1]</code>、... 是一维数组中元素的内存空间。</li></ul></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义二维数组</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {{</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}, {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">6</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}, {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">9</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">11</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">12</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 获取行列数</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> row </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(arr) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> col </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 打印二维数组元素</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> row; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> col; j</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i][j]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br></div></div><h2 id="_3-5-二维数组的内存分析" tabindex="-1">3.5 二维数组的内存分析 <a class="header-anchor" href="#_3-5-二维数组的内存分析" aria-label="Permalink to &quot;3.5 二维数组的内存分析&quot;"></a></h2><ul><li><p><code>矩阵形式</code>3 行 4 列形式)表示二维数组,是<code>逻辑</code>上的概念,能形象地表示出行列关系。而在<code>内存</code>中,各元素是连续存放的,不是二维的,是<code>线性</code>的。</p></li><li><p>C 语言中,二维数组中元素排列的顺序是<code>按行存放</code>的。即:先顺序存放第一行的元素,再存放第二行的元素。例如:数组<code>a[3][4] </code>在内存中的存放,如下所示:</p></li></ul><p><img src="/c/assets/21.uaya_nVR.png" alt="" loading="lazy"></p><h2 id="_3-6-二维数组的应用案例" tabindex="-1">3.6 二维数组的应用案例 <a class="header-anchor" href="#_3-6-二维数组的应用案例" aria-label="Permalink to &quot;3.6 二维数组的应用案例&quot;"></a></h2><ul><li><p>需求:现在有三个班,每个班五名同学,用二维数组保存他们的成绩,并求出每个班级平均分、以及所有班级平均分,数据要求从控制台输入。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义二维数组,用于保存成绩</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> double</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 获取二维数组的行数和列数</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> row </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(arr) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> col </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">][</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 从控制台输入成绩</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> row; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> col; j</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入第</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">个班级的第</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">个学生的成绩:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%lf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i][j]);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 总分</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> totalSum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 遍历数组,求总分和各个班级的平均分</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> row; i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> sum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; j </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> col; j</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> totalSum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i][j];</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> sum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+=</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[i][j];</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">个班级的总分为:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%.2lf\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, sum);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">个班级的平均分为:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%.2lf\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, sum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> col);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;所有班级的总分为:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%.2lf\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, totalSum);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;所有班级的平均分为:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%.2lf\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, totalSum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (row </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> col));</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br></div></div><h1 id="第四章-字符串-⭐" tabindex="-1">第四章:字符串(⭐) <a class="header-anchor" href="#第四章-字符串-⭐" aria-label="Permalink to &quot;第四章:字符串(⭐)&quot;"></a></h1><h2 id="_4-1-概述" tabindex="-1">4.1 概述 <a class="header-anchor" href="#_4-1-概述" aria-label="Permalink to &quot;4.1 概述&quot;"></a></h2><ul><li>在实际开发中,我们除了经常处理整数、浮点数、字符等,还经常和字符串打交道,如:<code>&quot;Hello World&quot;</code><code>&quot;Hi&quot;</code> 等。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>像这类<code>&quot;Hello World&quot;</code><code>&quot;Hi&quot;</code>等格式 ,使用双引号引起来的一串字符称为字符串字面值,简称字符串。</p></div><ul><li>对于整数、浮点数和字符C 语言中都提供了对应的数据类型。但是对于字符串C 语言并没有提供对应的数据类型,而是用<code>字符数组</code>来存储这类文本类型的数据,即字符串:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">char</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> str</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">32</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><ul><li>字符串不像整数、浮点数以及字符那样有固定的大小,字符串是不定长的,如:<code>&quot;Hello World&quot;</code><code>&quot;Hi&quot;</code> 等的长度就是不一样的。在 C 语言中,规定了字符串的结尾必须是 <code>\0</code> ,这种字符串也被称为 <code>C 风格的字符串</code>,如:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;Hello World&quot;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 在 C 语言中,底层存储就是 Hello World\0</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><ul><li>其对应的图示,如下所示:</li></ul><p><img src="/c/assets/22.CA2ak30R.png" alt="" loading="lazy"></p><ul><li><code>\0</code> 在 ASCII 码表中是第 0 个字符,用 NUL 表示,称为空字符,该字符既不能显示,也不是控制字符,输出该字符不会有任何效果,它在 C 语言中仅作为字符串的结束标志。</li></ul><p><img src="/c/assets/12.NlBmD7pA.png" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>在现代化的高级编程语言中都提供了字符串对应的类型Java 中的 StringJDK 11 之前,底层也是通过 <code>char[]</code> 数组来实现的) 。</p></div><h2 id="_4-2-字符数组-字符串-的定义" tabindex="-1">4.2 字符数组(字符串)的定义 <a class="header-anchor" href="#_4-2-字符数组-字符串-的定义" aria-label="Permalink to &quot;4.2 字符数组(字符串)的定义&quot;"></a></h2><h3 id="_4-2-1-标准写法" tabindex="-1">4.2.1 标准写法 <a class="header-anchor" href="#_4-2-1-标准写法" aria-label="Permalink to &quot;4.2.1 标准写法&quot;"></a></h3><ul><li><p>手动在字符串的结尾添加 <code>\0</code>作为字符串的结束标识。</p></li><li><p>示例:</p></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 禁用 stdout 缓冲区</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> setbuf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(stdout, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">NULL</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 字符数组,不是字符串</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> c1</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;H&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;e&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;l&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;l&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;o&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39; &#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;W&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;o&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;r&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;l&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;d&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // C 风格的字符串</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> c2</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;H&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;e&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;l&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;l&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;o&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39; &#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;W&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;o&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;r&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;l&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;d&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><h3 id="_4-2-2-简化写法-推荐" tabindex="-1">4.2.2 简化写法(推荐) <a class="header-anchor" href="#_4-2-2-简化写法-推荐" aria-label="Permalink to &quot;4.2.2 简化写法(推荐)&quot;"></a></h3><ul><li>字符串写成数组的形式非常麻烦。C 语言中提供了一种简化写法,即:双引号中的字符,会自动视为字符数组。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>简化写法会自动在末尾添加 <code>\0</code> 字符,强烈推荐使用。</p></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 禁用 stdout 缓冲区</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> setbuf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(stdout, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">NULL</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> c1</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;Hello World&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 注意使用双引号,非单引号</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> c2</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;Hello World&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // //可以省略一对 {} 来初始化数组元素</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><h2 id="_4-3-字符串的输入和输出" tabindex="-1">4.3 字符串的输入和输出 <a class="header-anchor" href="#_4-3-字符串的输入和输出" aria-label="Permalink to &quot;4.3 字符串的输入和输出&quot;"></a></h2><ul><li>对于字符串的输入和输出,同样可以使用 <code>scanf</code><code>printf</code> 函数来实现,并且其格式占位符是 <code>%s</code></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>之前提到,对于 scanf 函数而言,<code>%s</code> 默认是匹配到空格或 Enter 键,如果我们输入的字符串是 <code>Hello World</code>,就只能得到 <code>Hello</code> ;如果要实现匹配到换行,则可以在输入的时候,将格式占位符 <code>%s</code>替换为 <code>%[^\n]</code></p></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 禁用 stdout 缓冲区</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> setbuf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(stdout, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">NULL</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> c1</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;Hello World&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 注意使用双引号,非单引号</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> c2</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;Hello World&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // //可以省略一对 {} 来初始化数组元素</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;c1 = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%s\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, c1);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // c1 = Hello World</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;c2 = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%s\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, c2);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // c2 = Hello World</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><ul><li>示例:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 禁用 stdout 缓冲区</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> setbuf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(stdout, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">NULL</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> str</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">32</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;请输入字符串:&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#B31D28;--shiki-dark:#FDAEB7;--shiki-light-font-style:italic;--shiki-dark-font-style:italic;">%</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">[^</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">]&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, str);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;字符串是:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%s\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, str);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><h1 id="第五章-内存中的变量和数组-⭐" tabindex="-1">第五章:内存中的变量和数组(⭐) <a class="header-anchor" href="#第五章-内存中的变量和数组-⭐" aria-label="Permalink to &quot;第五章:内存中的变量和数组(⭐)&quot;"></a></h1><h2 id="_5-1-内存和内存地址" tabindex="-1">5.1 内存和内存地址 <a class="header-anchor" href="#_5-1-内存和内存地址" aria-label="Permalink to &quot;5.1 内存和内存地址&quot;"></a></h2><h3 id="_5-1-1-内存" tabindex="-1">5.1.1 内存 <a class="header-anchor" href="#_5-1-1-内存" aria-label="Permalink to &quot;5.1.1 内存&quot;"></a></h3><ul><li><p><code>内存</code>是一种<code>计算机硬件</code>,是<code>软件</code><code>运行过程</code>中,用来<code>临时存储数据</code>的。在生活中,最为常见的<code>内存</code>就是<code>随机存取存储器RAM内存条</code>),其特点如下所示:</p><ul><li>① 生活中最常见的内存类型,用于存储当前运行的程序和数据。</li><li>② 内存是易失性存储器,这意味着断电后数据会丢失。</li><li>③ 它具有高速读写特性,适用于需要快速访问的操作。</li></ul></li><li><p>内存条的外观,如下所示:</p></li></ul><p><img src="/c/assets/24.QdyrLkbx.jpeg" alt="" loading="lazy"></p><ul><li>像我们平常使用<code>记事本</code>软件一样,当我们输入一些文字的时候,其实是将数据<code>临时</code>保存在内存中的,如下所示:</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 目前,很多软件都很智能,如果用户没有将数据到保存文件中,将显示红色,以警告用户还没有保存数据,提醒用户需要尽快保存数据!!!</li><li>② 但是也有很多软件提供了自动保存数据的功能其原理就是定时1s、3s、5s将内存中的数据刷新到文件中以防止数据丢失</li><li>③ 将数据从内存存储到文件中,专业的说法是落盘(落在磁盘上)。</li></ul></div><p><img src="/c/assets/25.wg7a3XFP.gif" alt="" loading="lazy"></p><ul><li>此时,如果我们在没有保存的过程下,将<code>记事本</code>软件关闭,那么刚才输入的文字将丢失;下次,再打开同样的文件(将数据从磁盘加载进内存,再交给 CPU之前输入的文字将不复存在如下所示</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 目前,很多软件都很智能,如果你没有保存,将提醒你是否保存或丢失刚才输入的文字。</li><li>② 但是也有很多软件提供了自动保存数据的功能其原理就是定时1s、3s、5s将内存中的数据刷新到文件中以防止数据丢失</li><li>③ 将数据从内存存储到文件中,专业的说法是落盘(落在磁盘上)。</li></ul></div><p><img src="/c/assets/26.M8jrrq2u.gif" alt="" loading="lazy"></p><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p>内存就是软件在运行过程中,用来临时存储数据的,最为重要的两个步骤就是:</p><ul><li>① 将数据<code>保存</code>到内存中。</li><li>② 从内存中的<code>对应位置</code>将数据<code>取出来</code></li></ul></div><h3 id="_5-1-2-内存地址" tabindex="-1">5.1.2 内存地址 <a class="header-anchor" href="#_5-1-2-内存地址" aria-label="Permalink to &quot;5.1.2 内存地址&quot;"></a></h3><ul><li>在这个计算机的内存条,动不动就 32GB、64GB 、128GB 或更高的年代,如下所示:</li></ul><p><img src="/c/assets/27.BdWdvezm.png" alt="" loading="lazy"></p><ul><li>如果有一个 int 4 个字节)类型的数据 <code>2</code> ,如何将这个数据保存到内存中?(对应上述的步骤 ①)</li></ul><p><img src="/c/assets/28.C_QI84u9.svg" alt="" loading="lazy"></p><ul><li>就算数据 <code>2</code> 已经保存到内存中,那么内存中那么多的数据,我们又该如何取出呢?(对应上述的步骤 ②)</li></ul><p><img src="/c/assets/29.BB6sjxx5.svg" alt="" loading="lazy"></p><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p>答案就是<code>内存地址</code></p></div><ul><li>操作系统为了更快的去管理内存中的数据,会将<code>内存条</code>按照<code>字节</code>划分为一个个的<code>单元格</code>,如下所示:</li></ul><p><img src="/c/assets/30.CHyA9Yy8.svg" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>计算机中存储单位的换算,如下所示:</p><ul><li>1 B = 8 bit。</li><li>1 KB = 1024 B。</li><li>1 MB = 1024 KB。</li><li>1 GB = 1024 MB。</li><li>1 TB = 1024 GB 。</li><li>……</li></ul></div><ul><li>为了方便管理,每个独立的小单元格,都有自己唯一的编号(内存地址),如下所示:</li></ul><p><img src="/c/assets/4.DqDR6Thp.svg" alt="" loading="lazy"></p><ul><li><p>之所以,加了<code>内存地址</code>,就能<code>加快</code>数据的存取速度,可以类比生活中的<code>字典</code></p><ul><li>如果没有使用<code>拼音查找法</code><code>部首查找法</code>,我们需要一页一页,一行一行的,在整个字典中去搜索我们想要了解的汉字,效率非常低(如果要搜索的汉字在最后一页,可能需要将整个字典从头到尾翻一遍,这辈子真有可能翻得完?)。</li></ul><p><img src="/c/assets/32.3t5rXZRH.gif" alt="" loading="lazy"></p><ul><li>如果使用<code>拼音查找法</code><code>部首查找法</code>,我们可以很快的定位到所要了解汉字所在的页数,加快了搜索的效率。</li></ul><p><img src="/c/assets/33.BRUArxJK.jpg" alt="" loading="lazy"></p><p><img src="/c/assets/34.DIXK93xX.jpg" alt="" loading="lazy"></p></li><li><p>同样的道理,如果<code>没有</code>内存地址,我们只能一个个的去寻找想要的数据,效率非常低下,如下所示:</p></li></ul><p><img src="/c/assets/35.Bvu6CpUv.gif" alt="" loading="lazy"></p><ul><li>如果<code>使用</code>内存地址,我们就可以直接定位到指定的数据,效率非常高,如下所示:</li></ul><p><img src="/c/assets/36.DHPPX3_T.gif" alt="" loading="lazy"></p><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li>① 内存地址是计算机中用于标识内存中某个特定位置的数值。</li><li>② 每个内存单元都有一个唯一的地址,这些地址可以用于访问和操作存储在内存中的数据。</li></ul></div><ul><li>实际中的内存地址,并不是像上面的 <code>001</code><code>002</code> 、... 之类的数字,而是有自己的规则,即:内存地址规则。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 32 位的操作系统中,内存地址以 32 位的二进制表示。</li><li>② 64 位的操作系统中,内存地址以 64 位的二进制表示。</li></ul></div><ul><li>在 32 位的操作系统中,内存地址的范围是:<code>0000 0000 0000 0000 0000 0000 0000 0000</code> ~ <code>1111 1111 1111 1111 1111 1111 1111 1111</code> 2 ^ 32 次方)。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>在 32 位的操作系统中,一共有 4,294,967,296 个内存地址,其最大支持的内存大小是 4,294,967,296 字节,即 4 GB 。</p></div><ul><li>在 64 位的操作系统中,内存地址的范围是:<code>0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000</code> ~ <code>1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111</code> 2 ^ 64 次方)。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 在 64 位的操作系统中,一共有 18,446,744,073,709,551,616 个内存地址,其最大支持的内存大小是 18,446,744,073,709,551,616 字节,即 17,179 TB 。</li><li>② 虽然,从理论上 64 位的操作系统支持的内存最大容量是 17,179 TB但是实际操作系统会有所限制win11 的 64 位支持的最大内存是 128 GB ~ 6 TBLinux 64 位支持的最大内存通常是 256 TB。</li></ul></div><ul><li>在实际开发中64 位操作系统的内存地址表现形式,如:<code>0000 0000 0000 0000 0001 0000 1111 1010 0000 0000 0010 0000 0000 0010 0000 1000</code>,实在是太长了,我们通常转换为十六进制,以方便阅读,如:<code>0x000010FA00200208</code></li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li>① 内存地址是内存中每个单元的编号。</li><li>② 内存地址的作用是操作系统用来快速管理内存空间的。</li><li>③ 在 32 位操作系统上,内存地址以 32 位的二进制数字表示,最大支持的的内存是 4 GB所以 32 位操作系统已经被淘汰。</li><li>④ 在 64 位操作系统上,内存地址以 64 位的二进制数字表示,由于表示形式太长,我们通常会转为十六进制,以方便阅读。</li></ul></div><h2 id="_5-2-内存中的变量" tabindex="-1">5.2 内存中的变量 <a class="header-anchor" href="#_5-2-内存中的变量" aria-label="Permalink to &quot;5.2 内存中的变量&quot;"></a></h2><ul><li>在 C 语言中数据类型的种类很多short、int、long、float、double、char 等。以 int 类型为例,在 32 位或 64 位操作系统中的int 类型的变量都是占 4 个字节,当我们在代码中这么定义变量,如:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(){</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义一个变量并初始化</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> a </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><ul><li>那么,编译器就会这么处理,如下所示:</li></ul><p><img src="/c/assets/37.EU7nYUIS.svg" alt="" loading="lazy"></p><ul><li>在代码中,我们可以使用 <code>&amp;变量名</code> 来获取一个变量的内存首地址,如下所示:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义一个变量并初始化</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> a </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;变量 a 的首地址是: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%p\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">a);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 变量 a 的首地址是: 0000002bf1dffd0c</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;变量 a 的中保存的值是: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, a);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 变量 a 的中保存的值是: 10</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li><code>变量</code>是对程序中<code>数据</code>在内存中存储空间的抽象,如果不涉及到指针变量,那我们在编码的时候,就只需要将变量等价于内存中存储空间里面存储的数据,而不需要再去考虑编译器底层是如何转换,提高了开发效率(机器语言和汇编可不是这样的,需要关注每个细节)。</li><li>② 数据类型只在<code>定义</code>变量的时候<code>指定</code>,而且必须指定;<code>使用</code>变量的时候<code>无需</code>再声明,因为此时的数据类型已经确定了。</li></ul></div><h2 id="_5-3-内存中的数组" tabindex="-1">5.3 内存中的数组 <a class="header-anchor" href="#_5-3-内存中的数组" aria-label="Permalink to &quot;5.3 内存中的数组&quot;"></a></h2><ul><li>如果我们在代码中这么定义数组,如下所示:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(){</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义一个数组并初始化</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><ul><li>那么,编译器就会这么处理,如下所示:</li></ul><p><img src="/c/assets/38.BMoE_Ep0.svg" alt="" loading="lazy"></p><ul><li>在代码中,我们可以直接打印数组名的内存地址,如下所示:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">[]</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr 的首地址是: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%p</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, arr);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr 的首地址是: 0000003a6f7ffcd4</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr 的首地址是: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%p</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">arr);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // &amp;arr 的地址是: 0000003a6f7ffcd4</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[0] 的地址是: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%p</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[0] 的地址是: 0000003a6f7ffcd4</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[1] 的地址是: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%p</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[1] 的地址是: 0000003a6f7ffcd8</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;arr[2] 的地址是: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%p</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // arr[2] 的地址是: 0000003a6f7ffcdc</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><div class="warning custom-block github-alert"><p class="custom-block-title">WARNING</p><p></p><p>在上述示例中,<code>arr</code><code>&amp;arr</code> 的值是一样的,但是对应的含义是不同的。</p><ul><li><code>arr</code> 是数组名,在大多数情况下会转换为数组第一个元素的地址,即:<code>arr</code> 等价于 <code>&amp;arr[0]</code>,其数据类型是 <code>int *</code></li><li><code>&amp;arr</code>是数组名的地址,即整个数组的地址,它指向数组本身,并不是数组第一个元素的地址,<code>&amp;arr</code> 的数据类型是 <code>int(*)[3]</code></li></ul></div></div></div></main><footer class="VPDocFooter" data-v-39a288b8 data-v-e257564d><!--[--><!--]--><div class="edit-info" data-v-e257564d><!----><div class="last-updated" data-v-e257564d><p class="VPLastUpdated" data-v-e257564d data-v-e98dd255>上次更新: <time datetime="2024-08-27T03:11:14.000Z" data-v-e98dd255></time></p></div></div><nav class="prev-next" aria-labelledby="doc-footer-aria-label" data-v-e257564d><span class="visually-hidden" id="doc-footer-aria-label" data-v-e257564d>Pager</span><div class="pager" data-v-e257564d><a class="VPLink link pager-link prev" href="/c/notes/01_c-basic/05_xdx/" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>上一篇</span><span class="title" data-v-e257564d>流程控制</span><!--]--></a></div><div class="pager" data-v-e257564d><a class="VPLink link pager-link next" href="/c/notes/01_c-basic/07_xdx/" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>下一篇</span><span class="title" data-v-e257564d>指针</span><!--]--></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><footer class="VPFooter has-sidebar" data-v-5d98c3a5 data-v-e315a0ad><div class="container" data-v-e315a0ad><p class="message" data-v-e315a0ad>Released under the MIT License.</p><p class="copyright" data-v-e315a0ad>Copyright © 2024 许大仙</p></div></footer><!--[--><!--]--></div></div>
<script>window.__VP_HASH_MAP__=JSON.parse("{\"index.md\":\"Dga0tMF5\",\"notes_01_c-basic_00_xdx_index.md\":\"BRC7slaL\",\"notes_01_c-basic_01_xdx_index.md\":\"Fg4OXydV\",\"notes_01_c-basic_02_xdx_index.md\":\"CC2Mg9VD\",\"notes_01_c-basic_03_xdx_index.md\":\"Cw3Z19MO\",\"notes_01_c-basic_04_xdx_index.md\":\"ySxH8sG-\",\"notes_01_c-basic_05_xdx_index.md\":\"DUbOwEts\",\"notes_01_c-basic_06_xdx_index.md\":\"CV_r2WNu\",\"notes_01_c-basic_07_xdx_index.md\":\"CE9q5cmu\",\"notes_04_linux_01_xdx_index.md\":\"C9IatKsj\",\"notes_about_index.md\":\"DLuQgC_8\",\"notes_index.md\":\"CeV-uJ5V\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"zh-CN\",\"dir\":\"ltr\",\"title\":\"许大仙\",\"titleTemplate\":\"Hi终于等到你\",\"description\":\"许大仙前端、Java、大数据、云原生\",\"base\":\"/c/\",\"head\":[],\"router\":{\"prefetchLinks\":true},\"appearance\":true,\"themeConfig\":{\"lastUpdatedText\":\"上次更新\",\"returnToTopLabel\":\"返回顶部\",\"search\":{\"provider\":\"local\"},\"logo\":\"/logo.svg\",\"nav\":[{\"text\":\"首页\",\"link\":\"https://aexiar.github.io/\"},{\"text\":\"计组6件套\",\"link\":\"https://aexiar.github.io/coa6/notes/\"},{\"text\":\"编程语言\",\"items\":[{\"text\":\"c/c++\",\"link\":\"/notes/\"},{\"text\":\"前端\",\"link\":\"https://aexiar.github.io/web-design/notes/\"},{\"text\":\"Java\",\"link\":\"https://aexiar.github.io/java/notes/\"},{\"text\":\"大数据\",\"link\":\"https://aexiar.github.io/big-data/notes/\"},{\"text\":\"云原生\",\"link\":\"https://aexiar.github.io/linux/notes/\"},{\"text\":\"Go\",\"link\":\"https://aexiar.github.io/go/notes/\"},{\"text\":\"Python\",\"link\":\"https://aexiar.github.io/python/notes/\"}]},{\"text\":\"数据库\",\"link\":\"https://aexiar.github.io/db/notes/\"},{\"text\":\"开源软件\",\"link\":\"https://aexiar.github.io/open-software/notes/\"},{\"text\":\"关于我\",\"link\":\"/notes/about/\"}],\"sidebar\":{\"/notes/\":[{\"text\":\"C 语言基础\",\"collapsed\":true,\"items\":[{\"text\":\"编程基础\",\"link\":\"/notes/01_c-basic/00_xdx/\"},{\"text\":\"C 语言入门\",\"link\":\"/notes/01_c-basic/01_xdx/\"},{\"text\":\"变量和进制\",\"link\":\"/notes/01_c-basic/02_xdx/\"},{\"text\":\"数据类型和运算符\",\"link\":\"/notes/01_c-basic/03_xdx/\"},{\"text\":\"大话小数\",\"link\":\"/notes/01_c-basic/04_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/01_c-basic/05_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/01_c-basic/06_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/01_c-basic/07_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/01_c-basic/08_xdx/\"},{\"text\":\"预处理器\",\"link\":\"/notes/01_c-basic/09_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/01_c-basic/10_xdx/\"},{\"text\":\"内存管理\",\"link\":\"/notes/01_c-basic/11_xdx/\"},{\"text\":\"文件操作\",\"link\":\"/notes/01_c-basic/12_xdx/\"},{\"text\":\"调试工具和调试技巧gdb和make\",\"link\":\"/notes/02_c-basic/13_xdx/\"},{\"text\":\"常用库函数\",\"link\":\"/notes/01_c-basic/14_xdx/\"}]},{\"text\":\"C 语言高级\",\"collapsed\":true,\"items\":[{\"text\":\"变量和内存分布\",\"link\":\"/notes/02_c-advance/01_xdx/\"},{\"text\":\"指针强化\",\"link\":\"/notes/02_c-advance/02_xdx/\"},{\"text\":\"结构体和文件的高级用法\",\"link\":\"/notes/02_c-advance/03_xdx/\"},{\"text\":\"链表和回调函数\",\"link\":\"/notes/02_c-advance/04_xdx/\"},{\"text\":\"编译过程和面向接口\",\"link\":\"/notes/02_c-advance/05_xdx/\"}]},{\"text\":\"项目构建工具\",\"collapsed\":true,\"items\":[{\"text\":\"meson\",\"collapsed\":true,\"items\":[{\"text\":\"meson 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Cmake\",\"collapsed\":true,\"items\":[{\"text\":\"Cmake 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Conan \",\"link\":\"/notes/03_build/01_${commonDirectoryName}/\"},{\"text\":\"Gradle\",\"collapsed\":true,\"items\":[{\"text\":\"Gradle 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]}]},{\"text\":\"Linux\",\"collapsed\":true,\"items\":[{\"text\":\"Linux 初识和安装\",\"link\":\"/notes/04_linux/01_xdx/\"}]},{\"text\":\"C++ 基础\",\"collapsed\":true,\"items\":[{\"text\":\"C++ 入门\",\"link\":\"/notes/05_cpp/01_xdx/\"},{\"text\":\"变量、数据类型、运算符\",\"link\":\"/notes/05_cpp/02_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/05_cpp/03_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/05_cpp/04_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/05_cpp/05_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/05_cpp/06_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/05_cpp/07_xdx/\"},{\"text\":\"类和对象\",\"link\":\"/notes/05_cpp/08_xdx/\"},{\"text\":\"C++ 引用\",\"link\":\"/notes/05_cpp/09_xdx/\"},{\"text\":\"继承和派生\",\"link\":\"/notes/05_cpp/10_xdx/\"},{\"text\":\"C++ 多态和虚函数\",\"link\":\"/notes/05_cpp/11_xdx/\"},{\"text\":\"运算符重载\",\"link\":\"/notes/05_cpp/12_xdx/\"},{\"text\":\"模板\",\"link\":\"/notes/05_cpp/13_xdx/\"},{\"text\":\"C++ 异常\",\"link\":\"/notes/05_cpp/14_xdx/\"},{\"text\":\"面向对象进阶\",\"link\":\"/notes/05_cpp/15_xdx/\"},{\"text\":\"文件操作和 IO 流\",\"link\":\"/notes/05_cpp/16_xdx/\"},{\"text\":\"STL标准模板库\",\"link\":\"/notes/05_cpp/17_xdx/\"}]},{\"text\":\"C++ 高级\",\"collapsed\":true,\"items\":[]},{\"text\":\"QT 桌面开发\",\"collapsed\":true,\"items\":[]},{\"text\":\"Linux 高并发服务器开发\",\"collapsed\":true,\"items\":[]}]},\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/Aurorxa\"}],\"docFooter\":{\"prev\":\"上一篇\",\"next\":\"下一篇\"},\"darkModeSwitchLabel\":\"深浅模式\",\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2024 许大仙\"},\"outline\":{\"level\":[1,6],\"label\":\"目录\"},\"outlineTitle\":\"当前页大纲\"},\"locales\":{},\"scrollOffset\":134,\"cleanUrls\":false}");</script>
</body>
</html>

View File

@ -0,0 +1,109 @@
<!DOCTYPE html>
<html lang="zh-CN" dir="ltr">
<head>
<meta charset="utf-8">
<title>第一章:颇具争议的指针 | Hi终于等到你</title>
<meta name="description" content="许大仙前端、Java、大数据、云原生">
<meta name="generator" content="VitePress v1.3.3">
<link rel="preload stylesheet" href="/c/assets/style.zDJ0OJGU.css" as="style">
<script type="module" src="/c/assets/app.1a4d5P-6.js"></script>
<link rel="preload" href="/c/assets/inter-roman-latin.Di8DUHzh.woff2" as="font" type="font/woff2" crossorigin="">
<link rel="modulepreload" href="/c/assets/chunks/theme.Ddh-lpYV.js">
<link rel="modulepreload" href="/c/assets/chunks/framework.hMCIpNYY.js">
<link rel="modulepreload" href="/c/assets/notes_01_c-basic_07_xdx_index.md.CE9q5cmu.lean.js">
<link rel="shortcut icon" href="/c//logo.svg">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="">
<script id="register-sw">"serviceWorker"in navigator&&navigator.serviceWorker.register("/sw.js");</script>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no,shrink-to-fit=no">
<meta name="keywords" content="许大仙,许大仙的博客">
<script id="check-dark-mode">(()=>{const e=localStorage.getItem("vitepress-theme-appearance")||"auto",a=window.matchMedia("(prefers-color-scheme: dark)").matches;(!e||e==="auto"?a:e==="dark")&&document.documentElement.classList.add("dark")})();</script>
<script id="check-mac-os">document.documentElement.classList.toggle("mac",/Mac|iPhone|iPod|iPad/i.test(navigator.platform));</script>
</head>
<body>
<div id="app"><div class="Layout" data-v-5d98c3a5><!--[--><!--]--><!--[--><span tabindex="-1" data-v-0f60ec36></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-0f60ec36> Skip to content </a><!--]--><!----><header class="VPNav" data-v-5d98c3a5 data-v-ae24b3ad><div class="VPNavBar has-sidebar top" data-v-ae24b3ad data-v-6aa21345><div class="wrapper" data-v-6aa21345><div class="container" data-v-6aa21345><div class="title" data-v-6aa21345><div class="VPNavBarTitle has-sidebar" data-v-6aa21345 data-v-ab179fa1><a class="title" href="/c/" data-v-ab179fa1><!--[--><!--]--><!--[--><img class="VPImage logo" src="/c/logo.svg" alt data-v-8426fc1a><!--]--><span data-v-ab179fa1>许大仙</span><!--[--><!--]--></a></div></div><div class="content" data-v-6aa21345><div class="content-body" data-v-6aa21345><!--[--><!--]--><div class="VPNavBarSearch search" data-v-6aa21345><!--[--><!----><div id="local-search"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><span class="vp-icon DocSearch-Search-Icon"></span><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key">K</kbd></span></button></div><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-6aa21345 data-v-dc692963><span id="main-nav-aria-label" class="visually-hidden" data-v-dc692963> Main Navigation </span><!--[--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>首页</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/coa6/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>计组6件套</span><!--]--></a><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-dc692963 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-b6c34ac9><span class="text" data-v-b6c34ac9><!----><span data-v-b6c34ac9>编程语言</span><span class="vpi-chevron-down text-icon" data-v-b6c34ac9></span></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><div class="items" data-v-b98bc113><!--[--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link" href="/c/notes/" data-v-43f1e123><!--[-->c/c++<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/web-design/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->前端<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/java/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Java<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/big-data/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->大数据<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/linux/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->云原生<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/go/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Go<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/python/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Python<!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/db/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>数据库</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/open-software/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>开源软件</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/c/notes/about/" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>关于我</span><!--]--></a><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-6aa21345 data-v-6c893767><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-6c893767 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-6aa21345 data-v-0394ad82 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-6aa21345 data-v-bb2aa2f0 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-b6c34ac9><span class="vpi-more-horizontal icon" data-v-b6c34ac9></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><!----><!--[--><!--[--><!----><div class="group" data-v-bb2aa2f0><div class="item appearance" data-v-bb2aa2f0><p class="label" data-v-bb2aa2f0>深浅模式</p><div class="appearance-action" data-v-bb2aa2f0><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-bb2aa2f0 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div></div></div><div class="group" data-v-bb2aa2f0><div class="item social-links" data-v-bb2aa2f0><div class="VPSocialLinks social-links-list" data-v-bb2aa2f0 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div></div></div><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-6aa21345 data-v-e5dd9c1c><span class="container" data-v-e5dd9c1c><span class="top" data-v-e5dd9c1c></span><span class="middle" data-v-e5dd9c1c></span><span class="bottom" data-v-e5dd9c1c></span></span></button></div></div></div></div><div class="divider" data-v-6aa21345><div class="divider-line" data-v-6aa21345></div></div></div><!----></header><div class="VPLocalNav has-sidebar empty" data-v-5d98c3a5 data-v-a6f0e41e><div class="container" data-v-a6f0e41e><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-a6f0e41e><span class="vpi-align-left menu-icon" data-v-a6f0e41e></span><span class="menu-text" data-v-a6f0e41e>Menu</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-a6f0e41e data-v-17a5e62e><button data-v-17a5e62e>返回顶部</button><!----></div></div></div><aside class="VPSidebar" data-v-5d98c3a5 data-v-319d5ca6><div class="curtain" data-v-319d5ca6></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-319d5ca6><span class="visually-hidden" id="sidebar-aria-label" data-v-319d5ca6> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible has-active" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/00_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编程基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C 语言入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和进制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数据类型和运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>大话小数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>预处理器</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>内存管理</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/12_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-basic/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>调试工具和调试技巧gdb和make</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/14_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>常用库函数</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言高级</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和内存分布</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针强化</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>结构体和文件的高级用法</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>链表和回调函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编译过程和面向接口</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>项目构建工具</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>meson</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>meson 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Cmake</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Cmake 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_${commonDirectoryName}/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Conan </p><!--]--></a><!----></div><!----></div><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Gradle</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Gradle 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>Linux</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/04_linux/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Linux 初识和安装</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C++ 基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量、数据类型、运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>类和对象</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 引用</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>继承和派生</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 多态和虚函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/12_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>运算符重载</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>模板</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/14_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 异常</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/15_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>面向对象进阶</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/16_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作和 IO 流</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/17_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>STL标准模板库</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>C++ 高级</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>QT 桌面开发</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>Linux 高并发服务器开发</p><!----></div><!----></div></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-5d98c3a5 data-v-1428d186><div class="VPDoc has-sidebar has-aside" data-v-1428d186 data-v-39a288b8><!--[--><!--]--><div class="container" data-v-39a288b8><div class="aside" data-v-39a288b8><div class="aside-curtain" data-v-39a288b8></div><div class="aside-container" data-v-39a288b8><div class="aside-content" data-v-39a288b8><div class="VPDocAside" data-v-39a288b8 data-v-3f215769><!--[--><!--]--><!--[--><!--]--><nav aria-labelledby="doc-outline-aria-label" class="VPDocAsideOutline" data-v-3f215769 data-v-a5bbad30><div class="content" data-v-a5bbad30><div class="outline-marker" data-v-a5bbad30></div><div aria-level="2" class="outline-title" id="doc-outline-aria-label" role="heading" data-v-a5bbad30>目录</div><ul class="VPDocOutlineItem root" data-v-a5bbad30 data-v-b933a997><!--[--><!--]--></ul></div></nav><!--[--><!--]--><div class="spacer" data-v-3f215769></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-39a288b8><div class="content-container" data-v-39a288b8><!--[--><!--]--><main class="main" data-v-39a288b8><div style="position:relative;" class="vp-doc _c_notes_01_c-basic_07_xdx_" data-v-39a288b8><div><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li><code>指针</code>是 C 语言中<code>最重要</code>的概念之一,也是<code>最难以理解</code>的概念之一。</li><li><code>指针</code>是 C 语言的<code>精髓</code>,要想掌握 C 语言就需要深入地了解指针。</li></ul></div><h1 id="第一章-颇具争议的指针" tabindex="-1">第一章:颇具争议的指针 <a class="header-anchor" href="#第一章-颇具争议的指针" aria-label="Permalink to &quot;第一章:颇具争议的指针&quot;"></a></h1><h2 id="_1-1-概述" tabindex="-1">1.1 概述 <a class="header-anchor" href="#_1-1-概述" aria-label="Permalink to &quot;1.1 概述&quot;"></a></h2><ul><li>目前而言,操作系统几乎都是通过 C 语言来编写和维护的;而 C 语言提供了指针的用法,其能直接操作内存地址,是个非常<code>强大</code><code>灵活</code>的工具;但是,需要开发者<code>小心谨慎的使用</code>,以确保程序的稳定性和安全性。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>之所以指针在 C 语言中颇具争议,是因为一方面其功能强大,直接操作内存地址;另一方面,又很危险,不正确的使用指针的方式,非常容易导致程序崩溃。</p></div><ul><li><p>如果没有能很好的使用指针,就会带来一系列的问题,如:</p><ul><li><code>空指针引用</code>Null Pointer Dereference当一个指针没有正确初始化或者被赋予了空NULL值时如果程序尝试访问该指针所指向的内存会导致运行时错误甚至导致程序崩溃。</li><li><code>野指针</code>Dangling Pointers指针指向的内存地址曾经分配给某个变量或对象但后来该变量或对象被释放或者移动导致指针仍指向已经无效的内存位置。对野指针进行操作可能会导致未定义的行为或程序崩溃。</li><li><code>指针算术错误</code>:在进行指针运算时,如果没有正确管理指针的偏移量或者超出了数组的边界,可能会导致指针指向错误的内存位置,从而影响程序的正确性和安全性。</li><li><code>内存泄漏</code>:如果动态分配的内存通过指针分配,但在不再需要时没有正确释放,会导致内存泄漏,长时间运行的程序可能会耗尽系统资源。</li></ul></li><li><p>为了减少指针带来的风险,开发人员可以采取以下的措施:</p><ul><li><code>良好的编程实践</code>:确保指针的初始化和使用是安全的,避免空指针引用和野指针问题。</li><li><code>边界检查</code>:在进行指针运算时,始终确保不会超出数组或内存分配的边界。</li><li><code>使用指针和引用的适当性</code>:在可能的情况下,可以考虑使用更安全的语言特性,如:引用(在 C++ 等编程语言中)或者更高级别的数据结构来代替裸指针,从而减少指针使用时的潜在风险。</li></ul></li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li>① 既然指针很危险那么通过一系列的手段将指针包装或屏蔽以达到程序安全的目的这是现代化的高级编程语言解决的思路Java、Go、Rust 等)。</li><li>② 之所以指针还需要学习是因为在嵌入式等领域其机器的资源CPU、内存等非常有限而现代化的高级编程语言虽然安全但是需要的系统资源也庞大。</li><li>③ 我们知道编译型的程序不管编译过程如何复杂至少需要两步编译和运行。通常我们也将这两步称为编译期和运行期。C 语言中的指针之所以危险就在于程序要在运行的时候才会发现问题(后知后觉);而现代化的高级编程语言中的编译器在程序编译的时候就会发现问题(提前发现问题)。</li><li>④ C 语言的编译器之所以这么设计的原因,就在于当时的内存和 CPU 是非常有限PDP-7 早期小型计算机CPU18 bit 的电子管逻辑内存4kb 和昂贵72,000 $),如果加入安全限制的功能,会远远超过整个系统的资源。</li></ul></div><h2 id="_1-2-现代化高级编程语言是如何解决指针危险的" tabindex="-1">1.2 现代化高级编程语言是如何解决指针危险的? <a class="header-anchor" href="#_1-2-现代化高级编程语言是如何解决指针危险的" aria-label="Permalink to &quot;1.2 现代化高级编程语言是如何解决指针危险的?&quot;"></a></h2><ul><li><p><code>C++</code>采用了如下的策略和机制,来解决指针危险操作的:</p><ul><li><code>智能指针</code> C++ 引入了智能指针(如<code>std::shared_ptr</code><code>std::unique_ptr</code>),这些指针提供了自动资源管理和所有权的语义。<code>std::unique_ptr</code>确保只有一个指针可以访问给定的资源,从而避免了传统指针的悬空引用和内存泄漏问题。<code>std::shared_ptr</code>允许多个指针共享一个资源,并在所有引用释放后自动释放。</li><li><code>引用</code> C++ 中的引用(如:<code>&amp;</code>符号)提供了更安全的间接访问方法,与指针相比,引用不能重新绑定到不同的对象,从而减少了意外的指针错误。</li></ul></li><li><p><code>Go</code>采用了如下的策略和机制,来解决指针危险操作的:</p><ul><li><code>内存管理和垃圾回收</code> Go 语言通过自动垃圾回收器管理内存减少了手动内存管理所带来的指针操作错误。Go 的垃圾回收器定期扫描并释放不再使用的内存,避免了内存泄漏和悬空指针问题。</li><li><code>指针的安全性</code> Go 语言的指针是受限的,不支持指针运算,从而减少了指针操作可能带来的风险。</li></ul></li><li><p><code>Rust</code>采用了如下的策略和机制,来解决指针危险操作的:</p><ul><li><code>所有权和借用</code> Rust 引入了所有权和借用的概念,编译器在编译时静态分析所有权转移和引用的生命周期。这种机制避免了数据竞争和空指针解引用等运行时错误,使得在编译时就能够保证内存安全。</li><li><code>生命周期</code> Rust 的生命周期系统确保引用的有效性和安全性,防止了悬空引用和指针乱用。</li></ul></li><li><p><code>Java</code>采用了如下的策略和机制,来解决指针危险操作的:</p><ul><li><code>引用类型和自动内存管理</code> Java 中所有的对象引用都是通过引用来访问的而不是直接的指针。Java 的自动垃圾回收器负责管理内存,从而避免了手动内存管理可能导致的指针错误,如:内存泄漏和悬空指针。</li><li><code>强类型系统和异常处理</code> Java 的强类型系统和异常处理机制减少了指针操作带来的风险空指针解引用异常NullPointerException。编译器在编译时能够捕获许多潜在的类型错误进一步增强了程序的安全性和可靠性。</li></ul></li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p>总而言之,各种编程语言通过引入不同的策略和机制,如:智能指针、垃圾回收器、所有权和借用,以及强类型系统,有效地减少了指针操作所带来的各种安全性和可靠性问题,提升了程序的稳定性和开发效率。</p></div><h1 id="第二章-回顾知识" tabindex="-1">第二章:回顾知识 <a class="header-anchor" href="#第二章-回顾知识" aria-label="Permalink to &quot;第二章:回顾知识&quot;"></a></h1><h2 id="_2-1-变量" tabindex="-1">2.1 变量 <a class="header-anchor" href="#_2-1-变量" aria-label="Permalink to &quot;2.1 变量&quot;"></a></h2><ul><li>变量就是保存程序运行过程中临时产生的值,其语法如下:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">数据类型 变量名 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 值 ;</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p>变量名(标识符)需要符合命名规则和命名规范!!!</p><ul><li>强制规范: <ul><li>① 只能由<code>小写</code><code>大写英文字母</code><code>0-9</code><code>_</code> 组成。</li><li>② 不能以<code>数字</code>开头。</li><li>③ 不可以是<code>关键字</code></li><li>④ 标识符具有<code>长度</code>限制,不同编译器和平台会有所不同,一般限制在 63 个字符内。</li><li>⑤ 严格<code>区分大小写字母</code>Hello、hello 是不同的标识符。</li></ul></li><li>建议规范: <ul><li>① 为了提高阅读性使用有意义的单词见名知意sumnamemaxyear 等。</li><li>② 使用下划线连接多个单词组成的标识符max_classes_per_student 等。</li><li>③ 多个单词组成的标识符,除了使用下划线连接,也可以使用小驼峰命名法,除第一个单词外,后续单词的首字母大写,如: studentId、student_name 等。</li><li>④ 不要出现仅靠大小写区分不同的标识符name、Name 容易混淆。</li><li>⑤ 系统内部使用了一些下划线开头的标识符C99 标准添加的类型 <code>_Bool</code>,为防止冲突,建议开发者尽量避免使用下划线开头的标识符。</li></ul></li></ul></div><ul><li><code>变量名</code><code>作用</code>,如下所示: <ul><li>① 当我们<code>编写</code>代码的时候,使用<code>变量名</code><code>关联</code>某块内存的<code>地址</code></li><li>② 当 CPU <code>执行</code>的时候,会将变量名<code>替换</code>为具体的地址,再进行具体的操作。</li></ul></li></ul><h2 id="_2-2-普通变量和指针变量的区别" tabindex="-1">2.2 普通变量和指针变量的区别 <a class="header-anchor" href="#_2-2-普通变量和指针变量的区别" aria-label="Permalink to &quot;2.2 普通变量和指针变量的区别&quot;"></a></h2><ul><li>根据<code>变量</code><code>存储</code><code></code><code>不同</code>,我们可以将<code>变量</code>分为两类: <ul><li><code>普通变量</code>:变量所对应的内存中存储的是<code>普通值</code></li><li><code>指针变量</code>:变量所对应的内存中存储的是<code>另一个变量的地址</code></li></ul></li><li>如下图所示:</li></ul><p><img src="/c/assets/1.L8V3GBrc.png" alt="img" loading="lazy"></p><ul><li>普通变量和指针变量的相同点,如下所示: <ul><li>① 普通变量有内存空间,指针变量也有内存空间。</li><li>② 普通变量有内存地址,指针变量也有内存地址。</li><li>③ 普通变量所对应的内存空间中有值,指针变量所对应的内存空间中也有值。</li></ul></li><li>普通变量和指针变量的不同点: <ul><li><code>普通变量</code>所对应的内存空间<code>存储</code>的是<code>普通的值</code>,如:整数、小数、字符等;<code>指针变量</code>所对应的内存空间<code>存储</code>的是另外一个变量的<code>地址</code></li><li><code>普通变量有普通变量的运算方式</code>,而<code>指针变量有指针变量的运算方式</code>(后续讲解)。</li></ul></li></ul><h2 id="_2-3-运算符" tabindex="-1">2.3 运算符 <a class="header-anchor" href="#_2-3-运算符" aria-label="Permalink to &quot;2.3 运算符&quot;"></a></h2><h3 id="_2-3-1-概述" tabindex="-1">2.3.1 概述 <a class="header-anchor" href="#_2-3-1-概述" aria-label="Permalink to &quot;2.3.1 概述&quot;"></a></h3><ul><li>运算符是一种特殊的符号,用于数据的运算、赋值和比较等。</li><li><code>表达式</code>指的是一组运算数、运算符的组合,表达式<code>一定具有值</code>,一个变量或一个常量可以是表达式,变量、常量和运算符也可以组成表达式,如:</li></ul><p><img src="/c/assets/2.CdvhiwcU.png" alt="img" loading="lazy"></p><ul><li><code>操作数</code>指的是<code>参与运算</code><code></code>或者<code>对象</code>,如:</li></ul><p><img src="/c/assets/3.D74t3-Xt.png" alt="" loading="lazy"></p><ul><li>根据<code>操作数</code><code>个数</code>,可以将运算符分为: <ul><li>一元运算符(一目运算符)。</li><li>二元运算符(二目运算符)。</li><li>三元运算符(三目运算符)。</li></ul></li><li>根据<code>功能</code>,可以将运算符分为: <ul><li>算术运算符。</li><li>关系运算符(比较运算符)。</li><li>逻辑运算符。</li><li>赋值运算符。</li><li>逻辑运算符。</li><li>位运算符。</li><li>三元运算符。</li></ul></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>掌握一个运算符,需要关注以下几个方面:</p><ul><li>① 运算符的含义。</li><li>② 运算符操作数的个数。</li><li>③ 运算符所组成的表达式。</li><li>④ 运算符有无副作用,即:运算后是否会修改操作数的值。</li></ul></div><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p>普通变量支持上述的所有运算符;而指针变量并非支持上述的所有运算符,且支持运算符的含义和普通变量相差较大!!!</p></div><h3 id="_2-3-2-运算符的优先级" tabindex="-1">2.3.2 运算符的优先级 <a class="header-anchor" href="#_2-3-2-运算符的优先级" aria-label="Permalink to &quot;2.3.2 运算符的优先级&quot;"></a></h3><ul><li>C 语言中运算符的优先级,如下所示:</li></ul><table tabindex="0"><thead><tr><th><strong>优先级</strong></th><th><strong>运算符</strong></th><th><strong>名称或含义</strong></th><th><strong>结合方向</strong></th></tr></thead><tbody><tr><td><strong>1</strong></td><td><code>[]</code></td><td>数组下标</td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>()</code></td><td>圆括号</td><td></td></tr><tr><td></td><td><code>.</code></td><td>成员选择(对象)</td><td></td></tr><tr><td></td><td><code>-&gt;</code></td><td>成员选择(指针)</td><td></td></tr><tr><td><strong>2</strong></td><td><code>-</code></td><td>负号运算符</td><td>⬅️(从右到左)</td></tr><tr><td></td><td><code>(类型)</code></td><td>强制类型转换</td><td></td></tr><tr><td></td><td><code>++</code></td><td>自增运算符</td><td></td></tr><tr><td></td><td><code>--</code></td><td>自减运算符</td><td></td></tr><tr><td></td><td><code>*</code></td><td>取值运算符</td><td></td></tr><tr><td></td><td><code>&amp;</code></td><td>取地址运算符</td><td></td></tr><tr><td></td><td><code>!</code></td><td>逻辑非运算符</td><td></td></tr><tr><td></td><td><code>~</code></td><td>按位取反运算符</td><td></td></tr><tr><td></td><td><code>sizeof</code></td><td>长度运算符</td><td></td></tr><tr><td><strong>3</strong></td><td><code>/</code></td><td></td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>*</code></td><td></td><td></td></tr><tr><td></td><td><code>%</code></td><td>余数(取模)</td><td></td></tr><tr><td><strong>4</strong></td><td><code>+</code></td><td></td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>-</code></td><td></td><td></td></tr><tr><td><strong>5</strong></td><td><code>&lt;&lt;</code></td><td>左移</td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>&gt;&gt;</code></td><td>右移</td><td></td></tr><tr><td><strong>6</strong></td><td><code>&gt;</code></td><td>大于</td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>&gt;=</code></td><td>大于等于</td><td></td></tr><tr><td></td><td><code>&lt;</code></td><td>小于</td><td></td></tr><tr><td></td><td><code>&lt;=</code></td><td>小于等于</td><td></td></tr><tr><td><strong>7</strong></td><td><code>==</code></td><td>等于</td><td>➡️(从左到右)</td></tr><tr><td></td><td><code>!=</code></td><td>不等于</td><td></td></tr><tr><td><strong>8</strong></td><td><code>&amp;</code></td><td>按位与</td><td>➡️(从左到右)</td></tr><tr><td><strong>9</strong></td><td><code>^</code></td><td>按位异或</td><td>➡️(从左到右)</td></tr><tr><td><strong>10</strong></td><td><code>|</code></td><td>按位或</td><td>➡️(从左到右)</td></tr><tr><td><strong>11</strong></td><td><code>&amp;&amp;</code></td><td>逻辑与</td><td>➡️(从左到右)</td></tr><tr><td><strong>12</strong></td><td><code>||</code></td><td>逻辑或</td><td>➡️(从左到右)</td></tr><tr><td><strong>13</strong></td><td><code>?:</code></td><td>条件运算符</td><td>⬅️(从右到左)</td></tr><tr><td><strong>14</strong></td><td><code>=</code></td><td>赋值运算符</td><td>⬅️(从右到左)</td></tr><tr><td></td><td><code>/=</code></td><td>除后赋值</td><td></td></tr><tr><td></td><td><code>*=</code></td><td>乘后赋值</td><td></td></tr><tr><td></td><td><code>%=</code></td><td>取模后赋值</td><td></td></tr><tr><td></td><td><code>+=</code></td><td>加后赋值</td><td></td></tr><tr><td></td><td><code>-=</code></td><td>减后赋值</td><td></td></tr><tr><td></td><td><code>&lt;&lt;=</code></td><td>左移后赋值</td><td></td></tr><tr><td></td><td><code>&gt;&gt;=</code></td><td>右移后赋值</td><td></td></tr><tr><td></td><td><code>&amp;=</code></td><td>按位与后赋值</td><td></td></tr><tr><td></td><td><code>^=</code></td><td>按位异或后赋值</td><td></td></tr><tr><td></td><td><code>|=</code></td><td>按位或后赋值</td><td></td></tr><tr><td><strong>15</strong></td><td><code>,</code></td><td>逗号运算符</td><td>➡️(从左到右)</td></tr></tbody></table><div class="warning custom-block github-alert"><p class="custom-block-title">WARNING</p><p></p><ul><li>① 不要过多的依赖运算符的优先级来控制表达式的执行顺序,这样可读性太差,尽量<code>使用小括号来控制</code>表达式的执行顺序。</li><li>② 不要把一个表达式写得过于复杂,如果一个表达式过于复杂,则把它<code>分成几步</code>来完成。</li><li>③ 运算符优先级不用刻意地去记忆,总体上:一元运算符 &gt; 算术运算符 &gt; 关系运算符 &gt; 逻辑运算符 &gt; 三元运算符 &gt; 赋值运算符。</li></ul></div><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li>① 取值运算符 <code>*</code> 和取地址运算符 <code>&amp;</code> 的优先级相同,并且运算方向都是从右向左!!!</li><li>② 逗号运算符 <code>,</code> 的优先级最低,并且运算方向是从左向右!!!</li></ul></div><h1 id="第三章-指针的理解和定义-⭐" tabindex="-1">第三章:指针的理解和定义(⭐) <a class="header-anchor" href="#第三章-指针的理解和定义-⭐" aria-label="Permalink to &quot;第三章:指针的理解和定义(⭐)&quot;"></a></h1><h2 id="_3-1-变量的访问方式" tabindex="-1">3.1 变量的访问方式 <a class="header-anchor" href="#_3-1-变量的访问方式" aria-label="Permalink to &quot;3.1 变量的访问方式&quot;"></a></h2><ul><li>计算机中程序的运行都是在内存中进行的变量也是内存中分配的空间且不同类型的变量占据的内存空间大小不同char 类型的变量是 1 个字节short 类型的变量是 2 个字节int 类型的变量是 4 个字节...</li><li>之前我们都是通过<code>变量名(普通变量)</code>访问内存中存储的数据,如下所示:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义变量,即:开辟一块内存空间,并将初始化值存储进去</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 访问变量,即:访问变量在内存中对应的数据</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;num = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 给变量赋值,即:给变量在内存中占据的内存空间存储数据</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 100</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 访问变量,即:访问变量在内存中对应的数据</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;num = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br></div></div><ul><li>上述的这种方式也称为<code>直接访问</code>;当然,既然有<code>直接访问</code>的方式,必然有<code>间接访问</code>的方式,如:<code>指针</code></li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li>① 我们通过<code>变量名(普通变量)</code>访问内存中变量存储的数据,之所以称为<code>直接访问</code>的方式,是因为对于我们写程序而言,我们无需关心如何根据内存地址去获取内存中对应的数据,也无需关系如何根据内存地址将数据存储到对应的内存空间,这些操作步骤都是<code>编译器</code>帮助我们在底层自动完成的(自动化)。</li><li>② 但是,我们也可以通过<code>内存地址</code>去操作内存中对应的数据(手动化),这种方式就称为<code>间接访问</code>的方式了,相对于<code>直接访问</code>方式来说,要<code>理解</code><code>概念</code><code>操作</code><code>步骤</code>和之前<code>直接访问</code>的方式相比,要复杂和麻烦很多,但是效率高。</li></ul></div><h2 id="_3-2-内存地址和指针" tabindex="-1">3.2 内存地址和指针 <a class="header-anchor" href="#_3-2-内存地址和指针" aria-label="Permalink to &quot;3.2 内存地址和指针&quot;"></a></h2><ul><li>其实,在之前《数组》中,我们就已经讲解了<code>内存地址</code>的概念了,即:操作系统为了更快的去管理内存中的数据,会将<code>内存条</code>按照<code>字节</code>划分为一个个的<code>单元格</code>,并为每个独立的小的<code>单元格</code>,分配<code>唯一的编号</code>,即:<code>内存地址</code>,如下所示:</li></ul><p><img src="/c/assets/4.DqDR6Thp.svg" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>有了内存地址,就能加快数据的存取速度,可以类比生活中的<code>字典</code>,即:</p><ul><li>① 内存地址是计算机中用于标识内存中某个特定位置的数值。</li><li>② 每个内存单元都有一个唯一的地址,这些地址可以用于访问和操作存储在内存中的数据。</li></ul></div><ul><li>对于之前的代码,如下所示:</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 定义变量,即:开辟一块内存空间,并将初始化值存储进去</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><ul><li>虽然,之前我们在程序中都是通过<code>变量名(普通变量)</code>直接操作内存中的存储单元;但是,编译器底层还是会通过<code>内存地址</code>来找到所需要的存储单元,如下所示:</li></ul><p><img src="/c/assets/5.BzSkS-4w.svg" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>通过<code>内存地址</code>找到所需要的<code>存储单元</code>,即:内存地址指向该存储单元。此时,就可以将<code>内存地址</code>形象化的描述为<code>指针👉</code>,那么:</p><ul><li><code>变量</code>:命名的内存空间,用于存放各种类型的数据。</li><li><code>变量名</code>:变量名是给内存空间取一个容易记忆的名字,方便我们编写程序。</li><li><code>变量值</code>:变量所对应的内存中的存储单元中存放的数据值。</li><li><code>变量的地址</code>:变量所对应的内存中的存储单元的内存地址(首地址),也可以称为<code>指针</code></li></ul><p>总结:内存地址 = 指针。</p></div><ul><li><code>普通变量</code>所对应的内存空间<code>存储</code>的是<code>普通的值</code>,如:整数、小数、字符等;<code>指针变量</code>所对应的内存空间<code>存储</code>的是另外一个变量的<code>地址(指针)</code>,如下所示:</li></ul><p><img src="/c/assets/6.BPY9ZGed.svg" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>有的时候,为了方便阐述,我们会将<code>指针变量</code>称为<code>指针</code>。但是,需要记住的是:</p><ul><li>指针 = 内存地址。</li><li>指针变量 = 变量中保存的是另一个变量的地址。</li></ul><p>下文中提及的<code>指针</code>都是<code>指针变量</code>,不再阐述!!!</p></div><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p>如果你观察仔细的话,你可能会发现<code>指针变量</code><code>普通变量</code>在内存中占据的存储空间是不一样的,那么到底是什么原因造成这样的结果?</p></div><h2 id="_3-3-指针变量的定义" tabindex="-1">3.3 指针变量的定义 <a class="header-anchor" href="#_3-3-指针变量的定义" aria-label="Permalink to &quot;3.3 指针变量的定义&quot;"></a></h2><h2 id="_3-4-指针的作用" tabindex="-1">3.4 指针的作用 <a class="header-anchor" href="#_3-4-指针的作用" aria-label="Permalink to &quot;3.4 指针的作用&quot;"></a></h2><ul><li>查询数据。</li><li>存储数据。</li><li>参数传递。</li><li>内存管理。</li></ul><p>在 Java 中引用数据类型的向上类型转换upcasting和向下类型转换downcasting是面向对象编程中常见的操作。这些转换是 Java 继承体系和多态性的重要部分。我们先分别介绍向上类型转换和向下类型转换,然后讨论它们在 C 语言中指针的类似操作。</p><h3 id="向上类型转换-upcasting" tabindex="-1">向上类型转换Upcasting <a class="header-anchor" href="#向上类型转换-upcasting" aria-label="Permalink to &quot;向上类型转换Upcasting&quot;"></a></h3><p>向上类型转换是将一个子类对象引用转换为父类对象引用。由于子类继承了父类的所有方法和属性,子类对象也包含父类对象的所有部分,因此这种转换是安全且隐式的。</p><p><strong>例子:</strong></p><div class="language-java vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">java</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">class</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Animal</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> void</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> makeSound</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> System.out.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">println</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;Animal sound&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">class</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Dog</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> extends</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Animal</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> void</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> makeSound</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> System.out.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">println</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;Bark&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">public</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> class</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> public</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> static</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> void</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">String</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[] </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">args</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Dog dog </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> new</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Dog</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">();</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Animal animal </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> dog; </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// Upcasting, 隐式转换</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> animal.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">makeSound</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(); </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 输出Bark</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br></div></div><p>在这个例子中,<code>Dog</code> 类型的对象 <code>dog</code> 被转换为 <code>Animal</code> 类型。尽管 <code>animal</code> 引用的实际对象是 <code>Dog</code>,但在编译时,<code>animal</code> 被视为 <code>Animal</code> 类型。</p><h3 id="向下类型转换-downcasting" tabindex="-1">向下类型转换Downcasting <a class="header-anchor" href="#向下类型转换-downcasting" aria-label="Permalink to &quot;向下类型转换Downcasting&quot;"></a></h3><p>向下类型转换是将一个父类对象引用转换为子类对象引用。由于父类对象不一定具有子类的所有方法和属性,因此这种转换需要显式进行,并且在运行时进行类型检查(使用 <code>instanceof</code> 关键字来确保安全)。</p><p><strong>例子:</strong></p><div class="language-java vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">java</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">public</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> class</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> public</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> static</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> void</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">String</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[] </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">args</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Animal animal </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> new</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Dog</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(); </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// Upcasting</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (animal </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">instanceof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Dog) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Dog dog </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (Dog) animal; </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// Downcasting, 显式转换</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> dog.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">makeSound</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(); </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 输出Bark</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><p>在这个例子中,<code>animal</code> 引用的对象实际是 <code>Dog</code> 类型,在向下转换之前使用 <code>instanceof</code> 检查以确保安全。</p><h3 id="区别" tabindex="-1">区别 <a class="header-anchor" href="#区别" aria-label="Permalink to &quot;区别&quot;"></a></h3><ul><li><strong>向上类型转换</strong>:隐式的,安全的,因为子类是父类的扩展。</li><li><strong>向下类型转换</strong>:显式的,可能不安全,需要运行时检查,因为父类不一定具有子类的特性。</li></ul><h3 id="c-语言中的指针转换" tabindex="-1">C 语言中的指针转换 <a class="header-anchor" href="#c-语言中的指针转换" aria-label="Permalink to &quot;C 语言中的指针转换&quot;"></a></h3><p>在 C 语言中,指针的转换类似于引用类型的转换,但由于 C 语言没有继承和多态的概念,其转换更多是基于内存布局。</p><p><strong>例子:</strong></p><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">void</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printInt</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">void*</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> ptr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)ptr);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> x </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> void*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> voidPtr </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">x;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // Upcasting, 隐式转换</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printInt</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(voidPtr);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 输出10</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> intPtr </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)voidPtr;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // Downcasting, 显式转换</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">intPtr);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 输出10</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><p>在这个例子中,<code>void*</code> 是通用指针类型,可以指向任何类型的数据。将 <code>int*</code> 转换为 <code>void*</code> 是隐式的,而将 <code>void*</code> 转换为 <code>int*</code> 是显式的。由于 C 没有类型检查,因此这种转换需要程序员自己确保安全。</p><p>总结:</p><ul><li>Java 中的向上类型转换和向下类型转换是为了支持多态性和继承,向上转换是安全的,向下转换需要显式进行并且进行运行时检查。</li><li>C 语言中的指针转换没有多态性和继承的概念,但有类似的指针类型转换操作,程序员需要确保转换的安全性。</li></ul><h1 id="第四章-指针的运算-⭐" tabindex="-1">第四章:指针的运算(⭐) <a class="header-anchor" href="#第四章-指针的运算-⭐" aria-label="Permalink to &quot;第四章:指针的运算(⭐)&quot;"></a></h1><h2 id="_4-1-概述" tabindex="-1">4.1 概述 <a class="header-anchor" href="#_4-1-概述" aria-label="Permalink to &quot;4.1 概述&quot;"></a></h2><h2 id="_4-2-总结" tabindex="-1">4.2 总结 <a class="header-anchor" href="#_4-2-总结" aria-label="Permalink to &quot;4.2 总结&quot;"></a></h2><ul><li><p>在 C 语言中,<code>普通变量</code>是直接存储<code>数据</code><code>变量</code>。对于普通变量,支持的操作包括:</p><ul><li><strong>赋值操作</strong>:给变量赋值,如:<code>int a = 5</code></li><li><strong>算术运算</strong>:可以对数值类型的普通变量进行加、减、乘、除等运算,如:<code>a + b</code><code>a - b</code><code>a * b</code><code>a / b</code></li><li><strong>关系运算</strong>:可以进行比较运算(大于、小于、等于等),如: <code>a &gt; b</code><code>a == b</code></li><li><strong>逻辑运算</strong>:对布尔类型的值进行与、或、非运算,如: <code>a &amp;&amp; b</code><code>a || b</code><code>!a</code></li><li><strong>位运算</strong>:对整数类型的值进行位操作(与、或、异或、取反、左移、右移等),如: <code>a &amp; b</code><code>a | b</code><code>a ^ b</code><code>~a</code><code>a &lt;&lt; 2</code><code>a &gt;&gt; 2</code></li><li><strong>自增自减运算</strong><code>a++</code><code>--a</code> 等。</li></ul></li><li><p>在 C 语言中,<code>指针变量</code>存储的是<code>另一个变量</code><code>地址</code>。对于指针变量,支持的操作包括:</p><ul><li><strong>赋值操作</strong>:可以将一个地址赋值给指针,如: <code>int *p = &amp;a;</code></li><li><strong>解引用操作</strong>:通过指针访问它指向的变量,如: <code>*p = 10;</code> 修改指向变量的值。</li><li><strong>指针运算</strong> <ul><li><strong>指针和整数值的加减运算</strong>:指针可以进行整数的加减运算,用于访问数组或结构体成员,如: <code>p + 1</code></li><li><strong>指针的自增和自减运算</strong>:指的是内存地址的向前或向后移动,如:<code>p++</code><code>p--</code></li><li><strong>指针间的相减运算</strong>:两个指向同一数组的指针相减可以得到它们之间的元素个数,如: <code>ptr1 - ptr2</code></li><li><strong>指针间的比较运算</strong>:可以比较两个指针的大小,比较的是各自内存地址的大小,如: <code>p1 == p2</code><code>p1 != p2</code></li></ul></li><li><strong>数组访问</strong>:指针可以用于访问数组中的元素,通过 <code>*(p + i)</code> 访问第 <code>i</code> 个元素。</li><li><strong>指向指针的指针</strong>:可以声明指向指针的指针,即多级指针,如:<code>int **pp = &amp;p;</code></li></ul></li></ul><div class="warning custom-block github-alert"><p class="custom-block-title">WARNING</p><p></p><p>在使用指针时,务必小心避免野指针和内存泄漏等问题。</p></div><p>在C语言中同类指针相减的结果是一个整数它表示两个指针之间相隔多少个指向的对象单位而不是它们在内存中的字节偏移量。这种对象单位是指针所指向的具体类型的大小。</p><p>举个例子来说,如果你有两个指向整数数组元素的指针 <code>p</code><code>q</code>,那么 <code>p - q</code> 的结果将是 <code>p</code> 指向的数组元素的索引与 <code>q</code> 指向的数组元素索引之间的差值。这个差值代表了在数组中相隔多少个整数元素,而不是它们在内存中的字节偏移量。</p><p>这种设计的优势在于,它使得指针运算更加直观和便于理解,特别是在处理数组和其他连续存储的数据结构时。因为指针运算结果的单位是根据指针所指向的具体类型来计算的,这样可以确保不同平台上的程序行为是一致的,不会受到底层硬件架构或者字节对齐规则的影响。</p><p>在C语言中数组名和指针有很多相似之处但数组名并不是指针变量。数组名实际是一个常量它指向数组的第一个元素的地址。为了证明这一点可以通过以下几个方面来说明</p><ol><li><p><strong>数组名表示数组首地址</strong> 数组名可以作为一个指针使用,数组名本身表示的是数组首地址。</p><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">ptr </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 这句话是合法的ptr现在指向arr[0]</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%p\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, arr);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 打印数组名,会打印数组首地址</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%p\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 打印第一个元素的地址</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div></li><li><p><strong>数组名是常量指针</strong> 数组名是一个常量指针,不能改变它指向的位置,而指针变量可以改变它指向的位置。</p><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">ptr </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 合法ptr指向arr[0]</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">ptr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 合法ptr现在指向arr[1]</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// arr++; // 非法,编译错误,因为数组名是常量,不能改变</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div></li><li><p><strong>sizeof运算符的结果不同</strong> 使用<code>sizeof</code>运算符对数组名和指针变量会得到不同的结果,数组名会返回整个数组的大小,而指针变量会返回指针本身的大小。</p><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">ptr </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;sizeof(arr) = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%lu\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(arr));</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 返回数组的大小5 * sizeof(int)</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;sizeof(ptr) = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%lu\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">sizeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(ptr));</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 返回指针的大小通常是4或8字节</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div></li><li><p><strong>地址运算符的结果不同</strong> 使用地址运算符<code>&amp;</code>对数组名和指针变量会得到不同的结果,对数组名使用<code>&amp;</code>会返回数组的地址,而对指针变量使用<code>&amp;</code>会返回指针变量本身的地址。</p><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">];</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">ptr </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> arr;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;Address of array: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%p\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">arr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 返回整个数组的地址</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;Address of pointer: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%p\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">ptr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 返回指针变量ptr的地址</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div></li></ol><p>综上所述,通过这些示例和解释,可以看出数组名虽然在某些场合下可以像指针一样使用,但它并不是一个真正的指针变量,而是一个常量,表示数组的首地址。</p></div></div></main><footer class="VPDocFooter" data-v-39a288b8 data-v-e257564d><!--[--><!--]--><div class="edit-info" data-v-e257564d><!----><div class="last-updated" data-v-e257564d><p class="VPLastUpdated" data-v-e257564d data-v-e98dd255>上次更新: <time datetime="2024-08-27T03:11:14.000Z" data-v-e98dd255></time></p></div></div><nav class="prev-next" aria-labelledby="doc-footer-aria-label" data-v-e257564d><span class="visually-hidden" id="doc-footer-aria-label" data-v-e257564d>Pager</span><div class="pager" data-v-e257564d><a class="VPLink link pager-link prev" href="/c/notes/01_c-basic/06_xdx/" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>上一篇</span><span class="title" data-v-e257564d>数组</span><!--]--></a></div><div class="pager" data-v-e257564d><a class="VPLink link pager-link next" href="/c/notes/01_c-basic/08_xdx/" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>下一篇</span><span class="title" data-v-e257564d>函数</span><!--]--></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><footer class="VPFooter has-sidebar" data-v-5d98c3a5 data-v-e315a0ad><div class="container" data-v-e315a0ad><p class="message" data-v-e315a0ad>Released under the MIT License.</p><p class="copyright" data-v-e315a0ad>Copyright © 2024 许大仙</p></div></footer><!--[--><!--]--></div></div>
<script>window.__VP_HASH_MAP__=JSON.parse("{\"index.md\":\"Dga0tMF5\",\"notes_01_c-basic_00_xdx_index.md\":\"BRC7slaL\",\"notes_01_c-basic_01_xdx_index.md\":\"Fg4OXydV\",\"notes_01_c-basic_02_xdx_index.md\":\"CC2Mg9VD\",\"notes_01_c-basic_03_xdx_index.md\":\"Cw3Z19MO\",\"notes_01_c-basic_04_xdx_index.md\":\"ySxH8sG-\",\"notes_01_c-basic_05_xdx_index.md\":\"DUbOwEts\",\"notes_01_c-basic_06_xdx_index.md\":\"CV_r2WNu\",\"notes_01_c-basic_07_xdx_index.md\":\"CE9q5cmu\",\"notes_04_linux_01_xdx_index.md\":\"C9IatKsj\",\"notes_about_index.md\":\"DLuQgC_8\",\"notes_index.md\":\"CeV-uJ5V\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"zh-CN\",\"dir\":\"ltr\",\"title\":\"许大仙\",\"titleTemplate\":\"Hi终于等到你\",\"description\":\"许大仙前端、Java、大数据、云原生\",\"base\":\"/c/\",\"head\":[],\"router\":{\"prefetchLinks\":true},\"appearance\":true,\"themeConfig\":{\"lastUpdatedText\":\"上次更新\",\"returnToTopLabel\":\"返回顶部\",\"search\":{\"provider\":\"local\"},\"logo\":\"/logo.svg\",\"nav\":[{\"text\":\"首页\",\"link\":\"https://aexiar.github.io/\"},{\"text\":\"计组6件套\",\"link\":\"https://aexiar.github.io/coa6/notes/\"},{\"text\":\"编程语言\",\"items\":[{\"text\":\"c/c++\",\"link\":\"/notes/\"},{\"text\":\"前端\",\"link\":\"https://aexiar.github.io/web-design/notes/\"},{\"text\":\"Java\",\"link\":\"https://aexiar.github.io/java/notes/\"},{\"text\":\"大数据\",\"link\":\"https://aexiar.github.io/big-data/notes/\"},{\"text\":\"云原生\",\"link\":\"https://aexiar.github.io/linux/notes/\"},{\"text\":\"Go\",\"link\":\"https://aexiar.github.io/go/notes/\"},{\"text\":\"Python\",\"link\":\"https://aexiar.github.io/python/notes/\"}]},{\"text\":\"数据库\",\"link\":\"https://aexiar.github.io/db/notes/\"},{\"text\":\"开源软件\",\"link\":\"https://aexiar.github.io/open-software/notes/\"},{\"text\":\"关于我\",\"link\":\"/notes/about/\"}],\"sidebar\":{\"/notes/\":[{\"text\":\"C 语言基础\",\"collapsed\":true,\"items\":[{\"text\":\"编程基础\",\"link\":\"/notes/01_c-basic/00_xdx/\"},{\"text\":\"C 语言入门\",\"link\":\"/notes/01_c-basic/01_xdx/\"},{\"text\":\"变量和进制\",\"link\":\"/notes/01_c-basic/02_xdx/\"},{\"text\":\"数据类型和运算符\",\"link\":\"/notes/01_c-basic/03_xdx/\"},{\"text\":\"大话小数\",\"link\":\"/notes/01_c-basic/04_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/01_c-basic/05_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/01_c-basic/06_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/01_c-basic/07_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/01_c-basic/08_xdx/\"},{\"text\":\"预处理器\",\"link\":\"/notes/01_c-basic/09_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/01_c-basic/10_xdx/\"},{\"text\":\"内存管理\",\"link\":\"/notes/01_c-basic/11_xdx/\"},{\"text\":\"文件操作\",\"link\":\"/notes/01_c-basic/12_xdx/\"},{\"text\":\"调试工具和调试技巧gdb和make\",\"link\":\"/notes/02_c-basic/13_xdx/\"},{\"text\":\"常用库函数\",\"link\":\"/notes/01_c-basic/14_xdx/\"}]},{\"text\":\"C 语言高级\",\"collapsed\":true,\"items\":[{\"text\":\"变量和内存分布\",\"link\":\"/notes/02_c-advance/01_xdx/\"},{\"text\":\"指针强化\",\"link\":\"/notes/02_c-advance/02_xdx/\"},{\"text\":\"结构体和文件的高级用法\",\"link\":\"/notes/02_c-advance/03_xdx/\"},{\"text\":\"链表和回调函数\",\"link\":\"/notes/02_c-advance/04_xdx/\"},{\"text\":\"编译过程和面向接口\",\"link\":\"/notes/02_c-advance/05_xdx/\"}]},{\"text\":\"项目构建工具\",\"collapsed\":true,\"items\":[{\"text\":\"meson\",\"collapsed\":true,\"items\":[{\"text\":\"meson 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Cmake\",\"collapsed\":true,\"items\":[{\"text\":\"Cmake 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Conan \",\"link\":\"/notes/03_build/01_${commonDirectoryName}/\"},{\"text\":\"Gradle\",\"collapsed\":true,\"items\":[{\"text\":\"Gradle 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]}]},{\"text\":\"Linux\",\"collapsed\":true,\"items\":[{\"text\":\"Linux 初识和安装\",\"link\":\"/notes/04_linux/01_xdx/\"}]},{\"text\":\"C++ 基础\",\"collapsed\":true,\"items\":[{\"text\":\"C++ 入门\",\"link\":\"/notes/05_cpp/01_xdx/\"},{\"text\":\"变量、数据类型、运算符\",\"link\":\"/notes/05_cpp/02_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/05_cpp/03_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/05_cpp/04_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/05_cpp/05_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/05_cpp/06_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/05_cpp/07_xdx/\"},{\"text\":\"类和对象\",\"link\":\"/notes/05_cpp/08_xdx/\"},{\"text\":\"C++ 引用\",\"link\":\"/notes/05_cpp/09_xdx/\"},{\"text\":\"继承和派生\",\"link\":\"/notes/05_cpp/10_xdx/\"},{\"text\":\"C++ 多态和虚函数\",\"link\":\"/notes/05_cpp/11_xdx/\"},{\"text\":\"运算符重载\",\"link\":\"/notes/05_cpp/12_xdx/\"},{\"text\":\"模板\",\"link\":\"/notes/05_cpp/13_xdx/\"},{\"text\":\"C++ 异常\",\"link\":\"/notes/05_cpp/14_xdx/\"},{\"text\":\"面向对象进阶\",\"link\":\"/notes/05_cpp/15_xdx/\"},{\"text\":\"文件操作和 IO 流\",\"link\":\"/notes/05_cpp/16_xdx/\"},{\"text\":\"STL标准模板库\",\"link\":\"/notes/05_cpp/17_xdx/\"}]},{\"text\":\"C++ 高级\",\"collapsed\":true,\"items\":[]},{\"text\":\"QT 桌面开发\",\"collapsed\":true,\"items\":[]},{\"text\":\"Linux 高并发服务器开发\",\"collapsed\":true,\"items\":[]}]},\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/Aurorxa\"}],\"docFooter\":{\"prev\":\"上一篇\",\"next\":\"下一篇\"},\"darkModeSwitchLabel\":\"深浅模式\",\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2024 许大仙\"},\"outline\":{\"level\":[1,6],\"label\":\"目录\"},\"outlineTitle\":\"当前页大纲\"},\"locales\":{},\"scrollOffset\":134,\"cleanUrls\":false}");</script>
</body>
</html>

File diff suppressed because one or more lines are too long

View File

@ -8,9 +8,9 @@
<meta name="generator" content="VitePress v1.3.3">
<link rel="preload stylesheet" href="/c/assets/style.zDJ0OJGU.css" as="style">
<script type="module" src="/c/assets/app.Ca2FOFw4.js"></script>
<script type="module" src="/c/assets/app.1a4d5P-6.js"></script>
<link rel="preload" href="/c/assets/inter-roman-latin.Di8DUHzh.woff2" as="font" type="font/woff2" crossorigin="">
<link rel="modulepreload" href="/c/assets/chunks/theme.C6fZfLtk.js">
<link rel="modulepreload" href="/c/assets/chunks/theme.Ddh-lpYV.js">
<link rel="modulepreload" href="/c/assets/chunks/framework.hMCIpNYY.js">
<link rel="modulepreload" href="/c/assets/notes_about_index.md.DLuQgC_8.lean.js">
<link rel="shortcut icon" href="/c//logo.svg">
@ -22,8 +22,8 @@
<script id="check-mac-os">document.documentElement.classList.toggle("mac",/Mac|iPhone|iPod|iPad/i.test(navigator.platform));</script>
</head>
<body>
<div id="app"><div class="Layout" data-v-5d98c3a5><!--[--><!--]--><!--[--><span tabindex="-1" data-v-0f60ec36></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-0f60ec36> Skip to content </a><!--]--><!----><header class="VPNav" data-v-5d98c3a5 data-v-ae24b3ad><div class="VPNavBar has-sidebar top" data-v-ae24b3ad data-v-6aa21345><div class="wrapper" data-v-6aa21345><div class="container" data-v-6aa21345><div class="title" data-v-6aa21345><div class="VPNavBarTitle has-sidebar" data-v-6aa21345 data-v-ab179fa1><a class="title" href="/c/" data-v-ab179fa1><!--[--><!--]--><!--[--><img class="VPImage logo" src="/c/logo.svg" alt data-v-8426fc1a><!--]--><span data-v-ab179fa1>许大仙</span><!--[--><!--]--></a></div></div><div class="content" data-v-6aa21345><div class="content-body" data-v-6aa21345><!--[--><!--]--><div class="VPNavBarSearch search" data-v-6aa21345><!--[--><!----><div id="local-search"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><span class="vp-icon DocSearch-Search-Icon"></span><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key">K</kbd></span></button></div><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-6aa21345 data-v-dc692963><span id="main-nav-aria-label" class="visually-hidden" data-v-dc692963> Main Navigation </span><!--[--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>首页</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/coa6/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>计组6件套</span><!--]--></a><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-dc692963 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-b6c34ac9><span class="text" data-v-b6c34ac9><!----><span data-v-b6c34ac9>编程语言</span><span class="vpi-chevron-down text-icon" data-v-b6c34ac9></span></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><div class="items" data-v-b98bc113><!--[--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link" href="/c/notes/" data-v-43f1e123><!--[-->c/c++<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/web-design/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->前端<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/java/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Java<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/big-data/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->大数据<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/linux/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->云原生<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/go/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Go<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/python/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Python<!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/db/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>数据库</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/open-software/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>开源软件</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink active" href="/c/notes/about/" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>关于我</span><!--]--></a><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-6aa21345 data-v-6c893767><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-6c893767 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-6aa21345 data-v-0394ad82 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-6aa21345 data-v-bb2aa2f0 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-b6c34ac9><span class="vpi-more-horizontal icon" data-v-b6c34ac9></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><!----><!--[--><!--[--><!----><div class="group" data-v-bb2aa2f0><div class="item appearance" data-v-bb2aa2f0><p class="label" data-v-bb2aa2f0>深浅模式</p><div class="appearance-action" data-v-bb2aa2f0><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-bb2aa2f0 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div></div></div><div class="group" data-v-bb2aa2f0><div class="item social-links" data-v-bb2aa2f0><div class="VPSocialLinks social-links-list" data-v-bb2aa2f0 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div></div></div><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-6aa21345 data-v-e5dd9c1c><span class="container" data-v-e5dd9c1c><span class="top" data-v-e5dd9c1c></span><span class="middle" data-v-e5dd9c1c></span><span class="bottom" data-v-e5dd9c1c></span></span></button></div></div></div></div><div class="divider" data-v-6aa21345><div class="divider-line" data-v-6aa21345></div></div></div><!----></header><div class="VPLocalNav has-sidebar empty" data-v-5d98c3a5 data-v-a6f0e41e><div class="container" data-v-a6f0e41e><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-a6f0e41e><span class="vpi-align-left menu-icon" data-v-a6f0e41e></span><span class="menu-text" data-v-a6f0e41e>Menu</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-a6f0e41e data-v-17a5e62e><button data-v-17a5e62e>返回顶部</button><!----></div></div></div><aside class="VPSidebar" data-v-5d98c3a5 data-v-319d5ca6><div class="curtain" data-v-319d5ca6></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-319d5ca6><span class="visually-hidden" id="sidebar-aria-label" data-v-319d5ca6> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/00_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编程基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C 语言入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和进制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数据类型和运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>预处理器</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>内存管理</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-basic/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>调试工具和调试技巧gdb和make</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>常用库函数</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言高级</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和内存分布</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针强化</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>结构体和文件的高级用法</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>链表和回调函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编译过程和面向接口</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>项目构建工具</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>meson</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>meson 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Cmake</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Cmake 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_${commonDirectoryName}/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Conan </p><!--]--></a><!----></div><!----></div><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Gradle</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Gradle 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>Linux</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/04_linux/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Linux 初识和安装</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C++ 基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量、数据类型、运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>类和对象</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 引用</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>继承和派生</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 多态和虚函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/12_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>运算符重载</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>模板</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/14_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 异常</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/15_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>面向对象进阶</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/16_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作和 IO 流</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/17_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>STL标准模板库</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>C++ 高级</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>QT 桌面开发</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>Linux 高并发服务器开发</p><!----></div><!----></div></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-5d98c3a5 data-v-1428d186><div class="VPDoc has-sidebar has-aside" data-v-1428d186 data-v-39a288b8><!--[--><!--]--><div class="container" data-v-39a288b8><div class="aside" data-v-39a288b8><div class="aside-curtain" data-v-39a288b8></div><div class="aside-container" data-v-39a288b8><div class="aside-content" data-v-39a288b8><div class="VPDocAside" data-v-39a288b8 data-v-3f215769><!--[--><!--]--><!--[--><!--]--><nav aria-labelledby="doc-outline-aria-label" class="VPDocAsideOutline" data-v-3f215769 data-v-a5bbad30><div class="content" data-v-a5bbad30><div class="outline-marker" data-v-a5bbad30></div><div aria-level="2" class="outline-title" id="doc-outline-aria-label" role="heading" data-v-a5bbad30>目录</div><ul class="VPDocOutlineItem root" data-v-a5bbad30 data-v-b933a997><!--[--><!--]--></ul></div></nav><!--[--><!--]--><div class="spacer" data-v-3f215769></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-39a288b8><div class="content-container" data-v-39a288b8><!--[--><!--]--><main class="main" data-v-39a288b8><div style="position:relative;" class="vp-doc _c_notes_about_" data-v-39a288b8><div><h3 id="后端技术栈" tabindex="-1">后端技术栈 <a class="header-anchor" href="#后端技术栈" aria-label="Permalink to &quot;后端技术栈&quot;"></a></h3><p><img src="https://img.shields.io/badge/-Spring-6DB33F?logo=Spring&amp;logoColor=FFF" alt="Spring" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Spring%20Boot-6DB33F?logo=Spring-Boot&amp;logoColor=FFF" alt="Spring Boot" style="display:inline-block;">  <img src="https://img.shields.io/badge/-MySQL-4479A1?logo=MySQL&amp;logoColor=FFF" alt="MySQL" style="display:inline-block;">  <img src="https://img.shields.io/badge/-MariaDB-A9A9A9?logo=MariaDB&amp;logoColor=003545" alt="MariaDB" style="display:inline-block;">  <img src="https://img.shields.io/badge/-PostgreSQL-C0C0C0?logo=PostgreSQL&amp;logoColor=4169E1" alt="PostgreSQL" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Oracle-C0C0C0?logo=Oracle&amp;logoColor=F80000" alt="Oracle" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Microsoft%20SQL%20Server-D3D3D3?logo=Microsoft-SQL-Server&amp;logoColor=CC2927" alt="Microsoft SQL Server" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Redis-DC382D?logo=Redis&amp;logoColor=FFF" alt="Redis" style="display:inline-block;">  <img src="https://img.shields.io/badge/-MongoDB-47A248?logo=MongoDB&amp;logoColor=FFF" alt="MongoDB" style="display:inline-block;">  <img src="https://img.shields.io/badge/-RabbitMQ-FF6600?logo=RabbitMQ&amp;logoColor=FFF" alt="RabbitMQ" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Solr-D9411E?logo=Apache-Solr&amp;logoColor=FFF" alt="Solr" style="display:inline-block;">  <img src="https://img.shields.io/badge/-ElasticSearch-005571?logo=ElasticSearch&amp;logoColor=FFF" alt="ElasticSearch" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Logstash-A9A9A9?logo=Logstash&amp;logoColor=005571" alt="Logstash" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Kibana-A9A9A9?logo=Kibana&amp;logoColor=005571" alt="Kibana" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Kafka-C0C0C0?logo=Apache-Kafka&amp;logoColor=231F20" alt="Kafka" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Consul-F24C53?logo=Consul&amp;logoColor=FFF" alt="Consul" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Tomcat-F8DC75?logo=Apache-Tomcat&amp;logoColor=000" alt="Tomcat" style="display:inline-block;">  <img src="https://img.shields.io/badge/-JUnit5-25A162?logo=JUnit5&amp;logoColor=FFF" alt="JUnit5" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Liquibase-2962FF?logo=Liquibase&amp;logoColor=FFF" alt="Liquibase" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Maven-C71A36?logo=Apache-Maven&amp;logoColor=FFF" alt="Maven" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Gradle-D3D3D3?logo=Gradle&amp;logoColor=02303A" alt="Gradle" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Spring%20Security-6DB33F?logo=Spring-Security&amp;logoColor=FFF" alt="Spring Security" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Hibernate-59666C?logo=Hibernate&amp;logoColor=FFF" alt="Hibernate" style="display:inline-block;">  <img src="https://img.shields.io/badge/-JSON-000?logo=JSON&amp;logoColor=FFF" alt="JSON" style="display:inline-block;">  <img src="https://img.shields.io/badge/-JWT-000?logo=JSON-Web-Tokens&amp;logoColor=FFF" alt="JWT" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Java-F78C40?logo=OpenJDK&amp;logoColor=FFF" alt="Java" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Python-A9A9A9?logo=Python&amp;logoColor=3776AB" alt="Python" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Android-C0C0C0?logo=Android&amp;logoColor=3DDC84" alt="Android" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Go-DCDCDC?logo=Go&amp;logoColor=00ADD8" alt="Go" style="display:inline-block;">  <img src="https://img.shields.io/badge/-GraphQL-FFF?logo=GraphQL&amp;logoColor=E10098" alt="GraphQL" style="display:inline-block;">  </p><h3 id="前端技术栈" tabindex="-1">前端技术栈 <a class="header-anchor" href="#前端技术栈" aria-label="Permalink to &quot;前端技术栈&quot;"></a></h3><p><img src="https://img.shields.io/badge/-Vue3-C0C0C0?logo=Vue.js&amp;logoColor=4FC08D" alt="Vue3" style="display:inline-block;">  <img src="https://img.shields.io/badge/-TypeScript-C0C0C0?logo=TypeScript&amp;logoColor=3178C6" alt="TypeScript" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Ant%20Design-C0C0C0?logo=Ant-Design&amp;logoColor=0170FE" alt="Ant Design" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Node.js-D3D3D3?logo=Node.js&amp;logoColor=339933" alt="Node.js" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Vite-D3D3D3?logo=Vite&amp;logoColor=646CFF" alt="Vite" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Webpack-D3D3D3?logo=Webpack&amp;logoColor=8DD6F9" alt="Webpack" style="display:inline-block;">  <img src="https://img.shields.io/badge/-NPM-C0C0C0?logo=npm&amp;logoColor=CB3837" alt="NPM" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Axios-C0C0C0?logo=Axios&amp;logoColor=5A29E4" alt="Axios" style="display:inline-block;">  <img src="https://img.shields.io/badge/-ESLint-C0C0C0?logo=ESLint&amp;logoColor=4B32C3" alt="ESLint" style="display:inline-block;">  <img src="https://img.shields.io/badge/-jQuery-0769AD?logo=jQuery&amp;logoColor=FFF" alt="jQuery" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Bootstrap-7952B3?logo=Bootstrap&amp;logoColor=FFF" alt="BootStrap" style="display:inline-block;">  <img src="https://img.shields.io/badge/-ECharts-C0C0C0?logo=Apache-ECharts&amp;logoColor=AA344D" alt="ECharts" style="display:inline-block;">  <img src="https://img.shields.io/badge/-JavaScript-A9A9A9?logo=JavaScript&amp;logoColor=F7DF1E" alt="JavaScript" style="display:inline-block;">  <img src="https://img.shields.io/badge/-HTML5-A9A9A9?logo=HTML5&amp;logoColor=E34F26" alt="HTML5" style="display:inline-block;">  <img src="https://img.shields.io/badge/-CSS3-A9A9A9?logo=CSS3&amp;logoColor=1572B6" alt="CSS3" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Tailwind%20CSS-FFF?logo=Tailwind-CSS&amp;logoColor=06B6D4" alt="Tailwind CSS" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Less-D3D3D3?logo=Less&amp;logoColor=1D365D" alt="Less" style="display:inline-block;">  </p><h3 id="devops" tabindex="-1">DevOps <a class="header-anchor" href="#devops" aria-label="Permalink to &quot;DevOps&quot;"></a></h3><p><img src="https://img.shields.io/badge/-Git-F05032?logo=Git&amp;logoColor=FFF" alt="Git" style="display:inline-block;">  <img src="https://img.shields.io/badge/-GitHub-181717?logo=GitHub&amp;logoColor=FFF" alt="GitHub" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Gitee-C71D23?logo=Gitee&amp;logoColor=FFF" alt="Gitee" style="display:inline-block;">  <img src="https://img.shields.io/badge/-GitLab-FC6D26?logo=GitLab&amp;logoColor=FFF" alt="gitlab" style="display:inline-block;">  <img src="https://img.shields.io/badge/-GitHub%20Actions-2088FF?logo=GitHub-Actions&amp;logoColor=FFF" alt="GitHub Actions" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Jenkins-D24939?logo=Jenkins&amp;logoColor=000" alt="Jenkins" style="display:inline-block;">  <img src="https://img.shields.io/badge/-SonarQube-A9A9A9?logo=SonarQube&amp;logoColor=4E9BCD" alt="SonarQube" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Docker-2496ED?logo=Docker&amp;logoColor=FFF" alt="Docker" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Harbor-FFF?logo=Harbor&amp;logoColor=60B932" alt="Harbor" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Kubernetes-326CE5?logo=Kubernetes&amp;logoColor=FFF" alt="Kubernetes" style="display:inline-block;">  <img src="https://img.shields.io/badge/-CentOS-262577?logo=CentOS&amp;logoColor=FFF" alt="CentOS" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Ubuntu-E95420?logo=Ubuntu&amp;logoColor=FFF" alt="Ubuntu" style="display:inline-block;">  </p><h3 id="运维技术栈" tabindex="-1">运维技术栈 <a class="header-anchor" href="#运维技术栈" aria-label="Permalink to &quot;运维技术栈&quot;"></a></h3><p><img src="https://img.shields.io/badge/-阿里云-FF6A00?logo=Alibaba-Cloud&amp;logoColor=FFF" alt="阿里云" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Nginx-009639?logo=Nginx&amp;logoColor=FFF" alt="Nginx" style="display:inline-block;">  <img src="https://img.shields.io/badge/-VMware-607078?logo=VMware&amp;logoColor=FFF" alt="VMware" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Prometheus-C0C0C0?logo=Prometheus&amp;logoColor=E6522C" alt="Prometheus" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Grafana-DCDCDC?logo=Grafana&amp;logoColor=F46800" alt="Grafana" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Ansible-FFF?logo=Ansible&amp;logoColor=EE0000" alt="Ansible" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Lua-FFF?&amp;logo=Lua&amp;logoColor=2C2D72" alt="Lua" style="display:inline-block;">  </p><h3 id="测试技术栈" tabindex="-1">测试技术栈 <a class="header-anchor" href="#测试技术栈" aria-label="Permalink to &quot;测试技术栈&quot;"></a></h3><p><img src="https://img.shields.io/badge/-Postman-FF6C37?logo=Postman&amp;logoColor=FFF" alt="Postman" style="display:inline-block;">  <img src="https://img.shields.io/badge/-JMeter-D3D3D3?logo=Apache-JMeter&amp;logoColor=D22128" alt="JMeter" style="display:inline-block;">  </p><h3 id="开发工具" tabindex="-1">开发工具 <a class="header-anchor" href="#开发工具" aria-label="Permalink to &quot;开发工具&quot;"></a></h3><p><img src="https://img.shields.io/badge/-Intellij%20IDEA-000?logo=Intellij-IDEA&amp;logoColor=FFF" alt="Intellij IDEA" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Eclipse-2C2255?logo=Eclipse&amp;logoColor=FFF" alt="Eclipse" style="display:inline-block;">  <img src="https://img.shields.io/badge/-WebStorm-000?logo=WebStorm&amp;logoColor=FFF" alt="WebStorm" style="display:inline-block;">  <img src="https://img.shields.io/badge/-PyCharm-C0C0C0?logo=PyCharm&amp;logoColor=000" alt="PyCharm" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Android%20Studio-C0C0C0?logo=Android-Studio&amp;logoColor=3DDC84" alt="Android Studio" style="display:inline-block;">  <img src="https://img.shields.io/badge/-VSCode-C0C0C0?logo=Visual-Studio-Code&amp;logoColor=007ACC" alt="VSCode" style="display:inline-block;">  </p><h3 id="其他" tabindex="-1">其他 <a class="header-anchor" href="#其他" aria-label="Permalink to &quot;其他&quot;"></a></h3><p><img src="https://img.shields.io/badge/-Markdown-000?logo=Markdown&amp;logoColor=FFF" alt="Markdown" style="display:inline-block;">  <img src="https://img.shields.io/badge/-WordPress-21759B?logo=WordPress&amp;logoColor=FFF" alt="WordPress" style="display:inline-block;">  <img src="https://img.shields.io/badge/-GitHub%20Pages-222?logo=GitHub-Pages&amp;logoColor=FFF" alt="GitHub Pages" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Adobe%20Photoshop-A9A9A9?logo=Adobe-Photoshop&amp;logoColor=31A8FF" alt="Adobe Photoshop" style="display:inline-block;">  </p></div></div></main><footer class="VPDocFooter" data-v-39a288b8 data-v-e257564d><!--[--><!--]--><div class="edit-info" data-v-e257564d><!----><div class="last-updated" data-v-e257564d><p class="VPLastUpdated" data-v-e257564d data-v-e98dd255>上次更新: <time datetime="2024-08-16T02:24:26.000Z" data-v-e98dd255></time></p></div></div><nav class="prev-next" aria-labelledby="doc-footer-aria-label" data-v-e257564d><span class="visually-hidden" id="doc-footer-aria-label" data-v-e257564d>Pager</span><div class="pager" data-v-e257564d><!----></div><div class="pager" data-v-e257564d><a class="VPLink link pager-link next" href="/c/notes/01_c-basic/00_xdx/" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>下一篇</span><span class="title" data-v-e257564d>编程基础</span><!--]--></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><footer class="VPFooter has-sidebar" data-v-5d98c3a5 data-v-e315a0ad><div class="container" data-v-e315a0ad><p class="message" data-v-e315a0ad>Released under the MIT License.</p><p class="copyright" data-v-e315a0ad>Copyright © 2024 许大仙</p></div></footer><!--[--><!--]--></div></div>
<script>window.__VP_HASH_MAP__=JSON.parse("{\"index.md\":\"Dga0tMF5\",\"notes_01_c-basic_00_xdx_index.md\":\"BRC7slaL\",\"notes_01_c-basic_01_xdx_index.md\":\"DvCUr2L0\",\"notes_01_c-basic_02_xdx_index.md\":\"CC2Mg9VD\",\"notes_01_c-basic_03_xdx_index.md\":\"CcATnhKW\",\"notes_01_c-basic_04_xdx_index.md\":\"DABEMZSO\",\"notes_01_c-basic_05_xdx_index.md\":\"CGbN5wss\",\"notes_01_c-basic_06_xdx_index.md\":\"CIGNaKYV\",\"notes_04_linux_01_xdx_index.md\":\"C9IatKsj\",\"notes_about_index.md\":\"DLuQgC_8\",\"notes_index.md\":\"CeV-uJ5V\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"zh-CN\",\"dir\":\"ltr\",\"title\":\"许大仙\",\"titleTemplate\":\"Hi终于等到你\",\"description\":\"许大仙前端、Java、大数据、云原生\",\"base\":\"/c/\",\"head\":[],\"router\":{\"prefetchLinks\":true},\"appearance\":true,\"themeConfig\":{\"lastUpdatedText\":\"上次更新\",\"returnToTopLabel\":\"返回顶部\",\"search\":{\"provider\":\"local\"},\"logo\":\"/logo.svg\",\"nav\":[{\"text\":\"首页\",\"link\":\"https://aexiar.github.io/\"},{\"text\":\"计组6件套\",\"link\":\"https://aexiar.github.io/coa6/notes/\"},{\"text\":\"编程语言\",\"items\":[{\"text\":\"c/c++\",\"link\":\"/notes/\"},{\"text\":\"前端\",\"link\":\"https://aexiar.github.io/web-design/notes/\"},{\"text\":\"Java\",\"link\":\"https://aexiar.github.io/java/notes/\"},{\"text\":\"大数据\",\"link\":\"https://aexiar.github.io/big-data/notes/\"},{\"text\":\"云原生\",\"link\":\"https://aexiar.github.io/linux/notes/\"},{\"text\":\"Go\",\"link\":\"https://aexiar.github.io/go/notes/\"},{\"text\":\"Python\",\"link\":\"https://aexiar.github.io/python/notes/\"}]},{\"text\":\"数据库\",\"link\":\"https://aexiar.github.io/db/notes/\"},{\"text\":\"开源软件\",\"link\":\"https://aexiar.github.io/open-software/notes/\"},{\"text\":\"关于我\",\"link\":\"/notes/about/\"}],\"sidebar\":{\"/notes/\":[{\"text\":\"C 语言基础\",\"collapsed\":true,\"items\":[{\"text\":\"编程基础\",\"link\":\"/notes/01_c-basic/00_xdx/\"},{\"text\":\"C 语言入门\",\"link\":\"/notes/01_c-basic/01_xdx/\"},{\"text\":\"变量和进制\",\"link\":\"/notes/01_c-basic/02_xdx/\"},{\"text\":\"数据类型和运算符\",\"link\":\"/notes/01_c-basic/03_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/01_c-basic/04_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/01_c-basic/05_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/01_c-basic/06_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/01_c-basic/07_xdx/\"},{\"text\":\"预处理器\",\"link\":\"/notes/01_c-basic/08_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/01_c-basic/09_xdx/\"},{\"text\":\"内存管理\",\"link\":\"/notes/01_c-basic/10_xdx/\"},{\"text\":\"文件操作\",\"link\":\"/notes/01_c-basic/11_xdx/\"},{\"text\":\"调试工具和调试技巧gdb和make\",\"link\":\"/notes/02_c-basic/13_xdx/\"},{\"text\":\"常用库函数\",\"link\":\"/notes/01_c-basic/13_xdx/\"}]},{\"text\":\"C 语言高级\",\"collapsed\":true,\"items\":[{\"text\":\"变量和内存分布\",\"link\":\"/notes/02_c-advance/01_xdx/\"},{\"text\":\"指针强化\",\"link\":\"/notes/02_c-advance/02_xdx/\"},{\"text\":\"结构体和文件的高级用法\",\"link\":\"/notes/02_c-advance/03_xdx/\"},{\"text\":\"链表和回调函数\",\"link\":\"/notes/02_c-advance/04_xdx/\"},{\"text\":\"编译过程和面向接口\",\"link\":\"/notes/02_c-advance/05_xdx/\"}]},{\"text\":\"项目构建工具\",\"collapsed\":true,\"items\":[{\"text\":\"meson\",\"collapsed\":true,\"items\":[{\"text\":\"meson 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Cmake\",\"collapsed\":true,\"items\":[{\"text\":\"Cmake 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Conan \",\"link\":\"/notes/03_build/01_${commonDirectoryName}/\"},{\"text\":\"Gradle\",\"collapsed\":true,\"items\":[{\"text\":\"Gradle 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]}]},{\"text\":\"Linux\",\"collapsed\":true,\"items\":[{\"text\":\"Linux 初识和安装\",\"link\":\"/notes/04_linux/01_xdx/\"}]},{\"text\":\"C++ 基础\",\"collapsed\":true,\"items\":[{\"text\":\"C++ 入门\",\"link\":\"/notes/05_cpp/01_xdx/\"},{\"text\":\"变量、数据类型、运算符\",\"link\":\"/notes/05_cpp/02_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/05_cpp/03_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/05_cpp/04_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/05_cpp/05_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/05_cpp/06_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/05_cpp/07_xdx/\"},{\"text\":\"类和对象\",\"link\":\"/notes/05_cpp/08_xdx/\"},{\"text\":\"C++ 引用\",\"link\":\"/notes/05_cpp/09_xdx/\"},{\"text\":\"继承和派生\",\"link\":\"/notes/05_cpp/10_xdx/\"},{\"text\":\"C++ 多态和虚函数\",\"link\":\"/notes/05_cpp/11_xdx/\"},{\"text\":\"运算符重载\",\"link\":\"/notes/05_cpp/12_xdx/\"},{\"text\":\"模板\",\"link\":\"/notes/05_cpp/13_xdx/\"},{\"text\":\"C++ 异常\",\"link\":\"/notes/05_cpp/14_xdx/\"},{\"text\":\"面向对象进阶\",\"link\":\"/notes/05_cpp/15_xdx/\"},{\"text\":\"文件操作和 IO 流\",\"link\":\"/notes/05_cpp/16_xdx/\"},{\"text\":\"STL标准模板库\",\"link\":\"/notes/05_cpp/17_xdx/\"}]},{\"text\":\"C++ 高级\",\"collapsed\":true,\"items\":[]},{\"text\":\"QT 桌面开发\",\"collapsed\":true,\"items\":[]},{\"text\":\"Linux 高并发服务器开发\",\"collapsed\":true,\"items\":[]}]},\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/Aurorxa\"}],\"docFooter\":{\"prev\":\"上一篇\",\"next\":\"下一篇\"},\"darkModeSwitchLabel\":\"深浅模式\",\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2024 许大仙\"},\"outline\":{\"level\":[1,6],\"label\":\"目录\"},\"outlineTitle\":\"当前页大纲\"},\"locales\":{},\"scrollOffset\":134,\"cleanUrls\":false}");</script>
<div id="app"><div class="Layout" data-v-5d98c3a5><!--[--><!--]--><!--[--><span tabindex="-1" data-v-0f60ec36></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-0f60ec36> Skip to content </a><!--]--><!----><header class="VPNav" data-v-5d98c3a5 data-v-ae24b3ad><div class="VPNavBar has-sidebar top" data-v-ae24b3ad data-v-6aa21345><div class="wrapper" data-v-6aa21345><div class="container" data-v-6aa21345><div class="title" data-v-6aa21345><div class="VPNavBarTitle has-sidebar" data-v-6aa21345 data-v-ab179fa1><a class="title" href="/c/" data-v-ab179fa1><!--[--><!--]--><!--[--><img class="VPImage logo" src="/c/logo.svg" alt data-v-8426fc1a><!--]--><span data-v-ab179fa1>许大仙</span><!--[--><!--]--></a></div></div><div class="content" data-v-6aa21345><div class="content-body" data-v-6aa21345><!--[--><!--]--><div class="VPNavBarSearch search" data-v-6aa21345><!--[--><!----><div id="local-search"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><span class="vp-icon DocSearch-Search-Icon"></span><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key">K</kbd></span></button></div><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-6aa21345 data-v-dc692963><span id="main-nav-aria-label" class="visually-hidden" data-v-dc692963> Main Navigation </span><!--[--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>首页</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/coa6/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>计组6件套</span><!--]--></a><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-dc692963 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-b6c34ac9><span class="text" data-v-b6c34ac9><!----><span data-v-b6c34ac9>编程语言</span><span class="vpi-chevron-down text-icon" data-v-b6c34ac9></span></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><div class="items" data-v-b98bc113><!--[--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link" href="/c/notes/" data-v-43f1e123><!--[-->c/c++<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/web-design/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->前端<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/java/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Java<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/big-data/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->大数据<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/linux/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->云原生<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/go/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Go<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/python/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Python<!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/db/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>数据库</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/open-software/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>开源软件</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink active" href="/c/notes/about/" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>关于我</span><!--]--></a><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-6aa21345 data-v-6c893767><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-6c893767 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-6aa21345 data-v-0394ad82 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-6aa21345 data-v-bb2aa2f0 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-b6c34ac9><span class="vpi-more-horizontal icon" data-v-b6c34ac9></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><!----><!--[--><!--[--><!----><div class="group" data-v-bb2aa2f0><div class="item appearance" data-v-bb2aa2f0><p class="label" data-v-bb2aa2f0>深浅模式</p><div class="appearance-action" data-v-bb2aa2f0><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-bb2aa2f0 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div></div></div><div class="group" data-v-bb2aa2f0><div class="item social-links" data-v-bb2aa2f0><div class="VPSocialLinks social-links-list" data-v-bb2aa2f0 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div></div></div><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-6aa21345 data-v-e5dd9c1c><span class="container" data-v-e5dd9c1c><span class="top" data-v-e5dd9c1c></span><span class="middle" data-v-e5dd9c1c></span><span class="bottom" data-v-e5dd9c1c></span></span></button></div></div></div></div><div class="divider" data-v-6aa21345><div class="divider-line" data-v-6aa21345></div></div></div><!----></header><div class="VPLocalNav has-sidebar empty" data-v-5d98c3a5 data-v-a6f0e41e><div class="container" data-v-a6f0e41e><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-a6f0e41e><span class="vpi-align-left menu-icon" data-v-a6f0e41e></span><span class="menu-text" data-v-a6f0e41e>Menu</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-a6f0e41e data-v-17a5e62e><button data-v-17a5e62e>返回顶部</button><!----></div></div></div><aside class="VPSidebar" data-v-5d98c3a5 data-v-319d5ca6><div class="curtain" data-v-319d5ca6></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-319d5ca6><span class="visually-hidden" id="sidebar-aria-label" data-v-319d5ca6> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/00_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编程基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C 语言入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和进制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数据类型和运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>大话小数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>预处理器</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>内存管理</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/12_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-basic/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>调试工具和调试技巧gdb和make</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/14_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>常用库函数</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言高级</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和内存分布</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针强化</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>结构体和文件的高级用法</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>链表和回调函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编译过程和面向接口</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>项目构建工具</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>meson</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>meson 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Cmake</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Cmake 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_${commonDirectoryName}/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Conan </p><!--]--></a><!----></div><!----></div><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Gradle</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Gradle 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>Linux</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/04_linux/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Linux 初识和安装</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C++ 基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量、数据类型、运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>类和对象</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 引用</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>继承和派生</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 多态和虚函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/12_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>运算符重载</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>模板</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/14_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 异常</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/15_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>面向对象进阶</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/16_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作和 IO 流</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/17_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>STL标准模板库</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>C++ 高级</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>QT 桌面开发</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>Linux 高并发服务器开发</p><!----></div><!----></div></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-5d98c3a5 data-v-1428d186><div class="VPDoc has-sidebar has-aside" data-v-1428d186 data-v-39a288b8><!--[--><!--]--><div class="container" data-v-39a288b8><div class="aside" data-v-39a288b8><div class="aside-curtain" data-v-39a288b8></div><div class="aside-container" data-v-39a288b8><div class="aside-content" data-v-39a288b8><div class="VPDocAside" data-v-39a288b8 data-v-3f215769><!--[--><!--]--><!--[--><!--]--><nav aria-labelledby="doc-outline-aria-label" class="VPDocAsideOutline" data-v-3f215769 data-v-a5bbad30><div class="content" data-v-a5bbad30><div class="outline-marker" data-v-a5bbad30></div><div aria-level="2" class="outline-title" id="doc-outline-aria-label" role="heading" data-v-a5bbad30>目录</div><ul class="VPDocOutlineItem root" data-v-a5bbad30 data-v-b933a997><!--[--><!--]--></ul></div></nav><!--[--><!--]--><div class="spacer" data-v-3f215769></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-39a288b8><div class="content-container" data-v-39a288b8><!--[--><!--]--><main class="main" data-v-39a288b8><div style="position:relative;" class="vp-doc _c_notes_about_" data-v-39a288b8><div><h3 id="后端技术栈" tabindex="-1">后端技术栈 <a class="header-anchor" href="#后端技术栈" aria-label="Permalink to &quot;后端技术栈&quot;"></a></h3><p><img src="https://img.shields.io/badge/-Spring-6DB33F?logo=Spring&amp;logoColor=FFF" alt="Spring" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Spring%20Boot-6DB33F?logo=Spring-Boot&amp;logoColor=FFF" alt="Spring Boot" style="display:inline-block;">  <img src="https://img.shields.io/badge/-MySQL-4479A1?logo=MySQL&amp;logoColor=FFF" alt="MySQL" style="display:inline-block;">  <img src="https://img.shields.io/badge/-MariaDB-A9A9A9?logo=MariaDB&amp;logoColor=003545" alt="MariaDB" style="display:inline-block;">  <img src="https://img.shields.io/badge/-PostgreSQL-C0C0C0?logo=PostgreSQL&amp;logoColor=4169E1" alt="PostgreSQL" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Oracle-C0C0C0?logo=Oracle&amp;logoColor=F80000" alt="Oracle" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Microsoft%20SQL%20Server-D3D3D3?logo=Microsoft-SQL-Server&amp;logoColor=CC2927" alt="Microsoft SQL Server" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Redis-DC382D?logo=Redis&amp;logoColor=FFF" alt="Redis" style="display:inline-block;">  <img src="https://img.shields.io/badge/-MongoDB-47A248?logo=MongoDB&amp;logoColor=FFF" alt="MongoDB" style="display:inline-block;">  <img src="https://img.shields.io/badge/-RabbitMQ-FF6600?logo=RabbitMQ&amp;logoColor=FFF" alt="RabbitMQ" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Solr-D9411E?logo=Apache-Solr&amp;logoColor=FFF" alt="Solr" style="display:inline-block;">  <img src="https://img.shields.io/badge/-ElasticSearch-005571?logo=ElasticSearch&amp;logoColor=FFF" alt="ElasticSearch" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Logstash-A9A9A9?logo=Logstash&amp;logoColor=005571" alt="Logstash" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Kibana-A9A9A9?logo=Kibana&amp;logoColor=005571" alt="Kibana" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Kafka-C0C0C0?logo=Apache-Kafka&amp;logoColor=231F20" alt="Kafka" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Consul-F24C53?logo=Consul&amp;logoColor=FFF" alt="Consul" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Tomcat-F8DC75?logo=Apache-Tomcat&amp;logoColor=000" alt="Tomcat" style="display:inline-block;">  <img src="https://img.shields.io/badge/-JUnit5-25A162?logo=JUnit5&amp;logoColor=FFF" alt="JUnit5" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Liquibase-2962FF?logo=Liquibase&amp;logoColor=FFF" alt="Liquibase" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Maven-C71A36?logo=Apache-Maven&amp;logoColor=FFF" alt="Maven" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Gradle-D3D3D3?logo=Gradle&amp;logoColor=02303A" alt="Gradle" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Spring%20Security-6DB33F?logo=Spring-Security&amp;logoColor=FFF" alt="Spring Security" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Hibernate-59666C?logo=Hibernate&amp;logoColor=FFF" alt="Hibernate" style="display:inline-block;">  <img src="https://img.shields.io/badge/-JSON-000?logo=JSON&amp;logoColor=FFF" alt="JSON" style="display:inline-block;">  <img src="https://img.shields.io/badge/-JWT-000?logo=JSON-Web-Tokens&amp;logoColor=FFF" alt="JWT" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Java-F78C40?logo=OpenJDK&amp;logoColor=FFF" alt="Java" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Python-A9A9A9?logo=Python&amp;logoColor=3776AB" alt="Python" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Android-C0C0C0?logo=Android&amp;logoColor=3DDC84" alt="Android" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Go-DCDCDC?logo=Go&amp;logoColor=00ADD8" alt="Go" style="display:inline-block;">  <img src="https://img.shields.io/badge/-GraphQL-FFF?logo=GraphQL&amp;logoColor=E10098" alt="GraphQL" style="display:inline-block;">  </p><h3 id="前端技术栈" tabindex="-1">前端技术栈 <a class="header-anchor" href="#前端技术栈" aria-label="Permalink to &quot;前端技术栈&quot;"></a></h3><p><img src="https://img.shields.io/badge/-Vue3-C0C0C0?logo=Vue.js&amp;logoColor=4FC08D" alt="Vue3" style="display:inline-block;">  <img src="https://img.shields.io/badge/-TypeScript-C0C0C0?logo=TypeScript&amp;logoColor=3178C6" alt="TypeScript" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Ant%20Design-C0C0C0?logo=Ant-Design&amp;logoColor=0170FE" alt="Ant Design" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Node.js-D3D3D3?logo=Node.js&amp;logoColor=339933" alt="Node.js" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Vite-D3D3D3?logo=Vite&amp;logoColor=646CFF" alt="Vite" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Webpack-D3D3D3?logo=Webpack&amp;logoColor=8DD6F9" alt="Webpack" style="display:inline-block;">  <img src="https://img.shields.io/badge/-NPM-C0C0C0?logo=npm&amp;logoColor=CB3837" alt="NPM" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Axios-C0C0C0?logo=Axios&amp;logoColor=5A29E4" alt="Axios" style="display:inline-block;">  <img src="https://img.shields.io/badge/-ESLint-C0C0C0?logo=ESLint&amp;logoColor=4B32C3" alt="ESLint" style="display:inline-block;">  <img src="https://img.shields.io/badge/-jQuery-0769AD?logo=jQuery&amp;logoColor=FFF" alt="jQuery" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Bootstrap-7952B3?logo=Bootstrap&amp;logoColor=FFF" alt="BootStrap" style="display:inline-block;">  <img src="https://img.shields.io/badge/-ECharts-C0C0C0?logo=Apache-ECharts&amp;logoColor=AA344D" alt="ECharts" style="display:inline-block;">  <img src="https://img.shields.io/badge/-JavaScript-A9A9A9?logo=JavaScript&amp;logoColor=F7DF1E" alt="JavaScript" style="display:inline-block;">  <img src="https://img.shields.io/badge/-HTML5-A9A9A9?logo=HTML5&amp;logoColor=E34F26" alt="HTML5" style="display:inline-block;">  <img src="https://img.shields.io/badge/-CSS3-A9A9A9?logo=CSS3&amp;logoColor=1572B6" alt="CSS3" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Tailwind%20CSS-FFF?logo=Tailwind-CSS&amp;logoColor=06B6D4" alt="Tailwind CSS" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Less-D3D3D3?logo=Less&amp;logoColor=1D365D" alt="Less" style="display:inline-block;">  </p><h3 id="devops" tabindex="-1">DevOps <a class="header-anchor" href="#devops" aria-label="Permalink to &quot;DevOps&quot;"></a></h3><p><img src="https://img.shields.io/badge/-Git-F05032?logo=Git&amp;logoColor=FFF" alt="Git" style="display:inline-block;">  <img src="https://img.shields.io/badge/-GitHub-181717?logo=GitHub&amp;logoColor=FFF" alt="GitHub" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Gitee-C71D23?logo=Gitee&amp;logoColor=FFF" alt="Gitee" style="display:inline-block;">  <img src="https://img.shields.io/badge/-GitLab-FC6D26?logo=GitLab&amp;logoColor=FFF" alt="gitlab" style="display:inline-block;">  <img src="https://img.shields.io/badge/-GitHub%20Actions-2088FF?logo=GitHub-Actions&amp;logoColor=FFF" alt="GitHub Actions" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Jenkins-D24939?logo=Jenkins&amp;logoColor=000" alt="Jenkins" style="display:inline-block;">  <img src="https://img.shields.io/badge/-SonarQube-A9A9A9?logo=SonarQube&amp;logoColor=4E9BCD" alt="SonarQube" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Docker-2496ED?logo=Docker&amp;logoColor=FFF" alt="Docker" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Harbor-FFF?logo=Harbor&amp;logoColor=60B932" alt="Harbor" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Kubernetes-326CE5?logo=Kubernetes&amp;logoColor=FFF" alt="Kubernetes" style="display:inline-block;">  <img src="https://img.shields.io/badge/-CentOS-262577?logo=CentOS&amp;logoColor=FFF" alt="CentOS" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Ubuntu-E95420?logo=Ubuntu&amp;logoColor=FFF" alt="Ubuntu" style="display:inline-block;">  </p><h3 id="运维技术栈" tabindex="-1">运维技术栈 <a class="header-anchor" href="#运维技术栈" aria-label="Permalink to &quot;运维技术栈&quot;"></a></h3><p><img src="https://img.shields.io/badge/-阿里云-FF6A00?logo=Alibaba-Cloud&amp;logoColor=FFF" alt="阿里云" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Nginx-009639?logo=Nginx&amp;logoColor=FFF" alt="Nginx" style="display:inline-block;">  <img src="https://img.shields.io/badge/-VMware-607078?logo=VMware&amp;logoColor=FFF" alt="VMware" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Prometheus-C0C0C0?logo=Prometheus&amp;logoColor=E6522C" alt="Prometheus" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Grafana-DCDCDC?logo=Grafana&amp;logoColor=F46800" alt="Grafana" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Ansible-FFF?logo=Ansible&amp;logoColor=EE0000" alt="Ansible" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Lua-FFF?&amp;logo=Lua&amp;logoColor=2C2D72" alt="Lua" style="display:inline-block;">  </p><h3 id="测试技术栈" tabindex="-1">测试技术栈 <a class="header-anchor" href="#测试技术栈" aria-label="Permalink to &quot;测试技术栈&quot;"></a></h3><p><img src="https://img.shields.io/badge/-Postman-FF6C37?logo=Postman&amp;logoColor=FFF" alt="Postman" style="display:inline-block;">  <img src="https://img.shields.io/badge/-JMeter-D3D3D3?logo=Apache-JMeter&amp;logoColor=D22128" alt="JMeter" style="display:inline-block;">  </p><h3 id="开发工具" tabindex="-1">开发工具 <a class="header-anchor" href="#开发工具" aria-label="Permalink to &quot;开发工具&quot;"></a></h3><p><img src="https://img.shields.io/badge/-Intellij%20IDEA-000?logo=Intellij-IDEA&amp;logoColor=FFF" alt="Intellij IDEA" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Eclipse-2C2255?logo=Eclipse&amp;logoColor=FFF" alt="Eclipse" style="display:inline-block;">  <img src="https://img.shields.io/badge/-WebStorm-000?logo=WebStorm&amp;logoColor=FFF" alt="WebStorm" style="display:inline-block;">  <img src="https://img.shields.io/badge/-PyCharm-C0C0C0?logo=PyCharm&amp;logoColor=000" alt="PyCharm" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Android%20Studio-C0C0C0?logo=Android-Studio&amp;logoColor=3DDC84" alt="Android Studio" style="display:inline-block;">  <img src="https://img.shields.io/badge/-VSCode-C0C0C0?logo=Visual-Studio-Code&amp;logoColor=007ACC" alt="VSCode" style="display:inline-block;">  </p><h3 id="其他" tabindex="-1">其他 <a class="header-anchor" href="#其他" aria-label="Permalink to &quot;其他&quot;"></a></h3><p><img src="https://img.shields.io/badge/-Markdown-000?logo=Markdown&amp;logoColor=FFF" alt="Markdown" style="display:inline-block;">  <img src="https://img.shields.io/badge/-WordPress-21759B?logo=WordPress&amp;logoColor=FFF" alt="WordPress" style="display:inline-block;">  <img src="https://img.shields.io/badge/-GitHub%20Pages-222?logo=GitHub-Pages&amp;logoColor=FFF" alt="GitHub Pages" style="display:inline-block;">  <img src="https://img.shields.io/badge/-Adobe%20Photoshop-A9A9A9?logo=Adobe-Photoshop&amp;logoColor=31A8FF" alt="Adobe Photoshop" style="display:inline-block;">  </p></div></div></main><footer class="VPDocFooter" data-v-39a288b8 data-v-e257564d><!--[--><!--]--><div class="edit-info" data-v-e257564d><!----><div class="last-updated" data-v-e257564d><p class="VPLastUpdated" data-v-e257564d data-v-e98dd255>上次更新: <time datetime="2024-08-16T02:24:26.000Z" data-v-e98dd255></time></p></div></div><nav class="prev-next" aria-labelledby="doc-footer-aria-label" data-v-e257564d><span class="visually-hidden" id="doc-footer-aria-label" data-v-e257564d>Pager</span><div class="pager" data-v-e257564d><!----></div><div class="pager" data-v-e257564d><a class="VPLink link pager-link next" href="/c/notes/01_c-basic/00_xdx/" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>下一篇</span><span class="title" data-v-e257564d>编程基础</span><!--]--></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><footer class="VPFooter has-sidebar" data-v-5d98c3a5 data-v-e315a0ad><div class="container" data-v-e315a0ad><p class="message" data-v-e315a0ad>Released under the MIT License.</p><p class="copyright" data-v-e315a0ad>Copyright © 2024 许大仙</p></div></footer><!--[--><!--]--></div></div>
<script>window.__VP_HASH_MAP__=JSON.parse("{\"index.md\":\"Dga0tMF5\",\"notes_01_c-basic_00_xdx_index.md\":\"BRC7slaL\",\"notes_01_c-basic_01_xdx_index.md\":\"Fg4OXydV\",\"notes_01_c-basic_02_xdx_index.md\":\"CC2Mg9VD\",\"notes_01_c-basic_03_xdx_index.md\":\"Cw3Z19MO\",\"notes_01_c-basic_04_xdx_index.md\":\"ySxH8sG-\",\"notes_01_c-basic_05_xdx_index.md\":\"DUbOwEts\",\"notes_01_c-basic_06_xdx_index.md\":\"CV_r2WNu\",\"notes_01_c-basic_07_xdx_index.md\":\"CE9q5cmu\",\"notes_04_linux_01_xdx_index.md\":\"C9IatKsj\",\"notes_about_index.md\":\"DLuQgC_8\",\"notes_index.md\":\"CeV-uJ5V\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"zh-CN\",\"dir\":\"ltr\",\"title\":\"许大仙\",\"titleTemplate\":\"Hi终于等到你\",\"description\":\"许大仙前端、Java、大数据、云原生\",\"base\":\"/c/\",\"head\":[],\"router\":{\"prefetchLinks\":true},\"appearance\":true,\"themeConfig\":{\"lastUpdatedText\":\"上次更新\",\"returnToTopLabel\":\"返回顶部\",\"search\":{\"provider\":\"local\"},\"logo\":\"/logo.svg\",\"nav\":[{\"text\":\"首页\",\"link\":\"https://aexiar.github.io/\"},{\"text\":\"计组6件套\",\"link\":\"https://aexiar.github.io/coa6/notes/\"},{\"text\":\"编程语言\",\"items\":[{\"text\":\"c/c++\",\"link\":\"/notes/\"},{\"text\":\"前端\",\"link\":\"https://aexiar.github.io/web-design/notes/\"},{\"text\":\"Java\",\"link\":\"https://aexiar.github.io/java/notes/\"},{\"text\":\"大数据\",\"link\":\"https://aexiar.github.io/big-data/notes/\"},{\"text\":\"云原生\",\"link\":\"https://aexiar.github.io/linux/notes/\"},{\"text\":\"Go\",\"link\":\"https://aexiar.github.io/go/notes/\"},{\"text\":\"Python\",\"link\":\"https://aexiar.github.io/python/notes/\"}]},{\"text\":\"数据库\",\"link\":\"https://aexiar.github.io/db/notes/\"},{\"text\":\"开源软件\",\"link\":\"https://aexiar.github.io/open-software/notes/\"},{\"text\":\"关于我\",\"link\":\"/notes/about/\"}],\"sidebar\":{\"/notes/\":[{\"text\":\"C 语言基础\",\"collapsed\":true,\"items\":[{\"text\":\"编程基础\",\"link\":\"/notes/01_c-basic/00_xdx/\"},{\"text\":\"C 语言入门\",\"link\":\"/notes/01_c-basic/01_xdx/\"},{\"text\":\"变量和进制\",\"link\":\"/notes/01_c-basic/02_xdx/\"},{\"text\":\"数据类型和运算符\",\"link\":\"/notes/01_c-basic/03_xdx/\"},{\"text\":\"大话小数\",\"link\":\"/notes/01_c-basic/04_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/01_c-basic/05_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/01_c-basic/06_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/01_c-basic/07_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/01_c-basic/08_xdx/\"},{\"text\":\"预处理器\",\"link\":\"/notes/01_c-basic/09_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/01_c-basic/10_xdx/\"},{\"text\":\"内存管理\",\"link\":\"/notes/01_c-basic/11_xdx/\"},{\"text\":\"文件操作\",\"link\":\"/notes/01_c-basic/12_xdx/\"},{\"text\":\"调试工具和调试技巧gdb和make\",\"link\":\"/notes/02_c-basic/13_xdx/\"},{\"text\":\"常用库函数\",\"link\":\"/notes/01_c-basic/14_xdx/\"}]},{\"text\":\"C 语言高级\",\"collapsed\":true,\"items\":[{\"text\":\"变量和内存分布\",\"link\":\"/notes/02_c-advance/01_xdx/\"},{\"text\":\"指针强化\",\"link\":\"/notes/02_c-advance/02_xdx/\"},{\"text\":\"结构体和文件的高级用法\",\"link\":\"/notes/02_c-advance/03_xdx/\"},{\"text\":\"链表和回调函数\",\"link\":\"/notes/02_c-advance/04_xdx/\"},{\"text\":\"编译过程和面向接口\",\"link\":\"/notes/02_c-advance/05_xdx/\"}]},{\"text\":\"项目构建工具\",\"collapsed\":true,\"items\":[{\"text\":\"meson\",\"collapsed\":true,\"items\":[{\"text\":\"meson 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Cmake\",\"collapsed\":true,\"items\":[{\"text\":\"Cmake 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Conan \",\"link\":\"/notes/03_build/01_${commonDirectoryName}/\"},{\"text\":\"Gradle\",\"collapsed\":true,\"items\":[{\"text\":\"Gradle 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]}]},{\"text\":\"Linux\",\"collapsed\":true,\"items\":[{\"text\":\"Linux 初识和安装\",\"link\":\"/notes/04_linux/01_xdx/\"}]},{\"text\":\"C++ 基础\",\"collapsed\":true,\"items\":[{\"text\":\"C++ 入门\",\"link\":\"/notes/05_cpp/01_xdx/\"},{\"text\":\"变量、数据类型、运算符\",\"link\":\"/notes/05_cpp/02_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/05_cpp/03_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/05_cpp/04_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/05_cpp/05_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/05_cpp/06_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/05_cpp/07_xdx/\"},{\"text\":\"类和对象\",\"link\":\"/notes/05_cpp/08_xdx/\"},{\"text\":\"C++ 引用\",\"link\":\"/notes/05_cpp/09_xdx/\"},{\"text\":\"继承和派生\",\"link\":\"/notes/05_cpp/10_xdx/\"},{\"text\":\"C++ 多态和虚函数\",\"link\":\"/notes/05_cpp/11_xdx/\"},{\"text\":\"运算符重载\",\"link\":\"/notes/05_cpp/12_xdx/\"},{\"text\":\"模板\",\"link\":\"/notes/05_cpp/13_xdx/\"},{\"text\":\"C++ 异常\",\"link\":\"/notes/05_cpp/14_xdx/\"},{\"text\":\"面向对象进阶\",\"link\":\"/notes/05_cpp/15_xdx/\"},{\"text\":\"文件操作和 IO 流\",\"link\":\"/notes/05_cpp/16_xdx/\"},{\"text\":\"STL标准模板库\",\"link\":\"/notes/05_cpp/17_xdx/\"}]},{\"text\":\"C++ 高级\",\"collapsed\":true,\"items\":[]},{\"text\":\"QT 桌面开发\",\"collapsed\":true,\"items\":[]},{\"text\":\"Linux 高并发服务器开发\",\"collapsed\":true,\"items\":[]}]},\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/Aurorxa\"}],\"docFooter\":{\"prev\":\"上一篇\",\"next\":\"下一篇\"},\"darkModeSwitchLabel\":\"深浅模式\",\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2024 许大仙\"},\"outline\":{\"level\":[1,6],\"label\":\"目录\"},\"outlineTitle\":\"当前页大纲\"},\"locales\":{},\"scrollOffset\":134,\"cleanUrls\":false}");</script>
</body>
</html>

View File

@ -8,9 +8,9 @@
<meta name="generator" content="VitePress v1.3.3">
<link rel="preload stylesheet" href="/c/assets/style.zDJ0OJGU.css" as="style">
<script type="module" src="/c/assets/app.Ca2FOFw4.js"></script>
<script type="module" src="/c/assets/app.1a4d5P-6.js"></script>
<link rel="preload" href="/c/assets/inter-roman-latin.Di8DUHzh.woff2" as="font" type="font/woff2" crossorigin="">
<link rel="modulepreload" href="/c/assets/chunks/theme.C6fZfLtk.js">
<link rel="modulepreload" href="/c/assets/chunks/theme.Ddh-lpYV.js">
<link rel="modulepreload" href="/c/assets/chunks/framework.hMCIpNYY.js">
<link rel="modulepreload" href="/c/assets/notes_index.md.CeV-uJ5V.lean.js">
<link rel="shortcut icon" href="/c//logo.svg">
@ -22,8 +22,8 @@
<script id="check-mac-os">document.documentElement.classList.toggle("mac",/Mac|iPhone|iPod|iPad/i.test(navigator.platform));</script>
</head>
<body>
<div id="app"><div class="Layout" data-v-5d98c3a5><!--[--><!--]--><!--[--><span tabindex="-1" data-v-0f60ec36></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-0f60ec36> Skip to content </a><!--]--><!----><header class="VPNav" data-v-5d98c3a5 data-v-ae24b3ad><div class="VPNavBar has-sidebar top" data-v-ae24b3ad data-v-6aa21345><div class="wrapper" data-v-6aa21345><div class="container" data-v-6aa21345><div class="title" data-v-6aa21345><div class="VPNavBarTitle has-sidebar" data-v-6aa21345 data-v-ab179fa1><a class="title" href="/c/" data-v-ab179fa1><!--[--><!--]--><!--[--><img class="VPImage logo" src="/c/logo.svg" alt data-v-8426fc1a><!--]--><span data-v-ab179fa1>许大仙</span><!--[--><!--]--></a></div></div><div class="content" data-v-6aa21345><div class="content-body" data-v-6aa21345><!--[--><!--]--><div class="VPNavBarSearch search" data-v-6aa21345><!--[--><!----><div id="local-search"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><span class="vp-icon DocSearch-Search-Icon"></span><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key">K</kbd></span></button></div><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-6aa21345 data-v-dc692963><span id="main-nav-aria-label" class="visually-hidden" data-v-dc692963> Main Navigation </span><!--[--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>首页</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/coa6/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>计组6件套</span><!--]--></a><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup active" data-v-dc692963 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-b6c34ac9><span class="text" data-v-b6c34ac9><!----><span data-v-b6c34ac9>编程语言</span><span class="vpi-chevron-down text-icon" data-v-b6c34ac9></span></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><div class="items" data-v-b98bc113><!--[--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link active" href="/c/notes/" data-v-43f1e123><!--[-->c/c++<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/web-design/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->前端<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/java/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Java<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/big-data/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->大数据<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/linux/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->云原生<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/go/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Go<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/python/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Python<!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/db/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>数据库</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/open-software/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>开源软件</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/c/notes/about/" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>关于我</span><!--]--></a><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-6aa21345 data-v-6c893767><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-6c893767 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-6aa21345 data-v-0394ad82 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-6aa21345 data-v-bb2aa2f0 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-b6c34ac9><span class="vpi-more-horizontal icon" data-v-b6c34ac9></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><!----><!--[--><!--[--><!----><div class="group" data-v-bb2aa2f0><div class="item appearance" data-v-bb2aa2f0><p class="label" data-v-bb2aa2f0>深浅模式</p><div class="appearance-action" data-v-bb2aa2f0><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-bb2aa2f0 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div></div></div><div class="group" data-v-bb2aa2f0><div class="item social-links" data-v-bb2aa2f0><div class="VPSocialLinks social-links-list" data-v-bb2aa2f0 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div></div></div><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-6aa21345 data-v-e5dd9c1c><span class="container" data-v-e5dd9c1c><span class="top" data-v-e5dd9c1c></span><span class="middle" data-v-e5dd9c1c></span><span class="bottom" data-v-e5dd9c1c></span></span></button></div></div></div></div><div class="divider" data-v-6aa21345><div class="divider-line" data-v-6aa21345></div></div></div><!----></header><div class="VPLocalNav has-sidebar empty" data-v-5d98c3a5 data-v-a6f0e41e><div class="container" data-v-a6f0e41e><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-a6f0e41e><span class="vpi-align-left menu-icon" data-v-a6f0e41e></span><span class="menu-text" data-v-a6f0e41e>Menu</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-a6f0e41e data-v-17a5e62e><button data-v-17a5e62e>返回顶部</button><!----></div></div></div><aside class="VPSidebar" data-v-5d98c3a5 data-v-319d5ca6><div class="curtain" data-v-319d5ca6></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-319d5ca6><span class="visually-hidden" id="sidebar-aria-label" data-v-319d5ca6> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/00_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编程基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C 语言入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和进制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数据类型和运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>预处理器</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>内存管理</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-basic/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>调试工具和调试技巧gdb和make</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>常用库函数</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言高级</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和内存分布</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针强化</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>结构体和文件的高级用法</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>链表和回调函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编译过程和面向接口</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>项目构建工具</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>meson</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>meson 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Cmake</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Cmake 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_${commonDirectoryName}/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Conan </p><!--]--></a><!----></div><!----></div><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Gradle</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Gradle 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>Linux</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/04_linux/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Linux 初识和安装</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C++ 基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量、数据类型、运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>类和对象</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 引用</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>继承和派生</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 多态和虚函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/12_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>运算符重载</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>模板</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/14_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 异常</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/15_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>面向对象进阶</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/16_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作和 IO 流</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/17_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>STL标准模板库</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>C++ 高级</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>QT 桌面开发</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>Linux 高并发服务器开发</p><!----></div><!----></div></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-5d98c3a5 data-v-1428d186><div class="VPDoc has-sidebar has-aside" data-v-1428d186 data-v-39a288b8><!--[--><!--]--><div class="container" data-v-39a288b8><div class="aside" data-v-39a288b8><div class="aside-curtain" data-v-39a288b8></div><div class="aside-container" data-v-39a288b8><div class="aside-content" data-v-39a288b8><div class="VPDocAside" data-v-39a288b8 data-v-3f215769><!--[--><!--]--><!--[--><!--]--><nav aria-labelledby="doc-outline-aria-label" class="VPDocAsideOutline" data-v-3f215769 data-v-a5bbad30><div class="content" data-v-a5bbad30><div class="outline-marker" data-v-a5bbad30></div><div aria-level="2" class="outline-title" id="doc-outline-aria-label" role="heading" data-v-a5bbad30>目录</div><ul class="VPDocOutlineItem root" data-v-a5bbad30 data-v-b933a997><!--[--><!--]--></ul></div></nav><!--[--><!--]--><div class="spacer" data-v-3f215769></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-39a288b8><div class="content-container" data-v-39a288b8><!--[--><!--]--><main class="main" data-v-39a288b8><div style="position:relative;" class="vp-doc _c_notes_" data-v-39a288b8><div><h1 id="c-c-学科" tabindex="-1">c/c++ 学科 <a class="header-anchor" href="#c-c-学科" aria-label="Permalink to &quot;c/c++ 学科&quot;"></a></h1><hr><iframe src="https://roadmap.sh/r/embed?id=6695c8262b17b182cbf4b520" width="115%" height="500px" frameBorder="0"></iframe></div></div></main><footer class="VPDocFooter" data-v-39a288b8 data-v-e257564d><!--[--><!--]--><div class="edit-info" data-v-e257564d><!----><div class="last-updated" data-v-e257564d><p class="VPLastUpdated" data-v-e257564d data-v-e98dd255>上次更新: <time datetime="2024-08-01T02:00:11.000Z" data-v-e98dd255></time></p></div></div><nav class="prev-next" aria-labelledby="doc-footer-aria-label" data-v-e257564d><span class="visually-hidden" id="doc-footer-aria-label" data-v-e257564d>Pager</span><div class="pager" data-v-e257564d><!----></div><div class="pager" data-v-e257564d><a class="VPLink link pager-link next" href="/c/notes/01_c-basic/00_xdx/" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>下一篇</span><span class="title" data-v-e257564d>编程基础</span><!--]--></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><footer class="VPFooter has-sidebar" data-v-5d98c3a5 data-v-e315a0ad><div class="container" data-v-e315a0ad><p class="message" data-v-e315a0ad>Released under the MIT License.</p><p class="copyright" data-v-e315a0ad>Copyright © 2024 许大仙</p></div></footer><!--[--><!--]--></div></div>
<script>window.__VP_HASH_MAP__=JSON.parse("{\"index.md\":\"Dga0tMF5\",\"notes_01_c-basic_00_xdx_index.md\":\"BRC7slaL\",\"notes_01_c-basic_01_xdx_index.md\":\"DvCUr2L0\",\"notes_01_c-basic_02_xdx_index.md\":\"CC2Mg9VD\",\"notes_01_c-basic_03_xdx_index.md\":\"CcATnhKW\",\"notes_01_c-basic_04_xdx_index.md\":\"DABEMZSO\",\"notes_01_c-basic_05_xdx_index.md\":\"CGbN5wss\",\"notes_01_c-basic_06_xdx_index.md\":\"CIGNaKYV\",\"notes_04_linux_01_xdx_index.md\":\"C9IatKsj\",\"notes_about_index.md\":\"DLuQgC_8\",\"notes_index.md\":\"CeV-uJ5V\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"zh-CN\",\"dir\":\"ltr\",\"title\":\"许大仙\",\"titleTemplate\":\"Hi终于等到你\",\"description\":\"许大仙前端、Java、大数据、云原生\",\"base\":\"/c/\",\"head\":[],\"router\":{\"prefetchLinks\":true},\"appearance\":true,\"themeConfig\":{\"lastUpdatedText\":\"上次更新\",\"returnToTopLabel\":\"返回顶部\",\"search\":{\"provider\":\"local\"},\"logo\":\"/logo.svg\",\"nav\":[{\"text\":\"首页\",\"link\":\"https://aexiar.github.io/\"},{\"text\":\"计组6件套\",\"link\":\"https://aexiar.github.io/coa6/notes/\"},{\"text\":\"编程语言\",\"items\":[{\"text\":\"c/c++\",\"link\":\"/notes/\"},{\"text\":\"前端\",\"link\":\"https://aexiar.github.io/web-design/notes/\"},{\"text\":\"Java\",\"link\":\"https://aexiar.github.io/java/notes/\"},{\"text\":\"大数据\",\"link\":\"https://aexiar.github.io/big-data/notes/\"},{\"text\":\"云原生\",\"link\":\"https://aexiar.github.io/linux/notes/\"},{\"text\":\"Go\",\"link\":\"https://aexiar.github.io/go/notes/\"},{\"text\":\"Python\",\"link\":\"https://aexiar.github.io/python/notes/\"}]},{\"text\":\"数据库\",\"link\":\"https://aexiar.github.io/db/notes/\"},{\"text\":\"开源软件\",\"link\":\"https://aexiar.github.io/open-software/notes/\"},{\"text\":\"关于我\",\"link\":\"/notes/about/\"}],\"sidebar\":{\"/notes/\":[{\"text\":\"C 语言基础\",\"collapsed\":true,\"items\":[{\"text\":\"编程基础\",\"link\":\"/notes/01_c-basic/00_xdx/\"},{\"text\":\"C 语言入门\",\"link\":\"/notes/01_c-basic/01_xdx/\"},{\"text\":\"变量和进制\",\"link\":\"/notes/01_c-basic/02_xdx/\"},{\"text\":\"数据类型和运算符\",\"link\":\"/notes/01_c-basic/03_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/01_c-basic/04_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/01_c-basic/05_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/01_c-basic/06_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/01_c-basic/07_xdx/\"},{\"text\":\"预处理器\",\"link\":\"/notes/01_c-basic/08_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/01_c-basic/09_xdx/\"},{\"text\":\"内存管理\",\"link\":\"/notes/01_c-basic/10_xdx/\"},{\"text\":\"文件操作\",\"link\":\"/notes/01_c-basic/11_xdx/\"},{\"text\":\"调试工具和调试技巧gdb和make\",\"link\":\"/notes/02_c-basic/13_xdx/\"},{\"text\":\"常用库函数\",\"link\":\"/notes/01_c-basic/13_xdx/\"}]},{\"text\":\"C 语言高级\",\"collapsed\":true,\"items\":[{\"text\":\"变量和内存分布\",\"link\":\"/notes/02_c-advance/01_xdx/\"},{\"text\":\"指针强化\",\"link\":\"/notes/02_c-advance/02_xdx/\"},{\"text\":\"结构体和文件的高级用法\",\"link\":\"/notes/02_c-advance/03_xdx/\"},{\"text\":\"链表和回调函数\",\"link\":\"/notes/02_c-advance/04_xdx/\"},{\"text\":\"编译过程和面向接口\",\"link\":\"/notes/02_c-advance/05_xdx/\"}]},{\"text\":\"项目构建工具\",\"collapsed\":true,\"items\":[{\"text\":\"meson\",\"collapsed\":true,\"items\":[{\"text\":\"meson 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Cmake\",\"collapsed\":true,\"items\":[{\"text\":\"Cmake 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Conan \",\"link\":\"/notes/03_build/01_${commonDirectoryName}/\"},{\"text\":\"Gradle\",\"collapsed\":true,\"items\":[{\"text\":\"Gradle 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]}]},{\"text\":\"Linux\",\"collapsed\":true,\"items\":[{\"text\":\"Linux 初识和安装\",\"link\":\"/notes/04_linux/01_xdx/\"}]},{\"text\":\"C++ 基础\",\"collapsed\":true,\"items\":[{\"text\":\"C++ 入门\",\"link\":\"/notes/05_cpp/01_xdx/\"},{\"text\":\"变量、数据类型、运算符\",\"link\":\"/notes/05_cpp/02_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/05_cpp/03_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/05_cpp/04_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/05_cpp/05_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/05_cpp/06_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/05_cpp/07_xdx/\"},{\"text\":\"类和对象\",\"link\":\"/notes/05_cpp/08_xdx/\"},{\"text\":\"C++ 引用\",\"link\":\"/notes/05_cpp/09_xdx/\"},{\"text\":\"继承和派生\",\"link\":\"/notes/05_cpp/10_xdx/\"},{\"text\":\"C++ 多态和虚函数\",\"link\":\"/notes/05_cpp/11_xdx/\"},{\"text\":\"运算符重载\",\"link\":\"/notes/05_cpp/12_xdx/\"},{\"text\":\"模板\",\"link\":\"/notes/05_cpp/13_xdx/\"},{\"text\":\"C++ 异常\",\"link\":\"/notes/05_cpp/14_xdx/\"},{\"text\":\"面向对象进阶\",\"link\":\"/notes/05_cpp/15_xdx/\"},{\"text\":\"文件操作和 IO 流\",\"link\":\"/notes/05_cpp/16_xdx/\"},{\"text\":\"STL标准模板库\",\"link\":\"/notes/05_cpp/17_xdx/\"}]},{\"text\":\"C++ 高级\",\"collapsed\":true,\"items\":[]},{\"text\":\"QT 桌面开发\",\"collapsed\":true,\"items\":[]},{\"text\":\"Linux 高并发服务器开发\",\"collapsed\":true,\"items\":[]}]},\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/Aurorxa\"}],\"docFooter\":{\"prev\":\"上一篇\",\"next\":\"下一篇\"},\"darkModeSwitchLabel\":\"深浅模式\",\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2024 许大仙\"},\"outline\":{\"level\":[1,6],\"label\":\"目录\"},\"outlineTitle\":\"当前页大纲\"},\"locales\":{},\"scrollOffset\":134,\"cleanUrls\":false}");</script>
<div id="app"><div class="Layout" data-v-5d98c3a5><!--[--><!--]--><!--[--><span tabindex="-1" data-v-0f60ec36></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-0f60ec36> Skip to content </a><!--]--><!----><header class="VPNav" data-v-5d98c3a5 data-v-ae24b3ad><div class="VPNavBar has-sidebar top" data-v-ae24b3ad data-v-6aa21345><div class="wrapper" data-v-6aa21345><div class="container" data-v-6aa21345><div class="title" data-v-6aa21345><div class="VPNavBarTitle has-sidebar" data-v-6aa21345 data-v-ab179fa1><a class="title" href="/c/" data-v-ab179fa1><!--[--><!--]--><!--[--><img class="VPImage logo" src="/c/logo.svg" alt data-v-8426fc1a><!--]--><span data-v-ab179fa1>许大仙</span><!--[--><!--]--></a></div></div><div class="content" data-v-6aa21345><div class="content-body" data-v-6aa21345><!--[--><!--]--><div class="VPNavBarSearch search" data-v-6aa21345><!--[--><!----><div id="local-search"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><span class="vp-icon DocSearch-Search-Icon"></span><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key">K</kbd></span></button></div><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-6aa21345 data-v-dc692963><span id="main-nav-aria-label" class="visually-hidden" data-v-dc692963> Main Navigation </span><!--[--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>首页</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/coa6/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>计组6件套</span><!--]--></a><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup active" data-v-dc692963 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-b6c34ac9><span class="text" data-v-b6c34ac9><!----><span data-v-b6c34ac9>编程语言</span><span class="vpi-chevron-down text-icon" data-v-b6c34ac9></span></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><div class="items" data-v-b98bc113><!--[--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link active" href="/c/notes/" data-v-43f1e123><!--[-->c/c++<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/web-design/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->前端<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/java/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Java<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/big-data/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->大数据<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/linux/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->云原生<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/go/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Go<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b98bc113 data-v-43f1e123><a class="VPLink link vp-external-link-icon" href="https://aexiar.github.io/python/notes/" target="_blank" rel="noreferrer" data-v-43f1e123><!--[-->Python<!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/db/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>数据库</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/open-software/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>开源软件</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/c/notes/about/" tabindex="0" data-v-dc692963 data-v-9c663999><!--[--><span data-v-9c663999>关于我</span><!--]--></a><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-6aa21345 data-v-6c893767><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-6c893767 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-6aa21345 data-v-0394ad82 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-6aa21345 data-v-bb2aa2f0 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-b6c34ac9><span class="vpi-more-horizontal icon" data-v-b6c34ac9></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-b98bc113><!----><!--[--><!--[--><!----><div class="group" data-v-bb2aa2f0><div class="item appearance" data-v-bb2aa2f0><p class="label" data-v-bb2aa2f0>深浅模式</p><div class="appearance-action" data-v-bb2aa2f0><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-bb2aa2f0 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div></div></div><div class="group" data-v-bb2aa2f0><div class="item social-links" data-v-bb2aa2f0><div class="VPSocialLinks social-links-list" data-v-bb2aa2f0 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/Aurorxa" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div></div></div><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-6aa21345 data-v-e5dd9c1c><span class="container" data-v-e5dd9c1c><span class="top" data-v-e5dd9c1c></span><span class="middle" data-v-e5dd9c1c></span><span class="bottom" data-v-e5dd9c1c></span></span></button></div></div></div></div><div class="divider" data-v-6aa21345><div class="divider-line" data-v-6aa21345></div></div></div><!----></header><div class="VPLocalNav has-sidebar empty" data-v-5d98c3a5 data-v-a6f0e41e><div class="container" data-v-a6f0e41e><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-a6f0e41e><span class="vpi-align-left menu-icon" data-v-a6f0e41e></span><span class="menu-text" data-v-a6f0e41e>Menu</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-a6f0e41e data-v-17a5e62e><button data-v-17a5e62e>返回顶部</button><!----></div></div></div><aside class="VPSidebar" data-v-5d98c3a5 data-v-319d5ca6><div class="curtain" data-v-319d5ca6></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-319d5ca6><span class="visually-hidden" id="sidebar-aria-label" data-v-319d5ca6> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/00_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编程基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C 语言入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和进制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数据类型和运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>大话小数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>预处理器</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>内存管理</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/12_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-basic/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>调试工具和调试技巧gdb和make</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/01_c-basic/14_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>常用库函数</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C 语言高级</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量和内存分布</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针强化</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>结构体和文件的高级用法</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>链表和回调函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/02_c-advance/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>编译过程和面向接口</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>项目构建工具</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>meson</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>meson 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Cmake</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Cmake 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_${commonDirectoryName}/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Conan </p><!--]--></a><!----></div><!----></div><section class="VPSidebarItem level-1 collapsible collapsed" data-v-b7550ba0 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h3 class="text" data-v-b7550ba0>Gradle</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-2 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/03_build/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Gradle 入门</p><!--]--></a><!----></div><!----></div><!--]--></div></section><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>Linux</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/04_linux/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>Linux 初识和安装</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><h2 class="text" data-v-b7550ba0>C++ 基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b7550ba0><span class="vpi-chevron-right caret-icon" data-v-b7550ba0></span></div></div><div class="items" data-v-b7550ba0><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/01_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/02_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>变量、数据类型、运算符</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/03_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>流程控制</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/04_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>数组</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/05_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>指针</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/06_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/07_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>自定义数据类型</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/08_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>类和对象</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/09_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 引用</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/10_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>继承和派生</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/11_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 多态和虚函数</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/12_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>运算符重载</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/13_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>模板</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/14_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>C++ 异常</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/15_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>面向对象进阶</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/16_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>文件操作和 IO 流</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b7550ba0 data-v-b7550ba0><div class="item" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><a class="VPLink link link" href="/c/notes/05_cpp/17_xdx/" data-v-b7550ba0><!--[--><p class="text" data-v-b7550ba0>STL标准模板库</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>C++ 高级</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>QT 桌面开发</p><!----></div><!----></div></div><div class="no-transition group" data-v-c40bc020><div class="VPSidebarItem level-0 collapsible collapsed" data-v-c40bc020 data-v-b7550ba0><div class="item" role="button" tabindex="0" data-v-b7550ba0><div class="indicator" data-v-b7550ba0></div><p class="text" data-v-b7550ba0>Linux 高并发服务器开发</p><!----></div><!----></div></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-5d98c3a5 data-v-1428d186><div class="VPDoc has-sidebar has-aside" data-v-1428d186 data-v-39a288b8><!--[--><!--]--><div class="container" data-v-39a288b8><div class="aside" data-v-39a288b8><div class="aside-curtain" data-v-39a288b8></div><div class="aside-container" data-v-39a288b8><div class="aside-content" data-v-39a288b8><div class="VPDocAside" data-v-39a288b8 data-v-3f215769><!--[--><!--]--><!--[--><!--]--><nav aria-labelledby="doc-outline-aria-label" class="VPDocAsideOutline" data-v-3f215769 data-v-a5bbad30><div class="content" data-v-a5bbad30><div class="outline-marker" data-v-a5bbad30></div><div aria-level="2" class="outline-title" id="doc-outline-aria-label" role="heading" data-v-a5bbad30>目录</div><ul class="VPDocOutlineItem root" data-v-a5bbad30 data-v-b933a997><!--[--><!--]--></ul></div></nav><!--[--><!--]--><div class="spacer" data-v-3f215769></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-39a288b8><div class="content-container" data-v-39a288b8><!--[--><!--]--><main class="main" data-v-39a288b8><div style="position:relative;" class="vp-doc _c_notes_" data-v-39a288b8><div><h1 id="c-c-学科" tabindex="-1">c/c++ 学科 <a class="header-anchor" href="#c-c-学科" aria-label="Permalink to &quot;c/c++ 学科&quot;"></a></h1><hr><iframe src="https://roadmap.sh/r/embed?id=6695c8262b17b182cbf4b520" width="115%" height="500px" frameBorder="0"></iframe></div></div></main><footer class="VPDocFooter" data-v-39a288b8 data-v-e257564d><!--[--><!--]--><div class="edit-info" data-v-e257564d><!----><div class="last-updated" data-v-e257564d><p class="VPLastUpdated" data-v-e257564d data-v-e98dd255>上次更新: <time datetime="2024-08-01T02:00:11.000Z" data-v-e98dd255></time></p></div></div><nav class="prev-next" aria-labelledby="doc-footer-aria-label" data-v-e257564d><span class="visually-hidden" id="doc-footer-aria-label" data-v-e257564d>Pager</span><div class="pager" data-v-e257564d><!----></div><div class="pager" data-v-e257564d><a class="VPLink link pager-link next" href="/c/notes/01_c-basic/00_xdx/" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>下一篇</span><span class="title" data-v-e257564d>编程基础</span><!--]--></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><footer class="VPFooter has-sidebar" data-v-5d98c3a5 data-v-e315a0ad><div class="container" data-v-e315a0ad><p class="message" data-v-e315a0ad>Released under the MIT License.</p><p class="copyright" data-v-e315a0ad>Copyright © 2024 许大仙</p></div></footer><!--[--><!--]--></div></div>
<script>window.__VP_HASH_MAP__=JSON.parse("{\"index.md\":\"Dga0tMF5\",\"notes_01_c-basic_00_xdx_index.md\":\"BRC7slaL\",\"notes_01_c-basic_01_xdx_index.md\":\"Fg4OXydV\",\"notes_01_c-basic_02_xdx_index.md\":\"CC2Mg9VD\",\"notes_01_c-basic_03_xdx_index.md\":\"Cw3Z19MO\",\"notes_01_c-basic_04_xdx_index.md\":\"ySxH8sG-\",\"notes_01_c-basic_05_xdx_index.md\":\"DUbOwEts\",\"notes_01_c-basic_06_xdx_index.md\":\"CV_r2WNu\",\"notes_01_c-basic_07_xdx_index.md\":\"CE9q5cmu\",\"notes_04_linux_01_xdx_index.md\":\"C9IatKsj\",\"notes_about_index.md\":\"DLuQgC_8\",\"notes_index.md\":\"CeV-uJ5V\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"zh-CN\",\"dir\":\"ltr\",\"title\":\"许大仙\",\"titleTemplate\":\"Hi终于等到你\",\"description\":\"许大仙前端、Java、大数据、云原生\",\"base\":\"/c/\",\"head\":[],\"router\":{\"prefetchLinks\":true},\"appearance\":true,\"themeConfig\":{\"lastUpdatedText\":\"上次更新\",\"returnToTopLabel\":\"返回顶部\",\"search\":{\"provider\":\"local\"},\"logo\":\"/logo.svg\",\"nav\":[{\"text\":\"首页\",\"link\":\"https://aexiar.github.io/\"},{\"text\":\"计组6件套\",\"link\":\"https://aexiar.github.io/coa6/notes/\"},{\"text\":\"编程语言\",\"items\":[{\"text\":\"c/c++\",\"link\":\"/notes/\"},{\"text\":\"前端\",\"link\":\"https://aexiar.github.io/web-design/notes/\"},{\"text\":\"Java\",\"link\":\"https://aexiar.github.io/java/notes/\"},{\"text\":\"大数据\",\"link\":\"https://aexiar.github.io/big-data/notes/\"},{\"text\":\"云原生\",\"link\":\"https://aexiar.github.io/linux/notes/\"},{\"text\":\"Go\",\"link\":\"https://aexiar.github.io/go/notes/\"},{\"text\":\"Python\",\"link\":\"https://aexiar.github.io/python/notes/\"}]},{\"text\":\"数据库\",\"link\":\"https://aexiar.github.io/db/notes/\"},{\"text\":\"开源软件\",\"link\":\"https://aexiar.github.io/open-software/notes/\"},{\"text\":\"关于我\",\"link\":\"/notes/about/\"}],\"sidebar\":{\"/notes/\":[{\"text\":\"C 语言基础\",\"collapsed\":true,\"items\":[{\"text\":\"编程基础\",\"link\":\"/notes/01_c-basic/00_xdx/\"},{\"text\":\"C 语言入门\",\"link\":\"/notes/01_c-basic/01_xdx/\"},{\"text\":\"变量和进制\",\"link\":\"/notes/01_c-basic/02_xdx/\"},{\"text\":\"数据类型和运算符\",\"link\":\"/notes/01_c-basic/03_xdx/\"},{\"text\":\"大话小数\",\"link\":\"/notes/01_c-basic/04_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/01_c-basic/05_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/01_c-basic/06_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/01_c-basic/07_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/01_c-basic/08_xdx/\"},{\"text\":\"预处理器\",\"link\":\"/notes/01_c-basic/09_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/01_c-basic/10_xdx/\"},{\"text\":\"内存管理\",\"link\":\"/notes/01_c-basic/11_xdx/\"},{\"text\":\"文件操作\",\"link\":\"/notes/01_c-basic/12_xdx/\"},{\"text\":\"调试工具和调试技巧gdb和make\",\"link\":\"/notes/02_c-basic/13_xdx/\"},{\"text\":\"常用库函数\",\"link\":\"/notes/01_c-basic/14_xdx/\"}]},{\"text\":\"C 语言高级\",\"collapsed\":true,\"items\":[{\"text\":\"变量和内存分布\",\"link\":\"/notes/02_c-advance/01_xdx/\"},{\"text\":\"指针强化\",\"link\":\"/notes/02_c-advance/02_xdx/\"},{\"text\":\"结构体和文件的高级用法\",\"link\":\"/notes/02_c-advance/03_xdx/\"},{\"text\":\"链表和回调函数\",\"link\":\"/notes/02_c-advance/04_xdx/\"},{\"text\":\"编译过程和面向接口\",\"link\":\"/notes/02_c-advance/05_xdx/\"}]},{\"text\":\"项目构建工具\",\"collapsed\":true,\"items\":[{\"text\":\"meson\",\"collapsed\":true,\"items\":[{\"text\":\"meson 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Cmake\",\"collapsed\":true,\"items\":[{\"text\":\"Cmake 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]},{\"text\":\"Conan \",\"link\":\"/notes/03_build/01_${commonDirectoryName}/\"},{\"text\":\"Gradle\",\"collapsed\":true,\"items\":[{\"text\":\"Gradle 入门\",\"link\":\"/notes/03_build/01_xdx/\"}]}]},{\"text\":\"Linux\",\"collapsed\":true,\"items\":[{\"text\":\"Linux 初识和安装\",\"link\":\"/notes/04_linux/01_xdx/\"}]},{\"text\":\"C++ 基础\",\"collapsed\":true,\"items\":[{\"text\":\"C++ 入门\",\"link\":\"/notes/05_cpp/01_xdx/\"},{\"text\":\"变量、数据类型、运算符\",\"link\":\"/notes/05_cpp/02_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/05_cpp/03_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/05_cpp/04_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/05_cpp/05_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/05_cpp/06_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/05_cpp/07_xdx/\"},{\"text\":\"类和对象\",\"link\":\"/notes/05_cpp/08_xdx/\"},{\"text\":\"C++ 引用\",\"link\":\"/notes/05_cpp/09_xdx/\"},{\"text\":\"继承和派生\",\"link\":\"/notes/05_cpp/10_xdx/\"},{\"text\":\"C++ 多态和虚函数\",\"link\":\"/notes/05_cpp/11_xdx/\"},{\"text\":\"运算符重载\",\"link\":\"/notes/05_cpp/12_xdx/\"},{\"text\":\"模板\",\"link\":\"/notes/05_cpp/13_xdx/\"},{\"text\":\"C++ 异常\",\"link\":\"/notes/05_cpp/14_xdx/\"},{\"text\":\"面向对象进阶\",\"link\":\"/notes/05_cpp/15_xdx/\"},{\"text\":\"文件操作和 IO 流\",\"link\":\"/notes/05_cpp/16_xdx/\"},{\"text\":\"STL标准模板库\",\"link\":\"/notes/05_cpp/17_xdx/\"}]},{\"text\":\"C++ 高级\",\"collapsed\":true,\"items\":[]},{\"text\":\"QT 桌面开发\",\"collapsed\":true,\"items\":[]},{\"text\":\"Linux 高并发服务器开发\",\"collapsed\":true,\"items\":[]}]},\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/Aurorxa\"}],\"docFooter\":{\"prev\":\"上一篇\",\"next\":\"下一篇\"},\"darkModeSwitchLabel\":\"深浅模式\",\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2024 许大仙\"},\"outline\":{\"level\":[1,6],\"label\":\"目录\"},\"outlineTitle\":\"当前页大纲\"},\"locales\":{},\"scrollOffset\":134,\"cleanUrls\":false}");</script>
</body>
</html>