deploy: 278752d4361d2df75fbdf23bf93cc01a974db3c6
24
404.html
Normal file
@ -0,0 +1,24 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN" dir="ltr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
|
||||
<title>404 | Hi,终于等到你</title>
|
||||
<meta name="description" content="Not Found">
|
||||
<meta name="generator" content="VitePress v1.2.3">
|
||||
<link rel="preload stylesheet" href="/coa6/assets/style.93t0OQ_p.css" as="style">
|
||||
|
||||
<script type="module" src="/coa6/assets/app.BmFonQgT.js"></script>
|
||||
<link rel="preload" href="/coa6/assets/inter-roman-latin.Di8DUHzh.woff2" as="font" type="font/woff2" crossorigin="">
|
||||
<link rel="shortcut icon" href="/coa6//favicon.ico">
|
||||
<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>
|
||||
<script>window.__VP_HASH_MAP__=JSON.parse("{\"notes_index.md\":\"86O_Lb7b\",\"index.md\":\"LKQAh9T8\",\"notes_01_c-basic_02_xdx_index.md\":\"k6oVENcd\",\"notes_01_c-basic_01_xdx_index.md\":\"D1hb9NAd\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"zh-CN\",\"dir\":\"ltr\",\"title\":\"许大仙\",\"titleTemplate\":\"Hi,终于等到你\",\"description\":\"许大仙前端、Java、大数据、云原生\",\"base\":\"/coa6/\",\"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\":\"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\":\"开源软件\",\"link\":\"https://aexiar.github.io/open-software/notes/\"}],\"sidebar\":{\"/notes/\":[{\"text\":\"C语言基础\",\"collapsed\":true,\"items\":[{\"text\":\"C 语言入门\",\"link\":\"/notes/01_c-basic/01_xdx/\"},{\"text\":\"变量和进制\",\"link\":\"/notes/01_c-basic/02_xdx/\"}]},{\"text\":\"C 语言高级\",\"collapsed\":true,\"items\":[{\"text\":\"初识 C 语言\",\"link\":\"/notes/02_dsa/01_xdx/\"}]},{\"text\":\"C++ 核心编程\",\"collapsed\":true,\"items\":[{\"text\":\"计算机组成原理前言\",\"link\":\"/notes/03_coa/03_xdx/\"}]},{\"text\":\"QT 桌面开发\",\"collapsed\":true,\"items\":[{\"text\":\"操作系统前言\",\"link\":\"/notes/04_os/01_xdx/\"}]},{\"text\":\"Linux 高并发服务器开发\",\"collapsed\":true,\"items\":[{\"text\":\"操作系统前言\",\"link\":\"/notes/04_os/01_xdx/\"}]}]},\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/Aurorxa\"}],\"docFooter\":{\"prev\":\"上一篇\",\"next\":\"下一篇\"},\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2024 许大仙\"},\"outline\":{\"level\":[1,6],\"label\":\"目录\"},\"outlineTitle\":\"当前页大纲\"},\"locales\":{},\"scrollOffset\":134,\"cleanUrls\":false}");</script>
|
||||
|
||||
</body>
|
||||
</html>
|
BIN
assets/1.CXNJqOOc.png
Normal file
After Width: | Height: | Size: 117 KiB |
BIN
assets/1.D4a42fT1.jpg
Normal file
After Width: | Height: | Size: 281 KiB |
BIN
assets/10.CkykpHY2.png
Normal file
After Width: | Height: | Size: 6.5 KiB |
BIN
assets/10.h1ugtjyX.png
Normal file
After Width: | Height: | Size: 785 KiB |
BIN
assets/100.CaUm8Qhc.png
Normal file
After Width: | Height: | Size: 50 KiB |
BIN
assets/101.kOkqIKG6.png
Normal file
After Width: | Height: | Size: 53 KiB |
BIN
assets/102.CyeASH-c.png
Normal file
After Width: | Height: | Size: 166 KiB |
BIN
assets/103.CFdk60La.png
Normal file
After Width: | Height: | Size: 88 KiB |
BIN
assets/104.Bhl-0uK_.png
Normal file
After Width: | Height: | Size: 41 KiB |
BIN
assets/105.Dni9KbXV.png
Normal file
After Width: | Height: | Size: 142 KiB |
BIN
assets/106.BXx10MCV.png
Normal file
After Width: | Height: | Size: 97 KiB |
BIN
assets/107.CXcIKX1T.png
Normal file
After Width: | Height: | Size: 86 KiB |
BIN
assets/108.CQ3_QCQT.png
Normal file
After Width: | Height: | Size: 77 KiB |
BIN
assets/109.CQoDRJM5.gif
Normal file
After Width: | Height: | Size: 193 KiB |
BIN
assets/11.D5PWTabw.png
Normal file
After Width: | Height: | Size: 33 KiB |
BIN
assets/11.DV1YbrOP.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
assets/110.CPfwZvD9.gif
Normal file
After Width: | Height: | Size: 46 KiB |
BIN
assets/111.bxEomEjU.gif
Normal file
After Width: | Height: | Size: 48 KiB |
BIN
assets/112.C_onhf2k.png
Normal file
After Width: | Height: | Size: 54 KiB |
BIN
assets/113.Budj3s38.gif
Normal file
After Width: | Height: | Size: 571 KiB |
BIN
assets/114.CH8koQdu.gif
Normal file
After Width: | Height: | Size: 505 KiB |
BIN
assets/115.kUJhxMtg.png
Normal file
After Width: | Height: | Size: 151 KiB |
BIN
assets/116.BJeJJW4_.png
Normal file
After Width: | Height: | Size: 164 KiB |
BIN
assets/117.BCuK6eJL.gif
Normal file
After Width: | Height: | Size: 818 KiB |
BIN
assets/118.rKC-z4z-.gif
Normal file
After Width: | Height: | Size: 242 KiB |
BIN
assets/119.BJE3xxuT.gif
Normal file
After Width: | Height: | Size: 190 KiB |
BIN
assets/12.AHNJT9TV.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
assets/12.Bvs6QYjl.jpg
Normal file
After Width: | Height: | Size: 33 KiB |
BIN
assets/120.DJOq__O0.gif
Normal file
After Width: | Height: | Size: 461 KiB |
BIN
assets/121.BDt_0fRR.png
Normal file
After Width: | Height: | Size: 187 KiB |
BIN
assets/122.Bo5OawW8.png
Normal file
After Width: | Height: | Size: 96 KiB |
BIN
assets/123.sUWUfl5e.png
Normal file
After Width: | Height: | Size: 48 KiB |
BIN
assets/124.BK4jpnB8.png
Normal file
After Width: | Height: | Size: 27 KiB |
BIN
assets/125.EF8vdbSq.png
Normal file
After Width: | Height: | Size: 66 KiB |
BIN
assets/126.DjxdA_Co.png
Normal file
After Width: | Height: | Size: 40 KiB |
BIN
assets/127.sp68q1hh.gif
Normal file
After Width: | Height: | Size: 308 KiB |
BIN
assets/128.DhMRyxNN.gif
Normal file
After Width: | Height: | Size: 359 KiB |
BIN
assets/129.CdcLZM0R.gif
Normal file
After Width: | Height: | Size: 590 KiB |
BIN
assets/13.Bs-MOwx2.png
Normal file
After Width: | Height: | Size: 9.4 KiB |
BIN
assets/130.D-5AsTTr.png
Normal file
After Width: | Height: | Size: 26 KiB |
BIN
assets/131.2RQKmAUa.png
Normal file
After Width: | Height: | Size: 44 KiB |
BIN
assets/132.CI4xX8SM.png
Normal file
After Width: | Height: | Size: 62 KiB |
BIN
assets/133.C8QUZ9v3.gif
Normal file
After Width: | Height: | Size: 675 KiB |
BIN
assets/134.g5tQfhWz.gif
Normal file
After Width: | Height: | Size: 288 KiB |
BIN
assets/135.CX0_1NsE.gif
Normal file
After Width: | Height: | Size: 821 KiB |
BIN
assets/136.BrFJeoK6.png
Normal file
After Width: | Height: | Size: 123 KiB |
BIN
assets/137.58TjSSjH.gif
Normal file
After Width: | Height: | Size: 378 KiB |
BIN
assets/138.CgqNV2hL.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
assets/139.BasYWvkM.png
Normal file
After Width: | Height: | Size: 36 KiB |
BIN
assets/14.CsR5exrN.png
Normal file
After Width: | Height: | Size: 31 KiB |
BIN
assets/14.StzjmBz-.png
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
assets/140.CjFxJpBr.png
Normal file
After Width: | Height: | Size: 52 KiB |
BIN
assets/141.Dm5Jspvp.gif
Normal file
After Width: | Height: | Size: 41 KiB |
BIN
assets/142.1krCh8cy.gif
Normal file
After Width: | Height: | Size: 29 KiB |
BIN
assets/143.DOSyahv7.gif
Normal file
After Width: | Height: | Size: 53 KiB |
BIN
assets/144.BHEvX_FI.gif
Normal file
After Width: | Height: | Size: 38 KiB |
BIN
assets/145.DFA0g1_d.gif
Normal file
After Width: | Height: | Size: 39 KiB |
BIN
assets/146.D50nO5eA.gif
Normal file
After Width: | Height: | Size: 42 KiB |
BIN
assets/147.cAvG1Qfq.png
Normal file
After Width: | Height: | Size: 310 KiB |
BIN
assets/148.DpakQFWz.gif
Normal file
After Width: | Height: | Size: 35 KiB |
BIN
assets/149.Bg61j9QI.gif
Normal file
After Width: | Height: | Size: 2.0 MiB |
BIN
assets/15.BRG9GQdT.png
Normal file
After Width: | Height: | Size: 67 KiB |
BIN
assets/15.C0wVWaxD.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
assets/150.DPvD9UCw.gif
Normal file
After Width: | Height: | Size: 572 KiB |
BIN
assets/151.Ceu65U_n.gif
Normal file
After Width: | Height: | Size: 1.3 MiB |
BIN
assets/152.BWPFRK_8.gif
Normal file
After Width: | Height: | Size: 601 KiB |
BIN
assets/153.Ct4TfxPf.gif
Normal file
After Width: | Height: | Size: 681 KiB |
BIN
assets/154.zsKtx_jV.png
Normal file
After Width: | Height: | Size: 205 KiB |
BIN
assets/155.3oqDAW0w.png
Normal file
After Width: | Height: | Size: 153 KiB |
BIN
assets/156.D9TSeAa9.gif
Normal file
After Width: | Height: | Size: 614 KiB |
BIN
assets/157.CCRgYIVq.png
Normal file
After Width: | Height: | Size: 62 KiB |
BIN
assets/158.C1t2T6FV.gif
Normal file
After Width: | Height: | Size: 1.0 MiB |
BIN
assets/159.Rqa4uHq6.png
Normal file
After Width: | Height: | Size: 34 KiB |
BIN
assets/16.C2sciGZn.png
Normal file
After Width: | Height: | Size: 401 KiB |
BIN
assets/16.LXJMAihe.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
assets/160.6yQYnjOa.gif
Normal file
After Width: | Height: | Size: 209 KiB |
BIN
assets/161.hYR9GiiD.gif
Normal file
After Width: | Height: | Size: 1.1 MiB |
BIN
assets/162.D3b-QIrA.gif
Normal file
After Width: | Height: | Size: 456 KiB |
BIN
assets/163.DGbA6qsW.gif
Normal file
After Width: | Height: | Size: 388 KiB |
BIN
assets/164.BToOkxf2.gif
Normal file
After Width: | Height: | Size: 379 KiB |
BIN
assets/17.DdyXXyxJ.png
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
assets/17._UTCq3PD.png
Normal file
After Width: | Height: | Size: 19 KiB |
BIN
assets/18.BjQ5kBL-.png
Normal file
After Width: | Height: | Size: 27 KiB |
BIN
assets/18.DIeb_KXW.png
Normal file
After Width: | Height: | Size: 8.3 KiB |
BIN
assets/19.C-kvMz2p.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
assets/19.COIOzcmT.png
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
assets/2.D2wnxl5F.png
Normal file
After Width: | Height: | Size: 66 KiB |
BIN
assets/2.E0LS08Y5.png
Normal file
After Width: | Height: | Size: 34 KiB |
BIN
assets/20.CQqFxmDa.png
Normal file
After Width: | Height: | Size: 238 KiB |
BIN
assets/20.Cu__mjav.png
Normal file
After Width: | Height: | Size: 27 KiB |
BIN
assets/21.BX_KzkHt.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
assets/21.CjMWyIiX.png
Normal file
After Width: | Height: | Size: 171 KiB |
BIN
assets/22.COt_QxSP.png
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
assets/22.DFQhcDgs.png
Normal file
After Width: | Height: | Size: 111 KiB |
BIN
assets/23.Cco1vsW8.png
Normal file
After Width: | Height: | Size: 122 KiB |
BIN
assets/24.D60Zf6_d.png
Normal file
After Width: | Height: | Size: 108 KiB |
BIN
assets/25.D2-G6nV2.png
Normal file
After Width: | Height: | Size: 74 KiB |
BIN
assets/26.DpzkVk5V.png
Normal file
After Width: | Height: | Size: 424 KiB |
BIN
assets/27.BXk95GIP.png
Normal file
After Width: | Height: | Size: 90 KiB |
BIN
assets/28.CbWTB08W.png
Normal file
After Width: | Height: | Size: 90 KiB |
BIN
assets/29.twO9TCIg.png
Normal file
After Width: | Height: | Size: 166 KiB |
BIN
assets/3.Dq625oo9.jpg
Normal file
After Width: | Height: | Size: 74 KiB |
BIN
assets/3.XcPl7d9s.png
Normal file
After Width: | Height: | Size: 212 KiB |
BIN
assets/30.CKOjeIvS.png
Normal file
After Width: | Height: | Size: 130 KiB |
BIN
assets/31.DKmR0CxE.png
Normal file
After Width: | Height: | Size: 119 KiB |
BIN
assets/32.Cudf77_s.gif
Normal file
After Width: | Height: | Size: 38 KiB |
BIN
assets/33.BBUUlhRC.png
Normal file
After Width: | Height: | Size: 83 KiB |
BIN
assets/34.iLABkB7O.png
Normal file
After Width: | Height: | Size: 38 KiB |
BIN
assets/35.BQuYWOU9.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
assets/36.CslpH6j0.png
Normal file
After Width: | Height: | Size: 26 KiB |
BIN
assets/37.BAyvZdKq.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
assets/38.C3oC1iUd.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
assets/39.Ds-jsEZn.png
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
assets/4.DL02VQMp.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
assets/4.uqu1DEK4.png
Normal file
After Width: | Height: | Size: 140 KiB |
BIN
assets/40.Cd37gMYs.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
assets/41.CAw2z3gc.png
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
assets/42.DdPThnr-.png
Normal file
After Width: | Height: | Size: 41 KiB |
BIN
assets/43.q_rvlDnY.png
Normal file
After Width: | Height: | Size: 33 KiB |
BIN
assets/44.JRHg9RZA.png
Normal file
After Width: | Height: | Size: 31 KiB |
BIN
assets/45.Baq-Hb06.png
Normal file
After Width: | Height: | Size: 38 KiB |
BIN
assets/46.c1ht53mu.png
Normal file
After Width: | Height: | Size: 35 KiB |
BIN
assets/47.CAZmH5Py.png
Normal file
After Width: | Height: | Size: 35 KiB |
BIN
assets/48.DWeCYBe9.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
assets/49.2XM8pYni.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
assets/5.C6Q0Q8kf.jpg
Normal file
After Width: | Height: | Size: 112 KiB |
BIN
assets/5.Dr67r_Ws.png
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
assets/50.CN0t-fuo.png
Normal file
After Width: | Height: | Size: 19 KiB |
BIN
assets/51.AcDh3LXQ.png
Normal file
After Width: | Height: | Size: 85 KiB |
BIN
assets/52.CUkDFAc6.png
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
assets/53.picNTNaJ.png
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
assets/54.DKX92RgJ.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
assets/55.Bxr7QKI3.png
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
assets/56.DuFWsOgW.png
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
assets/57.Da9qUcfr.png
Normal file
After Width: | Height: | Size: 6.3 KiB |
BIN
assets/58.7_gEABSX.gif
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
assets/59.C2KQYoVC.gif
Normal file
After Width: | Height: | Size: 3.1 MiB |
BIN
assets/6.B4Srsb-0.png
Normal file
After Width: | Height: | Size: 249 KiB |
BIN
assets/6.C5XiXNVN.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
assets/60.RTUP8Vtx.png
Normal file
After Width: | Height: | Size: 72 KiB |
BIN
assets/61.Dq21DxwL.png
Normal file
After Width: | Height: | Size: 35 KiB |
BIN
assets/62.QmpUaNxU.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
assets/63.DP0C29gZ.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
assets/64.DwzHokd4.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
assets/65.Bi6K26yA.png
Normal file
After Width: | Height: | Size: 34 KiB |
BIN
assets/66.Bw8DcEQ_.png
Normal file
After Width: | Height: | Size: 25 KiB |
BIN
assets/67.DPc8Z9rS.png
Normal file
After Width: | Height: | Size: 48 KiB |
BIN
assets/68.S84xHMTl.png
Normal file
After Width: | Height: | Size: 66 KiB |
BIN
assets/69.iw3JQUkn.png
Normal file
After Width: | Height: | Size: 32 KiB |
BIN
assets/7.DO8XxSV6.jpg
Normal file
After Width: | Height: | Size: 217 KiB |
BIN
assets/7._D_c8Lrn.png
Normal file
After Width: | Height: | Size: 283 KiB |
BIN
assets/70.ILeJt-HK.png
Normal file
After Width: | Height: | Size: 62 KiB |
BIN
assets/71.CHgm7khh.png
Normal file
After Width: | Height: | Size: 104 KiB |
BIN
assets/72.N1nqJaEg.png
Normal file
After Width: | Height: | Size: 82 KiB |
BIN
assets/73.DHsnibMi.png
Normal file
After Width: | Height: | Size: 79 KiB |
BIN
assets/74.BQr6Q0uV.png
Normal file
After Width: | Height: | Size: 61 KiB |
BIN
assets/75.BVemi2Lh.png
Normal file
After Width: | Height: | Size: 88 KiB |
BIN
assets/76.BHR69UXx.png
Normal file
After Width: | Height: | Size: 124 KiB |
BIN
assets/77.CPSU5SJI.png
Normal file
After Width: | Height: | Size: 73 KiB |
BIN
assets/78.CaQLoDlw.png
Normal file
After Width: | Height: | Size: 786 KiB |
BIN
assets/79.aRGy4XbL.png
Normal file
After Width: | Height: | Size: 509 KiB |
BIN
assets/8.CUXrdefp.jpeg
Normal file
After Width: | Height: | Size: 103 KiB |
BIN
assets/8.DlIyFGDg.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
assets/80.kNO9fmPR.png
Normal file
After Width: | Height: | Size: 501 KiB |
BIN
assets/81.D4EkoC4o.png
Normal file
After Width: | Height: | Size: 494 KiB |
BIN
assets/82.V23Lo9e_.png
Normal file
After Width: | Height: | Size: 500 KiB |
BIN
assets/83.Du9LVeMB.png
Normal file
After Width: | Height: | Size: 502 KiB |
BIN
assets/84.DdFg75U9.png
Normal file
After Width: | Height: | Size: 488 KiB |
BIN
assets/85.C6bz6KtT.png
Normal file
After Width: | Height: | Size: 508 KiB |
BIN
assets/86.CB6LAhB5.png
Normal file
After Width: | Height: | Size: 261 KiB |
BIN
assets/87.Bip8bkua.png
Normal file
After Width: | Height: | Size: 341 KiB |
BIN
assets/88.DRNHRduW.png
Normal file
After Width: | Height: | Size: 317 KiB |
BIN
assets/89.Cth4qqEn.png
Normal file
After Width: | Height: | Size: 280 KiB |
BIN
assets/9.7zkUmpQw.png
Normal file
After Width: | Height: | Size: 53 KiB |
BIN
assets/9.uqLiL_yu.png
Normal file
After Width: | Height: | Size: 9.6 KiB |
BIN
assets/90.DWGWZ64P.png
Normal file
After Width: | Height: | Size: 191 KiB |
BIN
assets/91.3hDIDdvx.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
assets/92.Bw_dQ4ap.png
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
assets/93.Cn_ubTyA.png
Normal file
After Width: | Height: | Size: 119 KiB |
BIN
assets/94.C84EBqwB.png
Normal file
After Width: | Height: | Size: 132 KiB |
BIN
assets/95.dZfJY4eR.png
Normal file
After Width: | Height: | Size: 84 KiB |
BIN
assets/96.B0zm0Z79.png
Normal file
After Width: | Height: | Size: 83 KiB |
BIN
assets/97.CaTcEy1Q.png
Normal file
After Width: | Height: | Size: 89 KiB |
BIN
assets/98.iEc8mo9g.png
Normal file
After Width: | Height: | Size: 53 KiB |
BIN
assets/99.Co2KxM6t.png
Normal file
After Width: | Height: | Size: 83 KiB |
1
assets/app.BmFonQgT.js
Normal file
@ -0,0 +1 @@
|
||||
import{U as o,a6 as p,a7 as u,a8 as l,a9 as c,aa as f,ab as d,ac as m,ad as h,ae as g,af as A,d as P,u as v,y,x as w,ag as C,ah as R,ai as b,a4 as E}from"./chunks/framework.D1oHBMsh.js";import{R as S}from"./chunks/theme.DstJSxiY.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(S),T=P({name:"VitePressApp",setup(){const{site:e,lang:a,dir:t}=v();return y(()=>{w(()=>{document.documentElement.lang=a.value,document.documentElement.dir=t.value})}),e.value.router.prefetchLinks&&C(),R(),b(),s.setup&&s.setup(),()=>E(s.Layout)}});async function _(){globalThis.__VITEPRESS__=!0;const e=D(),a=x();a.provide(u,e);const t=l(e.route);return a.provide(c,t),a.component("Content",f),a.component("ClientOnly",d),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:m}),{app:a,router:e,data:t}}function x(){return h(T)}function D(){let e=o,a;return g(t=>{let n=A(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&&_().then(({app:e,router:a,data:t})=>{a.go().then(()=>{p(a.route,t.site),e.mount("#app")})});export{_ as createApp};
|
1
assets/chunks/@localSearchIndexroot.C5vPI6F-.js
Normal file
7
assets/chunks/VPLocalSearchBox.Bt_ZNxRf.js
Normal file
17
assets/chunks/framework.D1oHBMsh.js
Normal file
@ -0,0 +1,17 @@
|
||||
/**
|
||||
* @vue/shared v3.4.30
|
||||
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
||||
* @license MIT
|
||||
**//*! #__NO_SIDE_EFFECTS__ */function wr(e,t){const n=new Set(e.split(","));return r=>n.has(r)}const te={},mt=[],xe=()=>{},Li=()=>!1,kt=e=>e.charCodeAt(0)===111&&e.charCodeAt(1)===110&&(e.charCodeAt(2)>122||e.charCodeAt(2)<97),Er=e=>e.startsWith("onUpdate:"),le=Object.assign,Cr=(e,t)=>{const n=e.indexOf(t);n>-1&&e.splice(n,1)},Ii=Object.prototype.hasOwnProperty,z=(e,t)=>Ii.call(e,t),k=Array.isArray,yt=e=>Sn(e)==="[object Map]",zs=e=>Sn(e)==="[object Set]",K=e=>typeof e=="function",oe=e=>typeof e=="string",et=e=>typeof e=="symbol",Z=e=>e!==null&&typeof e=="object",Js=e=>(Z(e)||K(e))&&K(e.then)&&K(e.catch),Qs=Object.prototype.toString,Sn=e=>Qs.call(e),Mi=e=>Sn(e).slice(8,-1),Zs=e=>Sn(e)==="[object Object]",xr=e=>oe(e)&&e!=="NaN"&&e[0]!=="-"&&""+parseInt(e,10)===e,_t=wr(",key,ref,ref_for,ref_key,onVnodeBeforeMount,onVnodeMounted,onVnodeBeforeUpdate,onVnodeUpdated,onVnodeBeforeUnmount,onVnodeUnmounted"),Tn=e=>{const t=Object.create(null);return n=>t[n]||(t[n]=e(n))},Pi=/-(\w)/g,$e=Tn(e=>e.replace(Pi,(t,n)=>n?n.toUpperCase():"")),Ni=/\B([A-Z])/g,ft=Tn(e=>e.replace(Ni,"-$1").toLowerCase()),An=Tn(e=>e.charAt(0).toUpperCase()+e.slice(1)),un=Tn(e=>e?`on${An(e)}`:""),Qe=(e,t)=>!Object.is(e,t),fn=(e,...t)=>{for(let n=0;n<e.length;n++)e[n](...t)},eo=(e,t,n,r=!1)=>{Object.defineProperty(e,t,{configurable:!0,enumerable:!1,writable:r,value:n})},cr=e=>{const t=parseFloat(e);return isNaN(t)?e:t},Fi=e=>{const t=oe(e)?Number(e):NaN;return isNaN(t)?e:t};let Jr;const to=()=>Jr||(Jr=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:typeof global<"u"?global:{});function Sr(e){if(k(e)){const t={};for(let n=0;n<e.length;n++){const r=e[n],s=oe(r)?Vi(r):Sr(r);if(s)for(const o in s)t[o]=s[o]}return t}else if(oe(e)||Z(e))return e}const $i=/;(?![^(]*\))/g,Hi=/:([^]+)/,ji=/\/\*[^]*?\*\//g;function Vi(e){const t={};return e.replace(ji,"").split($i).forEach(n=>{if(n){const r=n.split(Hi);r.length>1&&(t[r[0].trim()]=r[1].trim())}}),t}function Tr(e){let t="";if(oe(e))t=e;else if(k(e))for(let n=0;n<e.length;n++){const r=Tr(e[n]);r&&(t+=r+" ")}else if(Z(e))for(const n in e)e[n]&&(t+=n+" ");return t.trim()}const Di="itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly",Ui=wr(Di);function no(e){return!!e||e===""}const nu=e=>oe(e)?e:e==null?"":k(e)||Z(e)&&(e.toString===Qs||!K(e.toString))?JSON.stringify(e,ro,2):String(e),ro=(e,t)=>t&&t.__v_isRef?ro(e,t.value):yt(t)?{[`Map(${t.size})`]:[...t.entries()].reduce((n,[r,s],o)=>(n[kn(r,o)+" =>"]=s,n),{})}:zs(t)?{[`Set(${t.size})`]:[...t.values()].map(n=>kn(n))}:et(t)?kn(t):Z(t)&&!k(t)&&!Zs(t)?String(t):t,kn=(e,t="")=>{var n;return et(e)?`Symbol(${(n=e.description)!=null?n:t})`:e};/**
|
||||
* @vue/reactivity v3.4.30
|
||||
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
||||
* @license MIT
|
||||
**/let we;class Bi{constructor(t=!1){this.detached=t,this._active=!0,this.effects=[],this.cleanups=[],this.parent=we,!t&&we&&(this.index=(we.scopes||(we.scopes=[])).push(this)-1)}get active(){return this._active}run(t){if(this._active){const n=we;try{return we=this,t()}finally{we=n}}}on(){we=this}off(){we=this.parent}stop(t){if(this._active){let n,r;for(n=0,r=this.effects.length;n<r;n++)this.effects[n].stop();for(n=0,r=this.cleanups.length;n<r;n++)this.cleanups[n]();if(this.scopes)for(n=0,r=this.scopes.length;n<r;n++)this.scopes[n].stop(!0);if(!this.detached&&this.parent&&!t){const s=this.parent.scopes.pop();s&&s!==this&&(this.parent.scopes[this.index]=s,s.index=this.index)}this.parent=void 0,this._active=!1}}}function ki(e,t=we){t&&t.active&&t.effects.push(e)}function so(){return we}function Ki(e){we&&we.cleanups.push(e)}let ct;class Ar{constructor(t,n,r,s){this.fn=t,this.trigger=n,this.scheduler=r,this.active=!0,this.deps=[],this._dirtyLevel=5,this._trackId=0,this._runnings=0,this._shouldSchedule=!1,this._depsLength=0,ki(this,s)}get dirty(){if(this._dirtyLevel===2)return!1;if(this._dirtyLevel===3||this._dirtyLevel===4){this._dirtyLevel=1,tt();for(let t=0;t<this._depsLength;t++){const n=this.deps[t];if(n.computed){if(n.computed.effect._dirtyLevel===2)return Ue(),!0;if(Wi(n.computed),this._dirtyLevel>=5)break}}this._dirtyLevel===1&&(this._dirtyLevel=0),Ue()}return this._dirtyLevel>=5}set dirty(t){this._dirtyLevel=t?5:0}run(){if(this._dirtyLevel=0,!this.active)return this.fn();let t=ze,n=ct;try{return ze=!0,ct=this,this._runnings++,Qr(this),this.fn()}finally{Zr(this),this._runnings--,ct=n,ze=t}}stop(){this.active&&(Qr(this),Zr(this),this.onStop&&this.onStop(),this.active=!1)}}function Wi(e){return e.value}function Qr(e){e._trackId++,e._depsLength=0}function Zr(e){if(e.deps.length>e._depsLength){for(let t=e._depsLength;t<e.deps.length;t++)oo(e.deps[t],e);e.deps.length=e._depsLength}}function oo(e,t){const n=e.get(t);n!==void 0&&t._trackId!==n&&(e.delete(t),e.size===0&&e.cleanup())}let ze=!0,ar=0;const io=[];function tt(){io.push(ze),ze=!1}function Ue(){const e=io.pop();ze=e===void 0?!0:e}function Rr(){ar++}function Or(){for(ar--;!ar&&ur.length;)ur.shift()()}function lo(e,t,n){if(t.get(e)!==e._trackId){t.set(e,e._trackId);const r=e.deps[e._depsLength];r!==t?(r&&oo(r,e),e.deps[e._depsLength++]=t):e._depsLength++}}const ur=[];function co(e,t,n){Rr();for(const r of e.keys()){let s;if(!e.computed&&r.computed&&r._runnings>0&&(s??(s=e.get(r)===r._trackId))){r._dirtyLevel=2;continue}r._dirtyLevel<t&&(s??(s=e.get(r)===r._trackId))&&(r._shouldSchedule||(r._shouldSchedule=r._dirtyLevel===0),r.computed&&r._dirtyLevel===2&&(r._shouldSchedule=!0),r._dirtyLevel=t),r._shouldSchedule&&(s??(s=e.get(r)===r._trackId))&&(r.trigger(),(!r._runnings||r.allowRecurse)&&r._dirtyLevel!==3&&(r._shouldSchedule=!1,r.scheduler&&ur.push(r.scheduler)))}Or()}const ao=(e,t)=>{const n=new Map;return n.cleanup=e,n.computed=t,n},mn=new WeakMap,at=Symbol(""),fr=Symbol("");function ve(e,t,n){if(ze&&ct){let r=mn.get(e);r||mn.set(e,r=new Map);let s=r.get(n);s||r.set(n,s=ao(()=>r.delete(n))),lo(ct,s)}}function De(e,t,n,r,s,o){const i=mn.get(e);if(!i)return;let l=[];if(t==="clear")l=[...i.values()];else if(n==="length"&&k(e)){const c=Number(r);i.forEach((a,f)=>{(f==="length"||!et(f)&&f>=c)&&l.push(a)})}else switch(n!==void 0&&l.push(i.get(n)),t){case"add":k(e)?xr(n)&&l.push(i.get("length")):(l.push(i.get(at)),yt(e)&&l.push(i.get(fr)));break;case"delete":k(e)||(l.push(i.get(at)),yt(e)&&l.push(i.get(fr)));break;case"set":yt(e)&&l.push(i.get(at));break}Rr();for(const c of l)c&&co(c,5);Or()}function qi(e,t){const n=mn.get(e);return n&&n.get(t)}const Gi=wr("__proto__,__v_isRef,__isVue"),uo=new Set(Object.getOwnPropertyNames(Symbol).filter(e=>e!=="arguments"&&e!=="caller").map(e=>Symbol[e]).filter(et)),es=Xi();function Xi(){const e={};return["includes","indexOf","lastIndexOf"].forEach(t=>{e[t]=function(...n){const r=J(this);for(let o=0,i=this.length;o<i;o++)ve(r,"get",o+"");const s=r[t](...n);return s===-1||s===!1?r[t](...n.map(J)):s}}),["push","pop","shift","unshift","splice"].forEach(t=>{e[t]=function(...n){tt(),Rr();const r=J(this)[t].apply(this,n);return Or(),Ue(),r}}),e}function Yi(e){et(e)||(e=String(e));const t=J(this);return ve(t,"has",e),t.hasOwnProperty(e)}class fo{constructor(t=!1,n=!1){this._isReadonly=t,this._isShallow=n}get(t,n,r){const s=this._isReadonly,o=this._isShallow;if(n==="__v_isReactive")return!s;if(n==="__v_isReadonly")return s;if(n==="__v_isShallow")return o;if(n==="__v_raw")return r===(s?o?cl:mo:o?go:po).get(t)||Object.getPrototypeOf(t)===Object.getPrototypeOf(r)?t:void 0;const i=k(t);if(!s){if(i&&z(es,n))return Reflect.get(es,n,r);if(n==="hasOwnProperty")return Yi}const l=Reflect.get(t,n,r);return(et(n)?uo.has(n):Gi(n))||(s||ve(t,"get",n),o)?l:de(l)?i&&xr(n)?l:l.value:Z(l)?s?Ln(l):On(l):l}}class ho extends fo{constructor(t=!1){super(!1,t)}set(t,n,r,s){let o=t[n];if(!this._isShallow){const c=$t(o);if(!yn(r)&&!$t(r)&&(o=J(o),r=J(r)),!k(t)&&de(o)&&!de(r))return c?!1:(o.value=r,!0)}const i=k(t)&&xr(n)?Number(n)<t.length:z(t,n),l=Reflect.set(t,n,r,s);return t===J(s)&&(i?Qe(r,o)&&De(t,"set",n,r):De(t,"add",n,r)),l}deleteProperty(t,n){const r=z(t,n);t[n];const s=Reflect.deleteProperty(t,n);return s&&r&&De(t,"delete",n,void 0),s}has(t,n){const r=Reflect.has(t,n);return(!et(n)||!uo.has(n))&&ve(t,"has",n),r}ownKeys(t){return ve(t,"iterate",k(t)?"length":at),Reflect.ownKeys(t)}}class zi extends fo{constructor(t=!1){super(!0,t)}set(t,n){return!0}deleteProperty(t,n){return!0}}const Ji=new ho,Qi=new zi,Zi=new ho(!0);const Lr=e=>e,Rn=e=>Reflect.getPrototypeOf(e);function zt(e,t,n=!1,r=!1){e=e.__v_raw;const s=J(e),o=J(t);n||(Qe(t,o)&&ve(s,"get",t),ve(s,"get",o));const{has:i}=Rn(s),l=r?Lr:n?Pr:Ht;if(i.call(s,t))return l(e.get(t));if(i.call(s,o))return l(e.get(o));e!==s&&e.get(t)}function Jt(e,t=!1){const n=this.__v_raw,r=J(n),s=J(e);return t||(Qe(e,s)&&ve(r,"has",e),ve(r,"has",s)),e===s?n.has(e):n.has(e)||n.has(s)}function Qt(e,t=!1){return e=e.__v_raw,!t&&ve(J(e),"iterate",at),Reflect.get(e,"size",e)}function ts(e){e=J(e);const t=J(this);return Rn(t).has.call(t,e)||(t.add(e),De(t,"add",e,e)),this}function ns(e,t){t=J(t);const n=J(this),{has:r,get:s}=Rn(n);let o=r.call(n,e);o||(e=J(e),o=r.call(n,e));const i=s.call(n,e);return n.set(e,t),o?Qe(t,i)&&De(n,"set",e,t):De(n,"add",e,t),this}function rs(e){const t=J(this),{has:n,get:r}=Rn(t);let s=n.call(t,e);s||(e=J(e),s=n.call(t,e)),r&&r.call(t,e);const o=t.delete(e);return s&&De(t,"delete",e,void 0),o}function ss(){const e=J(this),t=e.size!==0,n=e.clear();return t&&De(e,"clear",void 0,void 0),n}function Zt(e,t){return function(r,s){const o=this,i=o.__v_raw,l=J(i),c=t?Lr:e?Pr:Ht;return!e&&ve(l,"iterate",at),i.forEach((a,f)=>r.call(s,c(a),c(f),o))}}function en(e,t,n){return function(...r){const s=this.__v_raw,o=J(s),i=yt(o),l=e==="entries"||e===Symbol.iterator&&i,c=e==="keys"&&i,a=s[e](...r),f=n?Lr:t?Pr:Ht;return!t&&ve(o,"iterate",c?fr:at),{next(){const{value:h,done:m}=a.next();return m?{value:h,done:m}:{value:l?[f(h[0]),f(h[1])]:f(h),done:m}},[Symbol.iterator](){return this}}}}function ke(e){return function(...t){return e==="delete"?!1:e==="clear"?void 0:this}}function el(){const e={get(o){return zt(this,o)},get size(){return Qt(this)},has:Jt,add:ts,set:ns,delete:rs,clear:ss,forEach:Zt(!1,!1)},t={get(o){return zt(this,o,!1,!0)},get size(){return Qt(this)},has:Jt,add:ts,set:ns,delete:rs,clear:ss,forEach:Zt(!1,!0)},n={get(o){return zt(this,o,!0)},get size(){return Qt(this,!0)},has(o){return Jt.call(this,o,!0)},add:ke("add"),set:ke("set"),delete:ke("delete"),clear:ke("clear"),forEach:Zt(!0,!1)},r={get(o){return zt(this,o,!0,!0)},get size(){return Qt(this,!0)},has(o){return Jt.call(this,o,!0)},add:ke("add"),set:ke("set"),delete:ke("delete"),clear:ke("clear"),forEach:Zt(!0,!0)};return["keys","values","entries",Symbol.iterator].forEach(o=>{e[o]=en(o,!1,!1),n[o]=en(o,!0,!1),t[o]=en(o,!1,!0),r[o]=en(o,!0,!0)}),[e,n,t,r]}const[tl,nl,rl,sl]=el();function Ir(e,t){const n=t?e?sl:rl:e?nl:tl;return(r,s,o)=>s==="__v_isReactive"?!e:s==="__v_isReadonly"?e:s==="__v_raw"?r:Reflect.get(z(n,s)&&s in r?n:r,s,o)}const ol={get:Ir(!1,!1)},il={get:Ir(!1,!0)},ll={get:Ir(!0,!1)};const po=new WeakMap,go=new WeakMap,mo=new WeakMap,cl=new WeakMap;function al(e){switch(e){case"Object":case"Array":return 1;case"Map":case"Set":case"WeakMap":case"WeakSet":return 2;default:return 0}}function ul(e){return e.__v_skip||!Object.isExtensible(e)?0:al(Mi(e))}function On(e){return $t(e)?e:Mr(e,!1,Ji,ol,po)}function fl(e){return Mr(e,!1,Zi,il,go)}function Ln(e){return Mr(e,!0,Qi,ll,mo)}function Mr(e,t,n,r,s){if(!Z(e)||e.__v_raw&&!(t&&e.__v_isReactive))return e;const o=s.get(e);if(o)return o;const i=ul(e);if(i===0)return e;const l=new Proxy(e,i===2?r:n);return s.set(e,l),l}function Rt(e){return $t(e)?Rt(e.__v_raw):!!(e&&e.__v_isReactive)}function $t(e){return!!(e&&e.__v_isReadonly)}function yn(e){return!!(e&&e.__v_isShallow)}function yo(e){return e?!!e.__v_raw:!1}function J(e){const t=e&&e.__v_raw;return t?J(t):e}function dn(e){return Object.isExtensible(e)&&eo(e,"__v_skip",!0),e}const Ht=e=>Z(e)?On(e):e,Pr=e=>Z(e)?Ln(e):e;class _o{constructor(t,n,r,s){this.getter=t,this._setter=n,this.dep=void 0,this.__v_isRef=!0,this.__v_isReadonly=!1,this.effect=new Ar(()=>t(this._value),()=>Ot(this,this.effect._dirtyLevel===3?3:4)),this.effect.computed=this,this.effect.active=this._cacheable=!s,this.__v_isReadonly=r}get value(){const t=J(this),n=t.effect._dirtyLevel;return(!t._cacheable||t.effect.dirty)&&Qe(t._value,t._value=t.effect.run())&&n!==3&&Ot(t,5),Nr(t),t.effect._dirtyLevel>=2&&Ot(t,3),t._value}set value(t){this._setter(t)}get _dirty(){return this.effect.dirty}set _dirty(t){this.effect.dirty=t}}function dl(e,t,n=!1){let r,s;const o=K(e);return o?(r=e,s=xe):(r=e.get,s=e.set),new _o(r,s,o||!s,n)}function Nr(e){var t;ze&&ct&&(e=J(e),lo(ct,(t=e.dep)!=null?t:e.dep=ao(()=>e.dep=void 0,e instanceof _o?e:void 0)))}function Ot(e,t=5,n,r){e=J(e);const s=e.dep;s&&co(s,t)}function de(e){return!!(e&&e.__v_isRef===!0)}function se(e){return vo(e,!1)}function Fr(e){return vo(e,!0)}function vo(e,t){return de(e)?e:new hl(e,t)}class hl{constructor(t,n){this.__v_isShallow=n,this.dep=void 0,this.__v_isRef=!0,this._rawValue=n?t:J(t),this._value=n?t:Ht(t)}get value(){return Nr(this),this._value}set value(t){const n=this.__v_isShallow||yn(t)||$t(t);t=n?t:J(t),Qe(t,this._rawValue)&&(this._rawValue,this._rawValue=t,this._value=n?t:Ht(t),Ot(this,5))}}function bo(e){return de(e)?e.value:e}const pl={get:(e,t,n)=>bo(Reflect.get(e,t,n)),set:(e,t,n,r)=>{const s=e[t];return de(s)&&!de(n)?(s.value=n,!0):Reflect.set(e,t,n,r)}};function wo(e){return Rt(e)?e:new Proxy(e,pl)}class gl{constructor(t){this.dep=void 0,this.__v_isRef=!0;const{get:n,set:r}=t(()=>Nr(this),()=>Ot(this));this._get=n,this._set=r}get value(){return this._get()}set value(t){this._set(t)}}function ml(e){return new gl(e)}class yl{constructor(t,n,r){this._object=t,this._key=n,this._defaultValue=r,this.__v_isRef=!0}get value(){const t=this._object[this._key];return t===void 0?this._defaultValue:t}set value(t){this._object[this._key]=t}get dep(){return qi(J(this._object),this._key)}}class _l{constructor(t){this._getter=t,this.__v_isRef=!0,this.__v_isReadonly=!0}get value(){return this._getter()}}function vl(e,t,n){return de(e)?e:K(e)?new _l(e):Z(e)&&arguments.length>1?bl(e,t,n):se(e)}function bl(e,t,n){const r=e[t];return de(r)?r:new yl(e,t,n)}/**
|
||||
* @vue/runtime-core v3.4.30
|
||||
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
||||
* @license MIT
|
||||
**/function Je(e,t,n,r){try{return r?e(...r):e()}catch(s){Kt(s,t,n)}}function Se(e,t,n,r){if(K(e)){const s=Je(e,t,n,r);return s&&Js(s)&&s.catch(o=>{Kt(o,t,n)}),s}if(k(e)){const s=[];for(let o=0;o<e.length;o++)s.push(Se(e[o],t,n,r));return s}}function Kt(e,t,n,r=!0){const s=t?t.vnode:null;if(t){let o=t.parent;const i=t.proxy,l=`https://vuejs.org/error-reference/#runtime-${n}`;for(;o;){const a=o.ec;if(a){for(let f=0;f<a.length;f++)if(a[f](e,i,l)===!1)return}o=o.parent}const c=t.appContext.config.errorHandler;if(c){tt(),Je(c,null,10,[e,i,l]),Ue();return}}wl(e,n,s,r)}function wl(e,t,n,r=!0){console.error(e)}let jt=!1,dr=!1;const pe=[];let Pe=0;const vt=[];let qe=null,it=0;const Eo=Promise.resolve();let $r=null;function In(e){const t=$r||Eo;return e?t.then(this?e.bind(this):e):t}function El(e){let t=Pe+1,n=pe.length;for(;t<n;){const r=t+n>>>1,s=pe[r],o=Vt(s);o<e||o===e&&s.pre?t=r+1:n=r}return t}function Mn(e){(!pe.length||!pe.includes(e,jt&&e.allowRecurse?Pe+1:Pe))&&(e.id==null?pe.push(e):pe.splice(El(e.id),0,e),Co())}function Co(){!jt&&!dr&&(dr=!0,$r=Eo.then(xo))}function Cl(e){const t=pe.indexOf(e);t>Pe&&pe.splice(t,1)}function xl(e){k(e)?vt.push(...e):(!qe||!qe.includes(e,e.allowRecurse?it+1:it))&&vt.push(e),Co()}function os(e,t,n=jt?Pe+1:0){for(;n<pe.length;n++){const r=pe[n];if(r&&r.pre){if(e&&r.id!==e.uid)continue;pe.splice(n,1),n--,r()}}}function _n(e){if(vt.length){const t=[...new Set(vt)].sort((n,r)=>Vt(n)-Vt(r));if(vt.length=0,qe){qe.push(...t);return}for(qe=t,it=0;it<qe.length;it++){const n=qe[it];n.active!==!1&&n()}qe=null,it=0}}const Vt=e=>e.id==null?1/0:e.id,Sl=(e,t)=>{const n=Vt(e)-Vt(t);if(n===0){if(e.pre&&!t.pre)return-1;if(t.pre&&!e.pre)return 1}return n};function xo(e){dr=!1,jt=!0,pe.sort(Sl);try{for(Pe=0;Pe<pe.length;Pe++){const t=pe[Pe];t&&t.active!==!1&&Je(t,null,14)}}finally{Pe=0,pe.length=0,_n(),jt=!1,$r=null,(pe.length||vt.length)&&xo()}}function Tl(e,t,...n){if(e.isUnmounted)return;const r=e.vnode.props||te;let s=n;const o=t.startsWith("update:"),i=o&&t.slice(7);if(i&&i in r){const f=`${i==="modelValue"?"model":i}Modifiers`,{number:h,trim:m}=r[f]||te;m&&(s=n.map(_=>oe(_)?_.trim():_)),h&&(s=n.map(cr))}let l,c=r[l=un(t)]||r[l=un($e(t))];!c&&o&&(c=r[l=un(ft(t))]),c&&Se(c,e,6,s);const a=r[l+"Once"];if(a){if(!e.emitted)e.emitted={};else if(e.emitted[l])return;e.emitted[l]=!0,Se(a,e,6,s)}}function So(e,t,n=!1){const r=t.emitsCache,s=r.get(e);if(s!==void 0)return s;const o=e.emits;let i={},l=!1;if(!K(e)){const c=a=>{const f=So(a,t,!0);f&&(l=!0,le(i,f))};!n&&t.mixins.length&&t.mixins.forEach(c),e.extends&&c(e.extends),e.mixins&&e.mixins.forEach(c)}return!o&&!l?(Z(e)&&r.set(e,null),null):(k(o)?o.forEach(c=>i[c]=null):le(i,o),Z(e)&&r.set(e,i),i)}function Pn(e,t){return!e||!kt(t)?!1:(t=t.slice(2).replace(/Once$/,""),z(e,t[0].toLowerCase()+t.slice(1))||z(e,ft(t))||z(e,t))}let fe=null,Nn=null;function vn(e){const t=fe;return fe=e,Nn=e&&e.type.__scopeId||null,t}function ru(e){Nn=e}function su(){Nn=null}function Al(e,t=fe,n){if(!t||e._n)return e;const r=(...s)=>{r._d&&ws(-1);const o=vn(t);let i;try{i=e(...s)}finally{vn(o),r._d&&ws(1)}return i};return r._n=!0,r._c=!0,r._d=!0,r}function Kn(e){const{type:t,vnode:n,proxy:r,withProxy:s,propsOptions:[o],slots:i,attrs:l,emit:c,render:a,renderCache:f,props:h,data:m,setupState:_,ctx:C,inheritAttrs:I}=e,H=vn(e);let W,D;try{if(n.shapeFlag&4){const y=s||r,M=y;W=Ae(a.call(M,y,f,h,_,m,C)),D=l}else{const y=t;W=Ae(y.length>1?y(h,{attrs:l,slots:i,emit:c}):y(h,null)),D=t.props?l:Rl(l)}}catch(y){Nt.length=0,Kt(y,e,1),W=ie(me)}let p=W;if(D&&I!==!1){const y=Object.keys(D),{shapeFlag:M}=p;y.length&&M&7&&(o&&y.some(Er)&&(D=Ol(D,o)),p=Ze(p,D,!1,!0))}return n.dirs&&(p=Ze(p,null,!1,!0),p.dirs=p.dirs?p.dirs.concat(n.dirs):n.dirs),n.transition&&(p.transition=n.transition),W=p,vn(H),W}const Rl=e=>{let t;for(const n in e)(n==="class"||n==="style"||kt(n))&&((t||(t={}))[n]=e[n]);return t},Ol=(e,t)=>{const n={};for(const r in e)(!Er(r)||!(r.slice(9)in t))&&(n[r]=e[r]);return n};function Ll(e,t,n){const{props:r,children:s,component:o}=e,{props:i,children:l,patchFlag:c}=t,a=o.emitsOptions;if(t.dirs||t.transition)return!0;if(n&&c>=0){if(c&1024)return!0;if(c&16)return r?is(r,i,a):!!i;if(c&8){const f=t.dynamicProps;for(let h=0;h<f.length;h++){const m=f[h];if(i[m]!==r[m]&&!Pn(a,m))return!0}}}else return(s||l)&&(!l||!l.$stable)?!0:r===i?!1:r?i?is(r,i,a):!0:!!i;return!1}function is(e,t,n){const r=Object.keys(t);if(r.length!==Object.keys(e).length)return!0;for(let s=0;s<r.length;s++){const o=r[s];if(t[o]!==e[o]&&!Pn(n,o))return!0}return!1}function Il({vnode:e,parent:t},n){for(;t;){const r=t.subTree;if(r.suspense&&r.suspense.activeBranch===e&&(r.el=e.el),r===e)(e=t.vnode).el=n,t=t.parent;else break}}const To="components";function ou(e,t){return Ro(To,e,!0,t)||e}const Ao=Symbol.for("v-ndc");function iu(e){return oe(e)?Ro(To,e,!1)||e:e||Ao}function Ro(e,t,n=!0,r=!1){const s=fe||ue;if(s){const o=s.type;{const l=Oc(o,!1);if(l&&(l===t||l===$e(t)||l===An($e(t))))return o}const i=ls(s[e]||o[e],t)||ls(s.appContext[e],t);return!i&&r?o:i}}function ls(e,t){return e&&(e[t]||e[$e(t)]||e[An($e(t))])}const Ml=e=>e.__isSuspense;function Oo(e,t){t&&t.pendingBranch?k(e)?t.effects.push(...e):t.effects.push(e):xl(e)}function Fn(e,t,n=ue,r=!1){if(n){const s=n[e]||(n[e]=[]),o=t.__weh||(t.__weh=(...i)=>{tt();const l=qt(n),c=Se(t,n,e,i);return l(),Ue(),c});return r?s.unshift(o):s.push(o),o}}const Be=e=>(t,n=ue)=>{(!Gt||e==="sp")&&Fn(e,(...r)=>t(...r),n)},Pl=Be("bm"),xt=Be("m"),Nl=Be("bu"),Fl=Be("u"),Lo=Be("bum"),$n=Be("um"),$l=Be("sp"),Hl=Be("rtg"),jl=Be("rtc");function Vl(e,t=ue){Fn("ec",e,t)}function lu(e,t){if(fe===null)return e;const n=Vn(fe),r=e.dirs||(e.dirs=[]);for(let s=0;s<t.length;s++){let[o,i,l,c=te]=t[s];o&&(K(o)&&(o={mounted:o,updated:o}),o.deep&&Ye(i),r.push({dir:o,instance:n,value:i,oldValue:void 0,arg:l,modifiers:c}))}return e}function Me(e,t,n,r){const s=e.dirs,o=t&&t.dirs;for(let i=0;i<s.length;i++){const l=s[i];o&&(l.oldValue=o[i].value);let c=l.dir[r];c&&(tt(),Se(c,n,8,[e.el,l,e,t]),Ue())}}function cu(e,t,n,r){let s;const o=n;if(k(e)||oe(e)){s=new Array(e.length);for(let i=0,l=e.length;i<l;i++)s[i]=t(e[i],i,void 0,o)}else if(typeof e=="number"){s=new Array(e);for(let i=0;i<e;i++)s[i]=t(i+1,i,void 0,o)}else if(Z(e))if(e[Symbol.iterator])s=Array.from(e,(i,l)=>t(i,l,void 0,o));else{const i=Object.keys(e);s=new Array(i.length);for(let l=0,c=i.length;l<c;l++){const a=i[l];s[l]=t(e[a],a,l,o)}}else s=[];return s}/*! #__NO_SIDE_EFFECTS__ */function Hr(e,t){return K(e)?le({name:e.name},t,{setup:e}):e}const bt=e=>!!e.type.__asyncLoader;/*! #__NO_SIDE_EFFECTS__ */function au(e){K(e)&&(e={loader:e});const{loader:t,loadingComponent:n,errorComponent:r,delay:s=200,timeout:o,suspensible:i=!0,onError:l}=e;let c=null,a,f=0;const h=()=>(f++,c=null,m()),m=()=>{let _;return c||(_=c=t().catch(C=>{if(C=C instanceof Error?C:new Error(String(C)),l)return new Promise((I,H)=>{l(C,()=>I(h()),()=>H(C),f+1)});throw C}).then(C=>_!==c&&c?c:(C&&(C.__esModule||C[Symbol.toStringTag]==="Module")&&(C=C.default),a=C,C)))};return Hr({name:"AsyncComponentWrapper",__asyncLoader:m,get __asyncResolved(){return a},setup(){const _=ue;if(a)return()=>Wn(a,_);const C=D=>{c=null,Kt(D,_,13,!r)};if(i&&_.suspense||Gt)return m().then(D=>()=>Wn(D,_)).catch(D=>(C(D),()=>r?ie(r,{error:D}):null));const I=se(!1),H=se(),W=se(!!s);return s&&setTimeout(()=>{W.value=!1},s),o!=null&&setTimeout(()=>{if(!I.value&&!H.value){const D=new Error(`Async component timed out after ${o}ms.`);C(D),H.value=D}},o),m().then(()=>{I.value=!0,_.parent&&Wt(_.parent.vnode)&&(_.parent.effect.dirty=!0,Mn(_.parent.update))}).catch(D=>{C(D),H.value=D}),()=>{if(I.value&&a)return Wn(a,_);if(H.value&&r)return ie(r,{error:H.value});if(n&&!W.value)return ie(n)}}})}function Wn(e,t){const{ref:n,props:r,children:s,ce:o}=t.vnode,i=ie(e,r,s);return i.ref=n,i.ce=o,delete t.vnode.ce,i}function uu(e,t,n={},r,s){if(fe.isCE||fe.parent&&bt(fe.parent)&&fe.parent.isCE)return t!=="default"&&(n.name=t),ie("slot",n,r&&r());let o=e[t];o&&o._c&&(o._d=!1),Qo();const i=o&&Io(o(n)),l=ei(_e,{key:n.key||i&&i.key||`_${t}`},i||(r?r():[]),i&&e._===1?64:-2);return!s&&l.scopeId&&(l.slotScopeIds=[l.scopeId+"-s"]),o&&o._c&&(o._d=!0),l}function Io(e){return e.some(t=>Cn(t)?!(t.type===me||t.type===_e&&!Io(t.children)):!0)?e:null}function fu(e,t){const n={};for(const r in e)n[/[A-Z]/.test(r)?`on:${r}`:un(r)]=e[r];return n}const hr=e=>e?si(e)?Vn(e):hr(e.parent):null,Lt=le(Object.create(null),{$:e=>e,$el:e=>e.vnode.el,$data:e=>e.data,$props:e=>e.props,$attrs:e=>e.attrs,$slots:e=>e.slots,$refs:e=>e.refs,$parent:e=>hr(e.parent),$root:e=>hr(e.root),$emit:e=>e.emit,$options:e=>jr(e),$forceUpdate:e=>e.f||(e.f=()=>{e.effect.dirty=!0,Mn(e.update)}),$nextTick:e=>e.n||(e.n=In.bind(e.proxy)),$watch:e=>ac.bind(e)}),qn=(e,t)=>e!==te&&!e.__isScriptSetup&&z(e,t),Dl={get({_:e},t){if(t==="__v_skip")return!0;const{ctx:n,setupState:r,data:s,props:o,accessCache:i,type:l,appContext:c}=e;let a;if(t[0]!=="$"){const _=i[t];if(_!==void 0)switch(_){case 1:return r[t];case 2:return s[t];case 4:return n[t];case 3:return o[t]}else{if(qn(r,t))return i[t]=1,r[t];if(s!==te&&z(s,t))return i[t]=2,s[t];if((a=e.propsOptions[0])&&z(a,t))return i[t]=3,o[t];if(n!==te&&z(n,t))return i[t]=4,n[t];pr&&(i[t]=0)}}const f=Lt[t];let h,m;if(f)return t==="$attrs"&&ve(e.attrs,"get",""),f(e);if((h=l.__cssModules)&&(h=h[t]))return h;if(n!==te&&z(n,t))return i[t]=4,n[t];if(m=c.config.globalProperties,z(m,t))return m[t]},set({_:e},t,n){const{data:r,setupState:s,ctx:o}=e;return qn(s,t)?(s[t]=n,!0):r!==te&&z(r,t)?(r[t]=n,!0):z(e.props,t)||t[0]==="$"&&t.slice(1)in e?!1:(o[t]=n,!0)},has({_:{data:e,setupState:t,accessCache:n,ctx:r,appContext:s,propsOptions:o}},i){let l;return!!n[i]||e!==te&&z(e,i)||qn(t,i)||(l=o[0])&&z(l,i)||z(r,i)||z(Lt,i)||z(s.config.globalProperties,i)},defineProperty(e,t,n){return n.get!=null?e._.accessCache[t]=0:z(n,"value")&&this.set(e,t,n.value,null),Reflect.defineProperty(e,t,n)}};function du(){return Ul().slots}function Ul(){const e=jn();return e.setupContext||(e.setupContext=ii(e))}function cs(e){return k(e)?e.reduce((t,n)=>(t[n]=null,t),{}):e}let pr=!0;function Bl(e){const t=jr(e),n=e.proxy,r=e.ctx;pr=!1,t.beforeCreate&&as(t.beforeCreate,e,"bc");const{data:s,computed:o,methods:i,watch:l,provide:c,inject:a,created:f,beforeMount:h,mounted:m,beforeUpdate:_,updated:C,activated:I,deactivated:H,beforeDestroy:W,beforeUnmount:D,destroyed:p,unmounted:y,render:M,renderTracked:A,renderTriggered:F,errorCaptured:$,serverPrefetch:L,expose:w,inheritAttrs:N,components:T,directives:G,filters:ne}=t;if(a&&kl(a,r,null),i)for(const Y in i){const V=i[Y];K(V)&&(r[Y]=V.bind(n))}if(s){const Y=s.call(n,n);Z(Y)&&(e.data=On(Y))}if(pr=!0,o)for(const Y in o){const V=o[Y],He=K(V)?V.bind(n,n):K(V.get)?V.get.bind(n,n):xe,Xt=!K(V)&&K(V.set)?V.set.bind(n):xe,nt=re({get:He,set:Xt});Object.defineProperty(r,Y,{enumerable:!0,configurable:!0,get:()=>nt.value,set:Le=>nt.value=Le})}if(l)for(const Y in l)Mo(l[Y],r,n,Y);if(c){const Y=K(c)?c.call(n):c;Reflect.ownKeys(Y).forEach(V=>{Yl(V,Y[V])})}f&&as(f,e,"c");function U(Y,V){k(V)?V.forEach(He=>Y(He.bind(n))):V&&Y(V.bind(n))}if(U(Pl,h),U(xt,m),U(Nl,_),U(Fl,C),U(uc,I),U(fc,H),U(Vl,$),U(jl,A),U(Hl,F),U(Lo,D),U($n,y),U($l,L),k(w))if(w.length){const Y=e.exposed||(e.exposed={});w.forEach(V=>{Object.defineProperty(Y,V,{get:()=>n[V],set:He=>n[V]=He})})}else e.exposed||(e.exposed={});M&&e.render===xe&&(e.render=M),N!=null&&(e.inheritAttrs=N),T&&(e.components=T),G&&(e.directives=G)}function kl(e,t,n=xe){k(e)&&(e=gr(e));for(const r in e){const s=e[r];let o;Z(s)?"default"in s?o=wt(s.from||r,s.default,!0):o=wt(s.from||r):o=wt(s),de(o)?Object.defineProperty(t,r,{enumerable:!0,configurable:!0,get:()=>o.value,set:i=>o.value=i}):t[r]=o}}function as(e,t,n){Se(k(e)?e.map(r=>r.bind(t.proxy)):e.bind(t.proxy),t,n)}function Mo(e,t,n,r){const s=r.includes(".")?Wo(n,r):()=>n[r];if(oe(e)){const o=t[e];K(o)&&Ne(s,o)}else if(K(e))Ne(s,e.bind(n));else if(Z(e))if(k(e))e.forEach(o=>Mo(o,t,n,r));else{const o=K(e.handler)?e.handler.bind(n):t[e.handler];K(o)&&Ne(s,o,e)}}function jr(e){const t=e.type,{mixins:n,extends:r}=t,{mixins:s,optionsCache:o,config:{optionMergeStrategies:i}}=e.appContext,l=o.get(t);let c;return l?c=l:!s.length&&!n&&!r?c=t:(c={},s.length&&s.forEach(a=>bn(c,a,i,!0)),bn(c,t,i)),Z(t)&&o.set(t,c),c}function bn(e,t,n,r=!1){const{mixins:s,extends:o}=t;o&&bn(e,o,n,!0),s&&s.forEach(i=>bn(e,i,n,!0));for(const i in t)if(!(r&&i==="expose")){const l=Kl[i]||n&&n[i];e[i]=l?l(e[i],t[i]):t[i]}return e}const Kl={data:us,props:fs,emits:fs,methods:At,computed:At,beforeCreate:ge,created:ge,beforeMount:ge,mounted:ge,beforeUpdate:ge,updated:ge,beforeDestroy:ge,beforeUnmount:ge,destroyed:ge,unmounted:ge,activated:ge,deactivated:ge,errorCaptured:ge,serverPrefetch:ge,components:At,directives:At,watch:ql,provide:us,inject:Wl};function us(e,t){return t?e?function(){return le(K(e)?e.call(this,this):e,K(t)?t.call(this,this):t)}:t:e}function Wl(e,t){return At(gr(e),gr(t))}function gr(e){if(k(e)){const t={};for(let n=0;n<e.length;n++)t[e[n]]=e[n];return t}return e}function ge(e,t){return e?[...new Set([].concat(e,t))]:t}function At(e,t){return e?le(Object.create(null),e,t):t}function fs(e,t){return e?k(e)&&k(t)?[...new Set([...e,...t])]:le(Object.create(null),cs(e),cs(t??{})):t}function ql(e,t){if(!e)return t;if(!t)return e;const n=le(Object.create(null),e);for(const r in t)n[r]=ge(e[r],t[r]);return n}function Po(){return{app:null,config:{isNativeTag:Li,performance:!1,globalProperties:{},optionMergeStrategies:{},errorHandler:void 0,warnHandler:void 0,compilerOptions:{}},mixins:[],components:{},directives:{},provides:Object.create(null),optionsCache:new WeakMap,propsCache:new WeakMap,emitsCache:new WeakMap}}let Gl=0;function Xl(e,t){return function(r,s=null){K(r)||(r=le({},r)),s!=null&&!Z(s)&&(s=null);const o=Po(),i=new WeakSet;let l=!1;const c=o.app={_uid:Gl++,_component:r,_props:s,_container:null,_context:o,_instance:null,version:Ic,get config(){return o.config},set config(a){},use(a,...f){return i.has(a)||(a&&K(a.install)?(i.add(a),a.install(c,...f)):K(a)&&(i.add(a),a(c,...f))),c},mixin(a){return o.mixins.includes(a)||o.mixins.push(a),c},component(a,f){return f?(o.components[a]=f,c):o.components[a]},directive(a,f){return f?(o.directives[a]=f,c):o.directives[a]},mount(a,f,h){if(!l){const m=ie(r,s);return m.appContext=o,h===!0?h="svg":h===!1&&(h=void 0),f&&t?t(m,a):e(m,a,h),l=!0,c._container=a,a.__vue_app__=c,Vn(m.component)}},unmount(){l&&(e(null,c._container),delete c._container.__vue_app__)},provide(a,f){return o.provides[a]=f,c},runWithContext(a){const f=It;It=c;try{return a()}finally{It=f}}};return c}}let It=null;function Yl(e,t){if(ue){let n=ue.provides;const r=ue.parent&&ue.parent.provides;r===n&&(n=ue.provides=Object.create(r)),n[e]=t}}function wt(e,t,n=!1){const r=ue||fe;if(r||It){const s=r?r.parent==null?r.vnode.appContext&&r.vnode.appContext.provides:r.parent.provides:It._context.provides;if(s&&e in s)return s[e];if(arguments.length>1)return n&&K(t)?t.call(r&&r.proxy):t}}const No={},Fo=()=>Object.create(No),$o=e=>Object.getPrototypeOf(e)===No;function zl(e,t,n,r=!1){const s={},o=Fo();e.propsDefaults=Object.create(null),Ho(e,t,s,o);for(const i in e.propsOptions[0])i in s||(s[i]=void 0);n?e.props=r?s:fl(s):e.type.props?e.props=s:e.props=o,e.attrs=o}function Jl(e,t,n,r){const{props:s,attrs:o,vnode:{patchFlag:i}}=e,l=J(s),[c]=e.propsOptions;let a=!1;if((r||i>0)&&!(i&16)){if(i&8){const f=e.vnode.dynamicProps;for(let h=0;h<f.length;h++){let m=f[h];if(Pn(e.emitsOptions,m))continue;const _=t[m];if(c)if(z(o,m))_!==o[m]&&(o[m]=_,a=!0);else{const C=$e(m);s[C]=mr(c,l,C,_,e,!1)}else _!==o[m]&&(o[m]=_,a=!0)}}}else{Ho(e,t,s,o)&&(a=!0);let f;for(const h in l)(!t||!z(t,h)&&((f=ft(h))===h||!z(t,f)))&&(c?n&&(n[h]!==void 0||n[f]!==void 0)&&(s[h]=mr(c,l,h,void 0,e,!0)):delete s[h]);if(o!==l)for(const h in o)(!t||!z(t,h))&&(delete o[h],a=!0)}a&&De(e.attrs,"set","")}function Ho(e,t,n,r){const[s,o]=e.propsOptions;let i=!1,l;if(t)for(let c in t){if(_t(c))continue;const a=t[c];let f;s&&z(s,f=$e(c))?!o||!o.includes(f)?n[f]=a:(l||(l={}))[f]=a:Pn(e.emitsOptions,c)||(!(c in r)||a!==r[c])&&(r[c]=a,i=!0)}if(o){const c=J(n),a=l||te;for(let f=0;f<o.length;f++){const h=o[f];n[h]=mr(s,c,h,a[h],e,!z(a,h))}}return i}function mr(e,t,n,r,s,o){const i=e[n];if(i!=null){const l=z(i,"default");if(l&&r===void 0){const c=i.default;if(i.type!==Function&&!i.skipFactory&&K(c)){const{propsDefaults:a}=s;if(n in a)r=a[n];else{const f=qt(s);r=a[n]=c.call(null,t),f()}}else r=c}i[0]&&(o&&!l?r=!1:i[1]&&(r===""||r===ft(n))&&(r=!0))}return r}function jo(e,t,n=!1){const r=t.propsCache,s=r.get(e);if(s)return s;const o=e.props,i={},l=[];let c=!1;if(!K(e)){const f=h=>{c=!0;const[m,_]=jo(h,t,!0);le(i,m),_&&l.push(..._)};!n&&t.mixins.length&&t.mixins.forEach(f),e.extends&&f(e.extends),e.mixins&&e.mixins.forEach(f)}if(!o&&!c)return Z(e)&&r.set(e,mt),mt;if(k(o))for(let f=0;f<o.length;f++){const h=$e(o[f]);ds(h)&&(i[h]=te)}else if(o)for(const f in o){const h=$e(f);if(ds(h)){const m=o[f],_=i[h]=k(m)||K(m)?{type:m}:le({},m);if(_){const C=gs(Boolean,_.type),I=gs(String,_.type);_[0]=C>-1,_[1]=I<0||C<I,(C>-1||z(_,"default"))&&l.push(h)}}}const a=[i,l];return Z(e)&&r.set(e,a),a}function ds(e){return e[0]!=="$"&&!_t(e)}function hs(e){return e===null?"null":typeof e=="function"?e.name||"":typeof e=="object"&&e.constructor&&e.constructor.name||""}function ps(e,t){return hs(e)===hs(t)}function gs(e,t){return k(t)?t.findIndex(n=>ps(n,e)):K(t)&&ps(t,e)?0:-1}const Vo=e=>e[0]==="_"||e==="$stable",Vr=e=>k(e)?e.map(Ae):[Ae(e)],Ql=(e,t,n)=>{if(t._n)return t;const r=Al((...s)=>Vr(t(...s)),n);return r._c=!1,r},Do=(e,t,n)=>{const r=e._ctx;for(const s in e){if(Vo(s))continue;const o=e[s];if(K(o))t[s]=Ql(s,o,r);else if(o!=null){const i=Vr(o);t[s]=()=>i}}},Uo=(e,t)=>{const n=Vr(t);e.slots.default=()=>n},Zl=(e,t)=>{const n=e.slots=Fo();if(e.vnode.shapeFlag&32){const r=t._;r?(le(n,t),eo(n,"_",r,!0)):Do(t,n)}else t&&Uo(e,t)},ec=(e,t,n)=>{const{vnode:r,slots:s}=e;let o=!0,i=te;if(r.shapeFlag&32){const l=t._;l?n&&l===1?o=!1:(le(s,t),!n&&l===1&&delete s._):(o=!t.$stable,Do(t,s)),i=t}else t&&(Uo(e,t),i={default:1});if(o)for(const l in s)!Vo(l)&&i[l]==null&&delete s[l]};function wn(e,t,n,r,s=!1){if(k(e)){e.forEach((m,_)=>wn(m,t&&(k(t)?t[_]:t),n,r,s));return}if(bt(r)&&!s)return;const o=r.shapeFlag&4?Vn(r.component):r.el,i=s?null:o,{i:l,r:c}=e,a=t&&t.r,f=l.refs===te?l.refs={}:l.refs,h=l.setupState;if(a!=null&&a!==c&&(oe(a)?(f[a]=null,z(h,a)&&(h[a]=null)):de(a)&&(a.value=null)),K(c))Je(c,l,12,[i,f]);else{const m=oe(c),_=de(c);if(m||_){const C=()=>{if(e.f){const I=m?z(h,c)?h[c]:f[c]:c.value;s?k(I)&&Cr(I,o):k(I)?I.includes(o)||I.push(o):m?(f[c]=[o],z(h,c)&&(h[c]=f[c])):(c.value=[o],e.k&&(f[e.k]=c.value))}else m?(f[c]=i,z(h,c)&&(h[c]=i)):_&&(c.value=i,e.k&&(f[e.k]=i))};i?(C.id=-1,ye(C,n)):C()}}}let ms=!1;const pt=()=>{ms||(console.error("Hydration completed but contains mismatches."),ms=!0)},tc=e=>e.namespaceURI.includes("svg")&&e.tagName!=="foreignObject",nc=e=>e.namespaceURI.includes("MathML"),tn=e=>{if(tc(e))return"svg";if(nc(e))return"mathml"},nn=e=>e.nodeType===8;function rc(e){const{mt:t,p:n,o:{patchProp:r,createText:s,nextSibling:o,parentNode:i,remove:l,insert:c,createComment:a}}=e,f=(p,y)=>{if(!y.hasChildNodes()){n(null,p,y),_n(),y._vnode=p;return}h(y.firstChild,p,null,null,null),_n(),y._vnode=p},h=(p,y,M,A,F,$=!1)=>{$=$||!!y.dynamicChildren;const L=nn(p)&&p.data==="[",w=()=>I(p,y,M,A,F,L),{type:N,ref:T,shapeFlag:G,patchFlag:ne}=y;let ce=p.nodeType;y.el=p,ne===-2&&($=!1,y.dynamicChildren=null);let U=null;switch(N){case Et:ce!==3?y.children===""?(c(y.el=s(""),i(p),p),U=p):U=w():(p.data!==y.children&&(pt(),p.data=y.children),U=o(p));break;case me:D(p)?(U=o(p),W(y.el=p.content.firstChild,p,M)):ce!==8||L?U=w():U=o(p);break;case Pt:if(L&&(p=o(p),ce=p.nodeType),ce===1||ce===3){U=p;const Y=!y.children.length;for(let V=0;V<y.staticCount;V++)Y&&(y.children+=U.nodeType===1?U.outerHTML:U.data),V===y.staticCount-1&&(y.anchor=U),U=o(U);return L?o(U):U}else w();break;case _e:L?U=C(p,y,M,A,F,$):U=w();break;default:if(G&1)(ce!==1||y.type.toLowerCase()!==p.tagName.toLowerCase())&&!D(p)?U=w():U=m(p,y,M,A,F,$);else if(G&6){y.slotScopeIds=F;const Y=i(p);if(L?U=H(p):nn(p)&&p.data==="teleport start"?U=H(p,p.data,"teleport end"):U=o(p),t(y,Y,null,M,A,tn(Y),$),bt(y)){let V;L?(V=ie(_e),V.anchor=U?U.previousSibling:Y.lastChild):V=p.nodeType===3?ri(""):ie("div"),V.el=p,y.component.subTree=V}}else G&64?ce!==8?U=w():U=y.type.hydrate(p,y,M,A,F,$,e,_):G&128&&(U=y.type.hydrate(p,y,M,A,tn(i(p)),F,$,e,h))}return T!=null&&wn(T,null,A,y),U},m=(p,y,M,A,F,$)=>{$=$||!!y.dynamicChildren;const{type:L,props:w,patchFlag:N,shapeFlag:T,dirs:G,transition:ne}=y,ce=L==="input"||L==="option";if(ce||N!==-1){G&&Me(y,null,M,"created");let U=!1;if(D(p)){U=ko(A,ne)&&M&&M.vnode.props&&M.vnode.props.appear;const V=p.content.firstChild;U&&ne.beforeEnter(V),W(V,p,M),y.el=p=V}if(T&16&&!(w&&(w.innerHTML||w.textContent))){let V=_(p.firstChild,y,p,M,A,F,$);for(;V;){pt();const He=V;V=V.nextSibling,l(He)}}else T&8&&p.textContent!==y.children&&(pt(),p.textContent=y.children);if(w)if(ce||!$||N&48)for(const V in w)(ce&&(V.endsWith("value")||V==="indeterminate")||kt(V)&&!_t(V)||V[0]===".")&&r(p,V,null,w[V],void 0,void 0,M);else w.onClick&&r(p,"onClick",null,w.onClick,void 0,void 0,M);let Y;(Y=w&&w.onVnodeBeforeMount)&&Ce(Y,M,y),G&&Me(y,null,M,"beforeMount"),((Y=w&&w.onVnodeMounted)||G||U)&&Oo(()=>{Y&&Ce(Y,M,y),U&&ne.enter(p),G&&Me(y,null,M,"mounted")},A)}return p.nextSibling},_=(p,y,M,A,F,$,L)=>{L=L||!!y.dynamicChildren;const w=y.children,N=w.length;for(let T=0;T<N;T++){const G=L?w[T]:w[T]=Ae(w[T]);p?p=h(p,G,A,F,$,L):G.type===Et&&!G.children?c(G.el=s(""),M):(pt(),n(null,G,M,null,A,F,tn(M),$))}return p},C=(p,y,M,A,F,$)=>{const{slotScopeIds:L}=y;L&&(F=F?F.concat(L):L);const w=i(p),N=_(o(p),y,w,M,A,F,$);return N&&nn(N)&&N.data==="]"?o(y.anchor=N):(pt(),c(y.anchor=a("]"),w,N),N)},I=(p,y,M,A,F,$)=>{if(pt(),y.el=null,$){const N=H(p);for(;;){const T=o(p);if(T&&T!==N)l(T);else break}}const L=o(p),w=i(p);return l(p),n(null,y,w,L,M,A,tn(w),F),L},H=(p,y="[",M="]")=>{let A=0;for(;p;)if(p=o(p),p&&nn(p)&&(p.data===y&&A++,p.data===M)){if(A===0)return o(p);A--}return p},W=(p,y,M)=>{const A=y.parentNode;A&&A.replaceChild(p,y);let F=M;for(;F;)F.vnode.el===y&&(F.vnode.el=F.subTree.el=p),F=F.parent},D=p=>p.nodeType===1&&p.tagName.toLowerCase()==="template";return[f,h]}const ye=Oo;function sc(e){return Bo(e)}function oc(e){return Bo(e,rc)}function Bo(e,t){const n=to();n.__VUE__=!0;const{insert:r,remove:s,patchProp:o,createElement:i,createText:l,createComment:c,setText:a,setElementText:f,parentNode:h,nextSibling:m,setScopeId:_=xe,insertStaticContent:C}=e,I=(u,d,g,v=null,b=null,S=null,O=void 0,x=null,R=!!d.dynamicChildren)=>{if(u===d)return;u&&!lt(u,d)&&(v=Yt(u),Le(u,b,S,!0),u=null),d.patchFlag===-2&&(R=!1,d.dynamicChildren=null);const{type:E,ref:P,shapeFlag:B}=d;switch(E){case Et:H(u,d,g,v);break;case me:W(u,d,g,v);break;case Pt:u==null&&D(d,g,v,O);break;case _e:T(u,d,g,v,b,S,O,x,R);break;default:B&1?M(u,d,g,v,b,S,O,x,R):B&6?G(u,d,g,v,b,S,O,x,R):(B&64||B&128)&&E.process(u,d,g,v,b,S,O,x,R,dt)}P!=null&&b&&wn(P,u&&u.ref,S,d||u,!d)},H=(u,d,g,v)=>{if(u==null)r(d.el=l(d.children),g,v);else{const b=d.el=u.el;d.children!==u.children&&a(b,d.children)}},W=(u,d,g,v)=>{u==null?r(d.el=c(d.children||""),g,v):d.el=u.el},D=(u,d,g,v)=>{[u.el,u.anchor]=C(u.children,d,g,v,u.el,u.anchor)},p=({el:u,anchor:d},g,v)=>{let b;for(;u&&u!==d;)b=m(u),r(u,g,v),u=b;r(d,g,v)},y=({el:u,anchor:d})=>{let g;for(;u&&u!==d;)g=m(u),s(u),u=g;s(d)},M=(u,d,g,v,b,S,O,x,R)=>{d.type==="svg"?O="svg":d.type==="math"&&(O="mathml"),u==null?A(d,g,v,b,S,O,x,R):L(u,d,b,S,O,x,R)},A=(u,d,g,v,b,S,O,x)=>{let R,E;const{props:P,shapeFlag:B,transition:j,dirs:q}=u;if(R=u.el=i(u.type,S,P&&P.is,P),B&8?f(R,u.children):B&16&&$(u.children,R,null,v,b,Gn(u,S),O,x),q&&Me(u,null,v,"created"),F(R,u,u.scopeId,O,v),P){for(const ee in P)ee!=="value"&&!_t(ee)&&o(R,ee,null,P[ee],S,u.children,v,b,je);"value"in P&&o(R,"value",null,P.value,S),(E=P.onVnodeBeforeMount)&&Ce(E,v,u)}q&&Me(u,null,v,"beforeMount");const X=ko(b,j);X&&j.beforeEnter(R),r(R,d,g),((E=P&&P.onVnodeMounted)||X||q)&&ye(()=>{E&&Ce(E,v,u),X&&j.enter(R),q&&Me(u,null,v,"mounted")},b)},F=(u,d,g,v,b)=>{if(g&&_(u,g),v)for(let S=0;S<v.length;S++)_(u,v[S]);if(b){let S=b.subTree;if(d===S){const O=b.vnode;F(u,O,O.scopeId,O.slotScopeIds,b.parent)}}},$=(u,d,g,v,b,S,O,x,R=0)=>{for(let E=R;E<u.length;E++){const P=u[E]=x?Xe(u[E]):Ae(u[E]);I(null,P,d,g,v,b,S,O,x)}},L=(u,d,g,v,b,S,O)=>{const x=d.el=u.el;let{patchFlag:R,dynamicChildren:E,dirs:P}=d;R|=u.patchFlag&16;const B=u.props||te,j=d.props||te;let q;if(g&&rt(g,!1),(q=j.onVnodeBeforeUpdate)&&Ce(q,g,d,u),P&&Me(d,u,g,"beforeUpdate"),g&&rt(g,!0),E?w(u.dynamicChildren,E,x,g,v,Gn(d,b),S):O||V(u,d,x,null,g,v,Gn(d,b),S,!1),R>0){if(R&16)N(x,d,B,j,g,v,b);else if(R&2&&B.class!==j.class&&o(x,"class",null,j.class,b),R&4&&o(x,"style",B.style,j.style,b),R&8){const X=d.dynamicProps;for(let ee=0;ee<X.length;ee++){const Q=X[ee],ae=B[Q],Te=j[Q];(Te!==ae||Q==="value")&&o(x,Q,ae,Te,b,u.children,g,v,je)}}R&1&&u.children!==d.children&&f(x,d.children)}else!O&&E==null&&N(x,d,B,j,g,v,b);((q=j.onVnodeUpdated)||P)&&ye(()=>{q&&Ce(q,g,d,u),P&&Me(d,u,g,"updated")},v)},w=(u,d,g,v,b,S,O)=>{for(let x=0;x<d.length;x++){const R=u[x],E=d[x],P=R.el&&(R.type===_e||!lt(R,E)||R.shapeFlag&70)?h(R.el):g;I(R,E,P,null,v,b,S,O,!0)}},N=(u,d,g,v,b,S,O)=>{if(g!==v){if(g!==te)for(const x in g)!_t(x)&&!(x in v)&&o(u,x,g[x],null,O,d.children,b,S,je);for(const x in v){if(_t(x))continue;const R=v[x],E=g[x];R!==E&&x!=="value"&&o(u,x,E,R,O,d.children,b,S,je)}"value"in v&&o(u,"value",g.value,v.value,O)}},T=(u,d,g,v,b,S,O,x,R)=>{const E=d.el=u?u.el:l(""),P=d.anchor=u?u.anchor:l("");let{patchFlag:B,dynamicChildren:j,slotScopeIds:q}=d;q&&(x=x?x.concat(q):q),u==null?(r(E,g,v),r(P,g,v),$(d.children||[],g,P,b,S,O,x,R)):B>0&&B&64&&j&&u.dynamicChildren?(w(u.dynamicChildren,j,g,b,S,O,x),(d.key!=null||b&&d===b.subTree)&&Dr(u,d,!0)):V(u,d,g,P,b,S,O,x,R)},G=(u,d,g,v,b,S,O,x,R)=>{d.slotScopeIds=x,u==null?d.shapeFlag&512?b.ctx.activate(d,g,v,O,R):ne(d,g,v,b,S,O,R):ce(u,d,R)},ne=(u,d,g,v,b,S,O)=>{const x=u.component=Sc(u,v,b);if(Wt(u)&&(x.ctx.renderer=dt),Tc(x),x.asyncDep){if(b&&b.registerDep(x,U,O),!u.el){const R=x.subTree=ie(me);W(null,R,d,g)}}else U(x,u,d,g,b,S,O)},ce=(u,d,g)=>{const v=d.component=u.component;if(Ll(u,d,g))if(v.asyncDep&&!v.asyncResolved){Y(v,d,g);return}else v.next=d,Cl(v.update),v.effect.dirty=!0,v.update();else d.el=u.el,v.vnode=d},U=(u,d,g,v,b,S,O)=>{const x=()=>{if(u.isMounted){let{next:P,bu:B,u:j,parent:q,vnode:X}=u;{const ht=Ko(u);if(ht){P&&(P.el=X.el,Y(u,P,O)),ht.asyncDep.then(()=>{u.isUnmounted||x()});return}}let ee=P,Q;rt(u,!1),P?(P.el=X.el,Y(u,P,O)):P=X,B&&fn(B),(Q=P.props&&P.props.onVnodeBeforeUpdate)&&Ce(Q,q,P,X),rt(u,!0);const ae=Kn(u),Te=u.subTree;u.subTree=ae,I(Te,ae,h(Te.el),Yt(Te),u,b,S),P.el=ae.el,ee===null&&Il(u,ae.el),j&&ye(j,b),(Q=P.props&&P.props.onVnodeUpdated)&&ye(()=>Ce(Q,q,P,X),b)}else{let P;const{el:B,props:j}=d,{bm:q,m:X,parent:ee}=u,Q=bt(d);if(rt(u,!1),q&&fn(q),!Q&&(P=j&&j.onVnodeBeforeMount)&&Ce(P,ee,d),rt(u,!0),B&&Bn){const ae=()=>{u.subTree=Kn(u),Bn(B,u.subTree,u,b,null)};Q?d.type.__asyncLoader().then(()=>!u.isUnmounted&&ae()):ae()}else{const ae=u.subTree=Kn(u);I(null,ae,g,v,u,b,S),d.el=ae.el}if(X&&ye(X,b),!Q&&(P=j&&j.onVnodeMounted)){const ae=d;ye(()=>Ce(P,ee,ae),b)}(d.shapeFlag&256||ee&&bt(ee.vnode)&&ee.vnode.shapeFlag&256)&&u.a&&ye(u.a,b),u.isMounted=!0,d=g=v=null}},R=u.effect=new Ar(x,xe,()=>Mn(E),u.scope),E=u.update=()=>{R.dirty&&R.run()};E.id=u.uid,rt(u,!0),E()},Y=(u,d,g)=>{d.component=u;const v=u.vnode.props;u.vnode=d,u.next=null,Jl(u,d.props,v,g),ec(u,d.children,g),tt(),os(u),Ue()},V=(u,d,g,v,b,S,O,x,R=!1)=>{const E=u&&u.children,P=u?u.shapeFlag:0,B=d.children,{patchFlag:j,shapeFlag:q}=d;if(j>0){if(j&128){Xt(E,B,g,v,b,S,O,x,R);return}else if(j&256){He(E,B,g,v,b,S,O,x,R);return}}q&8?(P&16&&je(E,b,S),B!==E&&f(g,B)):P&16?q&16?Xt(E,B,g,v,b,S,O,x,R):je(E,b,S,!0):(P&8&&f(g,""),q&16&&$(B,g,v,b,S,O,x,R))},He=(u,d,g,v,b,S,O,x,R)=>{u=u||mt,d=d||mt;const E=u.length,P=d.length,B=Math.min(E,P);let j;for(j=0;j<B;j++){const q=d[j]=R?Xe(d[j]):Ae(d[j]);I(u[j],q,g,null,b,S,O,x,R)}E>P?je(u,b,S,!0,!1,B):$(d,g,v,b,S,O,x,R,B)},Xt=(u,d,g,v,b,S,O,x,R)=>{let E=0;const P=d.length;let B=u.length-1,j=P-1;for(;E<=B&&E<=j;){const q=u[E],X=d[E]=R?Xe(d[E]):Ae(d[E]);if(lt(q,X))I(q,X,g,null,b,S,O,x,R);else break;E++}for(;E<=B&&E<=j;){const q=u[B],X=d[j]=R?Xe(d[j]):Ae(d[j]);if(lt(q,X))I(q,X,g,null,b,S,O,x,R);else break;B--,j--}if(E>B){if(E<=j){const q=j+1,X=q<P?d[q].el:v;for(;E<=j;)I(null,d[E]=R?Xe(d[E]):Ae(d[E]),g,X,b,S,O,x,R),E++}}else if(E>j)for(;E<=B;)Le(u[E],b,S,!0),E++;else{const q=E,X=E,ee=new Map;for(E=X;E<=j;E++){const be=d[E]=R?Xe(d[E]):Ae(d[E]);be.key!=null&&ee.set(be.key,E)}let Q,ae=0;const Te=j-X+1;let ht=!1,Xr=0;const St=new Array(Te);for(E=0;E<Te;E++)St[E]=0;for(E=q;E<=B;E++){const be=u[E];if(ae>=Te){Le(be,b,S,!0);continue}let Ie;if(be.key!=null)Ie=ee.get(be.key);else for(Q=X;Q<=j;Q++)if(St[Q-X]===0&<(be,d[Q])){Ie=Q;break}Ie===void 0?Le(be,b,S,!0):(St[Ie-X]=E+1,Ie>=Xr?Xr=Ie:ht=!0,I(be,d[Ie],g,null,b,S,O,x,R),ae++)}const Yr=ht?ic(St):mt;for(Q=Yr.length-1,E=Te-1;E>=0;E--){const be=X+E,Ie=d[be],zr=be+1<P?d[be+1].el:v;St[E]===0?I(null,Ie,g,zr,b,S,O,x,R):ht&&(Q<0||E!==Yr[Q]?nt(Ie,g,zr,2):Q--)}}},nt=(u,d,g,v,b=null)=>{const{el:S,type:O,transition:x,children:R,shapeFlag:E}=u;if(E&6){nt(u.component.subTree,d,g,v);return}if(E&128){u.suspense.move(d,g,v);return}if(E&64){O.move(u,d,g,dt);return}if(O===_e){r(S,d,g);for(let B=0;B<R.length;B++)nt(R[B],d,g,v);r(u.anchor,d,g);return}if(O===Pt){p(u,d,g);return}if(v!==2&&E&1&&x)if(v===0)x.beforeEnter(S),r(S,d,g),ye(()=>x.enter(S),b);else{const{leave:B,delayLeave:j,afterLeave:q}=x,X=()=>r(S,d,g),ee=()=>{B(S,()=>{X(),q&&q()})};j?j(S,X,ee):ee()}else r(S,d,g)},Le=(u,d,g,v=!1,b=!1)=>{const{type:S,props:O,ref:x,children:R,dynamicChildren:E,shapeFlag:P,patchFlag:B,dirs:j,memoIndex:q}=u;if(B===-2&&(b=!1),x!=null&&wn(x,null,g,u,!0),q!=null&&(d.renderCache[q]=void 0),P&256){d.ctx.deactivate(u);return}const X=P&1&&j,ee=!bt(u);let Q;if(ee&&(Q=O&&O.onVnodeBeforeUnmount)&&Ce(Q,d,u),P&6)Oi(u.component,g,v);else{if(P&128){u.suspense.unmount(g,v);return}X&&Me(u,null,d,"beforeUnmount"),P&64?u.type.remove(u,d,g,dt,v):E&&(S!==_e||B>0&&B&64)?je(E,d,g,!1,!0):(S===_e&&B&384||!b&&P&16)&&je(R,d,g),v&&qr(u)}(ee&&(Q=O&&O.onVnodeUnmounted)||X)&&ye(()=>{Q&&Ce(Q,d,u),X&&Me(u,null,d,"unmounted")},g)},qr=u=>{const{type:d,el:g,anchor:v,transition:b}=u;if(d===_e){Ri(g,v);return}if(d===Pt){y(u);return}const S=()=>{s(g),b&&!b.persisted&&b.afterLeave&&b.afterLeave()};if(u.shapeFlag&1&&b&&!b.persisted){const{leave:O,delayLeave:x}=b,R=()=>O(g,S);x?x(u.el,S,R):R()}else S()},Ri=(u,d)=>{let g;for(;u!==d;)g=m(u),s(u),u=g;s(d)},Oi=(u,d,g)=>{const{bum:v,scope:b,update:S,subTree:O,um:x,m:R,a:E}=u;ys(R),ys(E),v&&fn(v),b.stop(),S&&(S.active=!1,Le(O,u,d,g)),x&&ye(x,d),ye(()=>{u.isUnmounted=!0},d),d&&d.pendingBranch&&!d.isUnmounted&&u.asyncDep&&!u.asyncResolved&&u.suspenseId===d.pendingId&&(d.deps--,d.deps===0&&d.resolve())},je=(u,d,g,v=!1,b=!1,S=0)=>{for(let O=S;O<u.length;O++)Le(u[O],d,g,v,b)},Yt=u=>u.shapeFlag&6?Yt(u.component.subTree):u.shapeFlag&128?u.suspense.next():m(u.anchor||u.el);let Dn=!1;const Gr=(u,d,g)=>{u==null?d._vnode&&Le(d._vnode,null,null,!0):I(d._vnode||null,u,d,null,null,null,g),Dn||(Dn=!0,os(),_n(),Dn=!1),d._vnode=u},dt={p:I,um:Le,m:nt,r:qr,mt:ne,mc:$,pc:V,pbc:w,n:Yt,o:e};let Un,Bn;return t&&([Un,Bn]=t(dt)),{render:Gr,hydrate:Un,createApp:Xl(Gr,Un)}}function Gn({type:e,props:t},n){return n==="svg"&&e==="foreignObject"||n==="mathml"&&e==="annotation-xml"&&t&&t.encoding&&t.encoding.includes("html")?void 0:n}function rt({effect:e,update:t},n){e.allowRecurse=t.allowRecurse=n}function ko(e,t){return(!e||e&&!e.pendingBranch)&&t&&!t.persisted}function Dr(e,t,n=!1){const r=e.children,s=t.children;if(k(r)&&k(s))for(let o=0;o<r.length;o++){const i=r[o];let l=s[o];l.shapeFlag&1&&!l.dynamicChildren&&((l.patchFlag<=0||l.patchFlag===32)&&(l=s[o]=Xe(s[o]),l.el=i.el),!n&&l.patchFlag!==-2&&Dr(i,l)),l.type===Et&&(l.el=i.el)}}function ic(e){const t=e.slice(),n=[0];let r,s,o,i,l;const c=e.length;for(r=0;r<c;r++){const a=e[r];if(a!==0){if(s=n[n.length-1],e[s]<a){t[r]=s,n.push(r);continue}for(o=0,i=n.length-1;o<i;)l=o+i>>1,e[n[l]]<a?o=l+1:i=l;a<e[n[o]]&&(o>0&&(t[r]=n[o-1]),n[o]=r)}}for(o=n.length,i=n[o-1];o-- >0;)n[o]=i,i=t[i];return n}function Ko(e){const t=e.subTree.component;if(t)return t.asyncDep&&!t.asyncResolved?t:Ko(t)}function ys(e){if(e)for(let t=0;t<e.length;t++)e[t].active=!1}const lc=Symbol.for("v-scx"),cc=()=>wt(lc);function Ur(e,t){return Hn(e,null,t)}function hu(e,t){return Hn(e,null,{flush:"post"})}const rn={};function Ne(e,t,n){return Hn(e,t,n)}function Hn(e,t,{immediate:n,deep:r,flush:s,once:o,onTrack:i,onTrigger:l}=te){if(t&&o){const A=t;t=(...F)=>{A(...F),M()}}const c=ue,a=A=>r===!0?A:Ye(A,r===!1?1:void 0);let f,h=!1,m=!1;if(de(e)?(f=()=>e.value,h=yn(e)):Rt(e)?(f=()=>a(e),h=!0):k(e)?(m=!0,h=e.some(A=>Rt(A)||yn(A)),f=()=>e.map(A=>{if(de(A))return A.value;if(Rt(A))return a(A);if(K(A))return Je(A,c,2)})):K(e)?t?f=()=>Je(e,c,2):f=()=>(_&&_(),Se(e,c,3,[C])):f=xe,t&&r){const A=f;f=()=>Ye(A())}let _,C=A=>{_=p.onStop=()=>{Je(A,c,4),_=p.onStop=void 0}},I;if(Gt)if(C=xe,t?n&&Se(t,c,3,[f(),m?[]:void 0,C]):f(),s==="sync"){const A=cc();I=A.__watcherHandles||(A.__watcherHandles=[])}else return xe;let H=m?new Array(e.length).fill(rn):rn;const W=()=>{if(!(!p.active||!p.dirty))if(t){const A=p.run();(r||h||(m?A.some((F,$)=>Qe(F,H[$])):Qe(A,H)))&&(_&&_(),Se(t,c,3,[A,H===rn?void 0:m&&H[0]===rn?[]:H,C]),H=A)}else p.run()};W.allowRecurse=!!t;let D;s==="sync"?D=W:s==="post"?D=()=>ye(W,c&&c.suspense):(W.pre=!0,c&&(W.id=c.uid),D=()=>Mn(W));const p=new Ar(f,xe,D),y=so(),M=()=>{p.stop(),y&&Cr(y.effects,p)};return t?n?W():H=p.run():s==="post"?ye(p.run.bind(p),c&&c.suspense):p.run(),I&&I.push(M),M}function ac(e,t,n){const r=this.proxy,s=oe(e)?e.includes(".")?Wo(r,e):()=>r[e]:e.bind(r,r);let o;K(t)?o=t:(o=t.handler,n=t);const i=qt(this),l=Hn(s,o.bind(r),n);return i(),l}function Wo(e,t){const n=t.split(".");return()=>{let r=e;for(let s=0;s<n.length&&r;s++)r=r[n[s]];return r}}function Ye(e,t=1/0,n){if(t<=0||!Z(e)||e.__v_skip||(n=n||new Set,n.has(e)))return e;if(n.add(e),t--,de(e))Ye(e.value,t,n);else if(k(e))for(let r=0;r<e.length;r++)Ye(e[r],t,n);else if(zs(e)||yt(e))e.forEach(r=>{Ye(r,t,n)});else if(Zs(e)){for(const r in e)Ye(e[r],t,n);for(const r of Object.getOwnPropertySymbols(e))Object.prototype.propertyIsEnumerable.call(e,r)&&Ye(e[r],t,n)}return e}const Wt=e=>e.type.__isKeepAlive;function uc(e,t){qo(e,"a",t)}function fc(e,t){qo(e,"da",t)}function qo(e,t,n=ue){const r=e.__wdc||(e.__wdc=()=>{let s=n;for(;s;){if(s.isDeactivated)return;s=s.parent}return e()});if(Fn(t,r,n),n){let s=n.parent;for(;s&&s.parent;)Wt(s.parent.vnode)&&dc(r,t,n,s),s=s.parent}}function dc(e,t,n,r){const s=Fn(t,e,r,!0);$n(()=>{Cr(r[t],s)},n)}const Ge=Symbol("_leaveCb"),sn=Symbol("_enterCb");function hc(){const e={isMounted:!1,isLeaving:!1,isUnmounting:!1,leavingVNodes:new Map};return xt(()=>{e.isMounted=!0}),Lo(()=>{e.isUnmounting=!0}),e}const Ee=[Function,Array],Go={mode:String,appear:Boolean,persisted:Boolean,onBeforeEnter:Ee,onEnter:Ee,onAfterEnter:Ee,onEnterCancelled:Ee,onBeforeLeave:Ee,onLeave:Ee,onAfterLeave:Ee,onLeaveCancelled:Ee,onBeforeAppear:Ee,onAppear:Ee,onAfterAppear:Ee,onAppearCancelled:Ee},Xo=e=>{const t=e.subTree;return t.component?Xo(t.component):t},pc={name:"BaseTransition",props:Go,setup(e,{slots:t}){const n=jn(),r=hc();return()=>{const s=t.default&&zo(t.default(),!0);if(!s||!s.length)return;let o=s[0];if(s.length>1){for(const m of s)if(m.type!==me){o=m;break}}const i=J(e),{mode:l}=i;if(r.isLeaving)return Xn(o);const c=_s(o);if(!c)return Xn(o);let a=yr(c,i,r,n,m=>a=m);En(c,a);const f=n.subTree,h=f&&_s(f);if(h&&h.type!==me&&!lt(c,h)&&Xo(n).type!==me){const m=yr(h,i,r,n);if(En(h,m),l==="out-in"&&c.type!==me)return r.isLeaving=!0,m.afterLeave=()=>{r.isLeaving=!1,n.update.active!==!1&&(n.effect.dirty=!0,n.update())},Xn(o);l==="in-out"&&c.type!==me&&(m.delayLeave=(_,C,I)=>{const H=Yo(r,h);H[String(h.key)]=h,_[Ge]=()=>{C(),_[Ge]=void 0,delete a.delayedLeave},a.delayedLeave=I})}return o}}},gc=pc;function Yo(e,t){const{leavingVNodes:n}=e;let r=n.get(t.type);return r||(r=Object.create(null),n.set(t.type,r)),r}function yr(e,t,n,r,s){const{appear:o,mode:i,persisted:l=!1,onBeforeEnter:c,onEnter:a,onAfterEnter:f,onEnterCancelled:h,onBeforeLeave:m,onLeave:_,onAfterLeave:C,onLeaveCancelled:I,onBeforeAppear:H,onAppear:W,onAfterAppear:D,onAppearCancelled:p}=t,y=String(e.key),M=Yo(n,e),A=(L,w)=>{L&&Se(L,r,9,w)},F=(L,w)=>{const N=w[1];A(L,w),k(L)?L.every(T=>T.length<=1)&&N():L.length<=1&&N()},$={mode:i,persisted:l,beforeEnter(L){let w=c;if(!n.isMounted)if(o)w=H||c;else return;L[Ge]&&L[Ge](!0);const N=M[y];N&<(e,N)&&N.el[Ge]&&N.el[Ge](),A(w,[L])},enter(L){let w=a,N=f,T=h;if(!n.isMounted)if(o)w=W||a,N=D||f,T=p||h;else return;let G=!1;const ne=L[sn]=ce=>{G||(G=!0,ce?A(T,[L]):A(N,[L]),$.delayedLeave&&$.delayedLeave(),L[sn]=void 0)};w?F(w,[L,ne]):ne()},leave(L,w){const N=String(e.key);if(L[sn]&&L[sn](!0),n.isUnmounting)return w();A(m,[L]);let T=!1;const G=L[Ge]=ne=>{T||(T=!0,w(),ne?A(I,[L]):A(C,[L]),L[Ge]=void 0,M[N]===e&&delete M[N])};M[N]=e,_?F(_,[L,G]):G()},clone(L){const w=yr(L,t,n,r,s);return s&&s(w),w}};return $}function Xn(e){if(Wt(e))return e=Ze(e),e.children=null,e}function _s(e){if(!Wt(e))return e;const{shapeFlag:t,children:n}=e;if(n){if(t&16)return n[0];if(t&32&&K(n.default))return n.default()}}function En(e,t){e.shapeFlag&6&&e.component?En(e.component.subTree,t):e.shapeFlag&128?(e.ssContent.transition=t.clone(e.ssContent),e.ssFallback.transition=t.clone(e.ssFallback)):e.transition=t}function zo(e,t=!1,n){let r=[],s=0;for(let o=0;o<e.length;o++){let i=e[o];const l=n==null?i.key:String(n)+String(i.key!=null?i.key:o);i.type===_e?(i.patchFlag&128&&s++,r=r.concat(zo(i.children,t,l))):(t||i.type!==me)&&r.push(l!=null?Ze(i,{key:l}):i)}if(s>1)for(let o=0;o<r.length;o++)r[o].patchFlag=-2;return r}const mc=e=>e.__isTeleport,Mt=e=>e&&(e.disabled||e.disabled===""),vs=e=>typeof SVGElement<"u"&&e instanceof SVGElement,bs=e=>typeof MathMLElement=="function"&&e instanceof MathMLElement,_r=(e,t)=>{const n=e&&e.to;return oe(n)?t?t(n):null:n},yc={name:"Teleport",__isTeleport:!0,process(e,t,n,r,s,o,i,l,c,a){const{mc:f,pc:h,pbc:m,o:{insert:_,querySelector:C,createText:I,createComment:H}}=a,W=Mt(t.props);let{shapeFlag:D,children:p,dynamicChildren:y}=t;if(e==null){const M=t.el=I(""),A=t.anchor=I("");_(M,n,r),_(A,n,r);const F=t.target=_r(t.props,C),$=t.targetAnchor=I("");F&&(_($,F),i==="svg"||vs(F)?i="svg":(i==="mathml"||bs(F))&&(i="mathml"));const L=(w,N)=>{D&16&&f(p,w,N,s,o,i,l,c)};W?L(n,A):F&&L(F,$)}else{t.el=e.el;const M=t.anchor=e.anchor,A=t.target=e.target,F=t.targetAnchor=e.targetAnchor,$=Mt(e.props),L=$?n:A,w=$?M:F;if(i==="svg"||vs(A)?i="svg":(i==="mathml"||bs(A))&&(i="mathml"),y?(m(e.dynamicChildren,y,L,s,o,i,l),Dr(e,t,!0)):c||h(e,t,L,w,s,o,i,l,!1),W)$?t.props&&e.props&&t.props.to!==e.props.to&&(t.props.to=e.props.to):on(t,n,M,a,1);else if((t.props&&t.props.to)!==(e.props&&e.props.to)){const N=t.target=_r(t.props,C);N&&on(t,N,null,a,0)}else $&&on(t,A,F,a,1)}Jo(t)},remove(e,t,n,{um:r,o:{remove:s}},o){const{shapeFlag:i,children:l,anchor:c,targetAnchor:a,target:f,props:h}=e;if(f&&s(a),o&&s(c),i&16){const m=o||!Mt(h);for(let _=0;_<l.length;_++){const C=l[_];r(C,t,n,m,!!C.dynamicChildren)}}},move:on,hydrate:_c};function on(e,t,n,{o:{insert:r},m:s},o=2){o===0&&r(e.targetAnchor,t,n);const{el:i,anchor:l,shapeFlag:c,children:a,props:f}=e,h=o===2;if(h&&r(i,t,n),(!h||Mt(f))&&c&16)for(let m=0;m<a.length;m++)s(a[m],t,n,2);h&&r(l,t,n)}function _c(e,t,n,r,s,o,{o:{nextSibling:i,parentNode:l,querySelector:c}},a){const f=t.target=_r(t.props,c);if(f){const h=f._lpa||f.firstChild;if(t.shapeFlag&16)if(Mt(t.props))t.anchor=a(i(e),t,l(e),n,r,s,o),t.targetAnchor=h;else{t.anchor=i(e);let m=h;for(;m;)if(m=i(m),m&&m.nodeType===8&&m.data==="teleport anchor"){t.targetAnchor=m,f._lpa=t.targetAnchor&&i(t.targetAnchor);break}a(h,t,f,n,r,s,o)}Jo(t)}return t.anchor&&i(t.anchor)}const pu=yc;function Jo(e){const t=e.ctx;if(t&&t.ut){let n=e.children[0].el;for(;n&&n!==e.targetAnchor;)n.nodeType===1&&n.setAttribute("data-v-owner",t.uid),n=n.nextSibling;t.ut()}}const _e=Symbol.for("v-fgt"),Et=Symbol.for("v-txt"),me=Symbol.for("v-cmt"),Pt=Symbol.for("v-stc"),Nt=[];let Re=null;function Qo(e=!1){Nt.push(Re=e?null:[])}function vc(){Nt.pop(),Re=Nt[Nt.length-1]||null}let Dt=1;function ws(e){Dt+=e}function Zo(e){return e.dynamicChildren=Dt>0?Re||mt:null,vc(),Dt>0&&Re&&Re.push(e),e}function gu(e,t,n,r,s,o){return Zo(ni(e,t,n,r,s,o,!0))}function ei(e,t,n,r,s){return Zo(ie(e,t,n,r,s,!0))}function Cn(e){return e?e.__v_isVNode===!0:!1}function lt(e,t){return e.type===t.type&&e.key===t.key}const ti=({key:e})=>e??null,hn=({ref:e,ref_key:t,ref_for:n})=>(typeof e=="number"&&(e=""+e),e!=null?oe(e)||de(e)||K(e)?{i:fe,r:e,k:t,f:!!n}:e:null);function ni(e,t=null,n=null,r=0,s=null,o=e===_e?0:1,i=!1,l=!1){const c={__v_isVNode:!0,__v_skip:!0,type:e,props:t,key:t&&ti(t),ref:t&&hn(t),scopeId:Nn,slotScopeIds:null,children:n,component:null,suspense:null,ssContent:null,ssFallback:null,dirs:null,transition:null,el:null,anchor:null,target:null,targetAnchor:null,staticCount:0,shapeFlag:o,patchFlag:r,dynamicProps:s,dynamicChildren:null,appContext:null,ctx:fe};return l?(Br(c,n),o&128&&e.normalize(c)):n&&(c.shapeFlag|=oe(n)?8:16),Dt>0&&!i&&Re&&(c.patchFlag>0||o&6)&&c.patchFlag!==32&&Re.push(c),c}const ie=bc;function bc(e,t=null,n=null,r=0,s=null,o=!1){if((!e||e===Ao)&&(e=me),Cn(e)){const l=Ze(e,t,!0);return n&&Br(l,n),Dt>0&&!o&&Re&&(l.shapeFlag&6?Re[Re.indexOf(e)]=l:Re.push(l)),l.patchFlag=-2,l}if(Lc(e)&&(e=e.__vccOpts),t){t=wc(t);let{class:l,style:c}=t;l&&!oe(l)&&(t.class=Tr(l)),Z(c)&&(yo(c)&&!k(c)&&(c=le({},c)),t.style=Sr(c))}const i=oe(e)?1:Ml(e)?128:mc(e)?64:Z(e)?4:K(e)?2:0;return ni(e,t,n,r,s,i,o,!0)}function wc(e){return e?yo(e)||$o(e)?le({},e):e:null}function Ze(e,t,n=!1,r=!1){const{props:s,ref:o,patchFlag:i,children:l,transition:c}=e,a=t?Ec(s||{},t):s,f={__v_isVNode:!0,__v_skip:!0,type:e.type,props:a,key:a&&ti(a),ref:t&&t.ref?n&&o?k(o)?o.concat(hn(t)):[o,hn(t)]:hn(t):o,scopeId:e.scopeId,slotScopeIds:e.slotScopeIds,children:l,target:e.target,targetAnchor:e.targetAnchor,staticCount:e.staticCount,shapeFlag:e.shapeFlag,patchFlag:t&&e.type!==_e?i===-1?16:i|16:i,dynamicProps:e.dynamicProps,dynamicChildren:e.dynamicChildren,appContext:e.appContext,dirs:e.dirs,transition:c,component:e.component,suspense:e.suspense,ssContent:e.ssContent&&Ze(e.ssContent),ssFallback:e.ssFallback&&Ze(e.ssFallback),el:e.el,anchor:e.anchor,ctx:e.ctx,ce:e.ce};return c&&r&&En(f,c.clone(f)),f}function ri(e=" ",t=0){return ie(Et,null,e,t)}function mu(e,t){const n=ie(Pt,null,e);return n.staticCount=t,n}function yu(e="",t=!1){return t?(Qo(),ei(me,null,e)):ie(me,null,e)}function Ae(e){return e==null||typeof e=="boolean"?ie(me):k(e)?ie(_e,null,e.slice()):typeof e=="object"?Xe(e):ie(Et,null,String(e))}function Xe(e){return e.el===null&&e.patchFlag!==-1||e.memo?e:Ze(e)}function Br(e,t){let n=0;const{shapeFlag:r}=e;if(t==null)t=null;else if(k(t))n=16;else if(typeof t=="object")if(r&65){const s=t.default;s&&(s._c&&(s._d=!1),Br(e,s()),s._c&&(s._d=!0));return}else{n=32;const s=t._;!s&&!$o(t)?t._ctx=fe:s===3&&fe&&(fe.slots._===1?t._=1:(t._=2,e.patchFlag|=1024))}else K(t)?(t={default:t,_ctx:fe},n=32):(t=String(t),r&64?(n=16,t=[ri(t)]):n=8);e.children=t,e.shapeFlag|=n}function Ec(...e){const t={};for(let n=0;n<e.length;n++){const r=e[n];for(const s in r)if(s==="class")t.class!==r.class&&(t.class=Tr([t.class,r.class]));else if(s==="style")t.style=Sr([t.style,r.style]);else if(kt(s)){const o=t[s],i=r[s];i&&o!==i&&!(k(o)&&o.includes(i))&&(t[s]=o?[].concat(o,i):i)}else s!==""&&(t[s]=r[s])}return t}function Ce(e,t,n,r=null){Se(e,t,7,[n,r])}const Cc=Po();let xc=0;function Sc(e,t,n){const r=e.type,s=(t?t.appContext:e.appContext)||Cc,o={uid:xc++,vnode:e,type:r,parent:t,appContext:s,root:null,next:null,subTree:null,effect:null,update:null,scope:new Bi(!0),render:null,proxy:null,exposed:null,exposeProxy:null,withProxy:null,provides:t?t.provides:Object.create(s.provides),accessCache:null,renderCache:[],components:null,directives:null,propsOptions:jo(r,s),emitsOptions:So(r,s),emit:null,emitted:null,propsDefaults:te,inheritAttrs:r.inheritAttrs,ctx:te,data:te,props:te,attrs:te,slots:te,refs:te,setupState:te,setupContext:null,attrsProxy:null,slotsProxy:null,suspense:n,suspenseId:n?n.pendingId:0,asyncDep:null,asyncResolved:!1,isMounted:!1,isUnmounted:!1,isDeactivated:!1,bc:null,c:null,bm:null,m:null,bu:null,u:null,um:null,bum:null,da:null,a:null,rtg:null,rtc:null,ec:null,sp:null};return o.ctx={_:o},o.root=t?t.root:o,o.emit=Tl.bind(null,o),e.ce&&e.ce(o),o}let ue=null;const jn=()=>ue||fe;let xn,vr;{const e=to(),t=(n,r)=>{let s;return(s=e[n])||(s=e[n]=[]),s.push(r),o=>{s.length>1?s.forEach(i=>i(o)):s[0](o)}};xn=t("__VUE_INSTANCE_SETTERS__",n=>ue=n),vr=t("__VUE_SSR_SETTERS__",n=>Gt=n)}const qt=e=>{const t=ue;return xn(e),e.scope.on(),()=>{e.scope.off(),xn(t)}},Es=()=>{ue&&ue.scope.off(),xn(null)};function si(e){return e.vnode.shapeFlag&4}let Gt=!1;function Tc(e,t=!1){t&&vr(t);const{props:n,children:r}=e.vnode,s=si(e);zl(e,n,s,t),Zl(e,r);const o=s?Ac(e,t):void 0;return t&&vr(!1),o}function Ac(e,t){const n=e.type;e.accessCache=Object.create(null),e.proxy=new Proxy(e.ctx,Dl);const{setup:r}=n;if(r){const s=e.setupContext=r.length>1?ii(e):null,o=qt(e);tt();const i=Je(r,e,0,[e.props,s]);if(Ue(),o(),Js(i)){if(i.then(Es,Es),t)return i.then(l=>{Cs(e,l,t)}).catch(l=>{Kt(l,e,0)});e.asyncDep=i}else Cs(e,i,t)}else oi(e,t)}function Cs(e,t,n){K(t)?e.type.__ssrInlineRender?e.ssrRender=t:e.render=t:Z(t)&&(e.setupState=wo(t)),oi(e,n)}let xs;function oi(e,t,n){const r=e.type;if(!e.render){if(!t&&xs&&!r.render){const s=r.template||jr(e).template;if(s){const{isCustomElement:o,compilerOptions:i}=e.appContext.config,{delimiters:l,compilerOptions:c}=r,a=le(le({isCustomElement:o,delimiters:l},i),c);r.render=xs(s,a)}}e.render=r.render||xe}{const s=qt(e);tt();try{Bl(e)}finally{Ue(),s()}}}const Rc={get(e,t){return ve(e,"get",""),e[t]}};function ii(e){const t=n=>{e.exposed=n||{}};return{attrs:new Proxy(e.attrs,Rc),slots:e.slots,emit:e.emit,expose:t}}function Vn(e){return e.exposed?e.exposeProxy||(e.exposeProxy=new Proxy(wo(dn(e.exposed)),{get(t,n){if(n in t)return t[n];if(n in Lt)return Lt[n](e)},has(t,n){return n in t||n in Lt}})):e.proxy}function Oc(e,t=!0){return K(e)?e.displayName||e.name:e.name||t&&e.__name}function Lc(e){return K(e)&&"__vccOpts"in e}const re=(e,t)=>dl(e,t,Gt);function br(e,t,n){const r=arguments.length;return r===2?Z(t)&&!k(t)?Cn(t)?ie(e,null,[t]):ie(e,t):ie(e,null,t):(r>3?n=Array.prototype.slice.call(arguments,2):r===3&&Cn(n)&&(n=[n]),ie(e,t,n))}const Ic="3.4.30";/**
|
||||
* @vue/runtime-dom v3.4.30
|
||||
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
||||
* @license MIT
|
||||
**/const Mc="http://www.w3.org/2000/svg",Pc="http://www.w3.org/1998/Math/MathML",Ve=typeof document<"u"?document:null,Ss=Ve&&Ve.createElement("template"),Nc={insert:(e,t,n)=>{t.insertBefore(e,n||null)},remove:e=>{const t=e.parentNode;t&&t.removeChild(e)},createElement:(e,t,n,r)=>{const s=t==="svg"?Ve.createElementNS(Mc,e):t==="mathml"?Ve.createElementNS(Pc,e):n?Ve.createElement(e,{is:n}):Ve.createElement(e);return e==="select"&&r&&r.multiple!=null&&s.setAttribute("multiple",r.multiple),s},createText:e=>Ve.createTextNode(e),createComment:e=>Ve.createComment(e),setText:(e,t)=>{e.nodeValue=t},setElementText:(e,t)=>{e.textContent=t},parentNode:e=>e.parentNode,nextSibling:e=>e.nextSibling,querySelector:e=>Ve.querySelector(e),setScopeId(e,t){e.setAttribute(t,"")},insertStaticContent(e,t,n,r,s,o){const i=n?n.previousSibling:t.lastChild;if(s&&(s===o||s.nextSibling))for(;t.insertBefore(s.cloneNode(!0),n),!(s===o||!(s=s.nextSibling)););else{Ss.innerHTML=r==="svg"?`<svg>${e}</svg>`:r==="mathml"?`<math>${e}</math>`:e;const l=Ss.content;if(r==="svg"||r==="mathml"){const c=l.firstChild;for(;c.firstChild;)l.appendChild(c.firstChild);l.removeChild(c)}t.insertBefore(l,n)}return[i?i.nextSibling:t.firstChild,n?n.previousSibling:t.lastChild]}},Ke="transition",Tt="animation",Ut=Symbol("_vtc"),li=(e,{slots:t})=>br(gc,Fc(e),t);li.displayName="Transition";const ci={name:String,type:String,css:{type:Boolean,default:!0},duration:[String,Number,Object],enterFromClass:String,enterActiveClass:String,enterToClass:String,appearFromClass:String,appearActiveClass:String,appearToClass:String,leaveFromClass:String,leaveActiveClass:String,leaveToClass:String};li.props=le({},Go,ci);const st=(e,t=[])=>{k(e)?e.forEach(n=>n(...t)):e&&e(...t)},Ts=e=>e?k(e)?e.some(t=>t.length>1):e.length>1:!1;function Fc(e){const t={};for(const T in e)T in ci||(t[T]=e[T]);if(e.css===!1)return t;const{name:n="v",type:r,duration:s,enterFromClass:o=`${n}-enter-from`,enterActiveClass:i=`${n}-enter-active`,enterToClass:l=`${n}-enter-to`,appearFromClass:c=o,appearActiveClass:a=i,appearToClass:f=l,leaveFromClass:h=`${n}-leave-from`,leaveActiveClass:m=`${n}-leave-active`,leaveToClass:_=`${n}-leave-to`}=e,C=$c(s),I=C&&C[0],H=C&&C[1],{onBeforeEnter:W,onEnter:D,onEnterCancelled:p,onLeave:y,onLeaveCancelled:M,onBeforeAppear:A=W,onAppear:F=D,onAppearCancelled:$=p}=t,L=(T,G,ne)=>{ot(T,G?f:l),ot(T,G?a:i),ne&&ne()},w=(T,G)=>{T._isLeaving=!1,ot(T,h),ot(T,_),ot(T,m),G&&G()},N=T=>(G,ne)=>{const ce=T?F:D,U=()=>L(G,T,ne);st(ce,[G,U]),As(()=>{ot(G,T?c:o),We(G,T?f:l),Ts(ce)||Rs(G,r,I,U)})};return le(t,{onBeforeEnter(T){st(W,[T]),We(T,o),We(T,i)},onBeforeAppear(T){st(A,[T]),We(T,c),We(T,a)},onEnter:N(!1),onAppear:N(!0),onLeave(T,G){T._isLeaving=!0;const ne=()=>w(T,G);We(T,h),We(T,m),Vc(),As(()=>{T._isLeaving&&(ot(T,h),We(T,_),Ts(y)||Rs(T,r,H,ne))}),st(y,[T,ne])},onEnterCancelled(T){L(T,!1),st(p,[T])},onAppearCancelled(T){L(T,!0),st($,[T])},onLeaveCancelled(T){w(T),st(M,[T])}})}function $c(e){if(e==null)return null;if(Z(e))return[Yn(e.enter),Yn(e.leave)];{const t=Yn(e);return[t,t]}}function Yn(e){return Fi(e)}function We(e,t){t.split(/\s+/).forEach(n=>n&&e.classList.add(n)),(e[Ut]||(e[Ut]=new Set)).add(t)}function ot(e,t){t.split(/\s+/).forEach(r=>r&&e.classList.remove(r));const n=e[Ut];n&&(n.delete(t),n.size||(e[Ut]=void 0))}function As(e){requestAnimationFrame(()=>{requestAnimationFrame(e)})}let Hc=0;function Rs(e,t,n,r){const s=e._endId=++Hc,o=()=>{s===e._endId&&r()};if(n)return setTimeout(o,n);const{type:i,timeout:l,propCount:c}=jc(e,t);if(!i)return r();const a=i+"end";let f=0;const h=()=>{e.removeEventListener(a,m),o()},m=_=>{_.target===e&&++f>=c&&h()};setTimeout(()=>{f<c&&h()},l+1),e.addEventListener(a,m)}function jc(e,t){const n=window.getComputedStyle(e),r=C=>(n[C]||"").split(", "),s=r(`${Ke}Delay`),o=r(`${Ke}Duration`),i=Os(s,o),l=r(`${Tt}Delay`),c=r(`${Tt}Duration`),a=Os(l,c);let f=null,h=0,m=0;t===Ke?i>0&&(f=Ke,h=i,m=o.length):t===Tt?a>0&&(f=Tt,h=a,m=c.length):(h=Math.max(i,a),f=h>0?i>a?Ke:Tt:null,m=f?f===Ke?o.length:c.length:0);const _=f===Ke&&/\b(transform|all)(,|$)/.test(r(`${Ke}Property`).toString());return{type:f,timeout:h,propCount:m,hasTransform:_}}function Os(e,t){for(;e.length<t.length;)e=e.concat(e);return Math.max(...t.map((n,r)=>Ls(n)+Ls(e[r])))}function Ls(e){return e==="auto"?0:Number(e.slice(0,-1).replace(",","."))*1e3}function Vc(){return document.body.offsetHeight}function Dc(e,t,n){const r=e[Ut];r&&(t=(t?[t,...r]:[...r]).join(" ")),t==null?e.removeAttribute("class"):n?e.setAttribute("class",t):e.className=t}const Is=Symbol("_vod"),Uc=Symbol("_vsh"),Bc=Symbol(""),kc=/(^|;)\s*display\s*:/;function Kc(e,t,n){const r=e.style,s=oe(n);let o=!1;if(n&&!s){if(t)if(oe(t))for(const i of t.split(";")){const l=i.slice(0,i.indexOf(":")).trim();n[l]==null&&pn(r,l,"")}else for(const i in t)n[i]==null&&pn(r,i,"");for(const i in n)i==="display"&&(o=!0),pn(r,i,n[i])}else if(s){if(t!==n){const i=r[Bc];i&&(n+=";"+i),r.cssText=n,o=kc.test(n)}}else t&&e.removeAttribute("style");Is in e&&(e[Is]=o?r.display:"",e[Uc]&&(r.display="none"))}const Ms=/\s*!important$/;function pn(e,t,n){if(k(n))n.forEach(r=>pn(e,t,r));else if(n==null&&(n=""),t.startsWith("--"))e.setProperty(t,n);else{const r=Wc(e,t);Ms.test(n)?e.setProperty(ft(r),n.replace(Ms,""),"important"):e[r]=n}}const Ps=["Webkit","Moz","ms"],zn={};function Wc(e,t){const n=zn[t];if(n)return n;let r=$e(t);if(r!=="filter"&&r in e)return zn[t]=r;r=An(r);for(let s=0;s<Ps.length;s++){const o=Ps[s]+r;if(o in e)return zn[t]=o}return t}const Ns="http://www.w3.org/1999/xlink";function Fs(e,t,n,r,s,o=Ui(t)){r&&t.startsWith("xlink:")?n==null?e.removeAttributeNS(Ns,t.slice(6,t.length)):e.setAttributeNS(Ns,t,n):n==null||o&&!no(n)?e.removeAttribute(t):e.setAttribute(t,o?"":et(n)?String(n):n)}function qc(e,t,n,r,s,o,i){if(t==="innerHTML"||t==="textContent"){r&&i(r,s,o),e[t]=n??"";return}const l=e.tagName;if(t==="value"&&l!=="PROGRESS"&&!l.includes("-")){const a=l==="OPTION"?e.getAttribute("value")||"":e.value,f=n==null?"":String(n);(a!==f||!("_value"in e))&&(e.value=f),n==null&&e.removeAttribute(t),e._value=n;return}let c=!1;if(n===""||n==null){const a=typeof e[t];a==="boolean"?n=no(n):n==null&&a==="string"?(n="",c=!0):a==="number"&&(n=0,c=!0)}try{e[t]=n}catch{}c&&e.removeAttribute(t)}function gt(e,t,n,r){e.addEventListener(t,n,r)}function Gc(e,t,n,r){e.removeEventListener(t,n,r)}const $s=Symbol("_vei");function Xc(e,t,n,r,s=null){const o=e[$s]||(e[$s]={}),i=o[t];if(r&&i)i.value=r;else{const[l,c]=Yc(t);if(r){const a=o[t]=Qc(r,s);gt(e,l,a,c)}else i&&(Gc(e,l,i,c),o[t]=void 0)}}const Hs=/(?:Once|Passive|Capture)$/;function Yc(e){let t;if(Hs.test(e)){t={};let r;for(;r=e.match(Hs);)e=e.slice(0,e.length-r[0].length),t[r[0].toLowerCase()]=!0}return[e[2]===":"?e.slice(3):ft(e.slice(2)),t]}let Jn=0;const zc=Promise.resolve(),Jc=()=>Jn||(zc.then(()=>Jn=0),Jn=Date.now());function Qc(e,t){const n=r=>{if(!r._vts)r._vts=Date.now();else if(r._vts<=n.attached)return;Se(Zc(r,n.value),t,5,[r])};return n.value=e,n.attached=Jc(),n}function Zc(e,t){if(k(t)){const n=e.stopImmediatePropagation;return e.stopImmediatePropagation=()=>{n.call(e),e._stopped=!0},t.map(r=>s=>!s._stopped&&r&&r(s))}else return t}const js=e=>e.charCodeAt(0)===111&&e.charCodeAt(1)===110&&e.charCodeAt(2)>96&&e.charCodeAt(2)<123,ea=(e,t,n,r,s,o,i,l,c)=>{const a=s==="svg";t==="class"?Dc(e,r,a):t==="style"?Kc(e,n,r):kt(t)?Er(t)||Xc(e,t,n,r,i):(t[0]==="."?(t=t.slice(1),!0):t[0]==="^"?(t=t.slice(1),!1):ta(e,t,r,a))?(qc(e,t,r,o,i,l,c),!e.tagName.includes("-")&&(t==="value"||t==="checked"||t==="selected")&&Fs(e,t,r,a,i,t!=="value")):(t==="true-value"?e._trueValue=r:t==="false-value"&&(e._falseValue=r),Fs(e,t,r,a))};function ta(e,t,n,r){if(r)return!!(t==="innerHTML"||t==="textContent"||t in e&&js(t)&&K(n));if(t==="spellcheck"||t==="draggable"||t==="translate"||t==="form"||t==="list"&&e.tagName==="INPUT"||t==="type"&&e.tagName==="TEXTAREA")return!1;if(t==="width"||t==="height"){const s=e.tagName;if(s==="IMG"||s==="VIDEO"||s==="CANVAS"||s==="SOURCE")return!1}return js(t)&&oe(n)?!1:t in e}const Vs=e=>{const t=e.props["onUpdate:modelValue"]||!1;return k(t)?n=>fn(t,n):t};function na(e){e.target.composing=!0}function Ds(e){const t=e.target;t.composing&&(t.composing=!1,t.dispatchEvent(new Event("input")))}const Qn=Symbol("_assign"),_u={created(e,{modifiers:{lazy:t,trim:n,number:r}},s){e[Qn]=Vs(s);const o=r||s.props&&s.props.type==="number";gt(e,t?"change":"input",i=>{if(i.target.composing)return;let l=e.value;n&&(l=l.trim()),o&&(l=cr(l)),e[Qn](l)}),n&>(e,"change",()=>{e.value=e.value.trim()}),t||(gt(e,"compositionstart",na),gt(e,"compositionend",Ds),gt(e,"change",Ds))},mounted(e,{value:t}){e.value=t??""},beforeUpdate(e,{value:t,oldValue:n,modifiers:{lazy:r,trim:s,number:o}},i){if(e[Qn]=Vs(i),e.composing)return;const l=(o||e.type==="number")&&!/^0\d/.test(e.value)?cr(e.value):e.value,c=t??"";l!==c&&(document.activeElement===e&&e.type!=="range"&&(r&&t===n||s&&e.value.trim()===c)||(e.value=c))}},ra=["ctrl","shift","alt","meta"],sa={stop:e=>e.stopPropagation(),prevent:e=>e.preventDefault(),self:e=>e.target!==e.currentTarget,ctrl:e=>!e.ctrlKey,shift:e=>!e.shiftKey,alt:e=>!e.altKey,meta:e=>!e.metaKey,left:e=>"button"in e&&e.button!==0,middle:e=>"button"in e&&e.button!==1,right:e=>"button"in e&&e.button!==2,exact:(e,t)=>ra.some(n=>e[`${n}Key`]&&!t.includes(n))},vu=(e,t)=>{const n=e._withMods||(e._withMods={}),r=t.join(".");return n[r]||(n[r]=(s,...o)=>{for(let i=0;i<t.length;i++){const l=sa[t[i]];if(l&&l(s,t))return}return e(s,...o)})},oa={esc:"escape",space:" ",up:"arrow-up",left:"arrow-left",right:"arrow-right",down:"arrow-down",delete:"backspace"},bu=(e,t)=>{const n=e._withKeys||(e._withKeys={}),r=t.join(".");return n[r]||(n[r]=s=>{if(!("key"in s))return;const o=ft(s.key);if(t.some(i=>i===o||oa[i]===o))return e(s)})},ai=le({patchProp:ea},Nc);let Ft,Us=!1;function ia(){return Ft||(Ft=sc(ai))}function la(){return Ft=Us?Ft:oc(ai),Us=!0,Ft}const wu=(...e)=>{const t=ia().createApp(...e),{mount:n}=t;return t.mount=r=>{const s=fi(r);if(!s)return;const o=t._component;!K(o)&&!o.render&&!o.template&&(o.template=s.innerHTML),s.innerHTML="";const i=n(s,!1,ui(s));return s instanceof Element&&(s.removeAttribute("v-cloak"),s.setAttribute("data-v-app","")),i},t},Eu=(...e)=>{const t=la().createApp(...e),{mount:n}=t;return t.mount=r=>{const s=fi(r);if(s)return n(s,!0,ui(s))},t};function ui(e){if(e instanceof SVGElement)return"svg";if(typeof MathMLElement=="function"&&e instanceof MathMLElement)return"mathml"}function fi(e){return oe(e)?document.querySelector(e):e}const Cu=(e,t)=>{const n=e.__vccOpts||e;for(const[r,s]of t)n[r]=s;return n},ca="modulepreload",aa=function(e){return"/coa6/"+e},Bs={},xu=function(t,n,r){let s=Promise.resolve();if(n&&n.length>0){document.getElementsByTagName("link");const o=document.querySelector("meta[property=csp-nonce]"),i=(o==null?void 0:o.nonce)||(o==null?void 0:o.getAttribute("nonce"));s=Promise.all(n.map(l=>{if(l=aa(l),l in Bs)return;Bs[l]=!0;const c=l.endsWith(".css"),a=c?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${l}"]${a}`))return;const f=document.createElement("link");if(f.rel=c?"stylesheet":ca,c||(f.as="script",f.crossOrigin=""),f.href=l,i&&f.setAttribute("nonce",i),document.head.appendChild(f),c)return new Promise((h,m)=>{f.addEventListener("load",h),f.addEventListener("error",()=>m(new Error(`Unable to preload CSS for ${l}`)))})}))}return s.then(()=>t()).catch(o=>{const i=new Event("vite:preloadError",{cancelable:!0});if(i.payload=o,window.dispatchEvent(i),!i.defaultPrevented)throw o})},ua=window.__VP_SITE_DATA__;function kr(e){return so()?(Ki(e),!0):!1}function Fe(e){return typeof e=="function"?e():bo(e)}const di=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const fa=Object.prototype.toString,da=e=>fa.call(e)==="[object Object]",Bt=()=>{},ks=ha();function ha(){var e,t;return di&&((e=window==null?void 0:window.navigator)==null?void 0:e.userAgent)&&(/iP(?:ad|hone|od)/.test(window.navigator.userAgent)||((t=window==null?void 0:window.navigator)==null?void 0:t.maxTouchPoints)>2&&/iPad|Macintosh/.test(window==null?void 0:window.navigator.userAgent))}function pa(e,t){function n(...r){return new Promise((s,o)=>{Promise.resolve(e(()=>t.apply(this,r),{fn:t,thisArg:this,args:r})).then(s).catch(o)})}return n}const hi=e=>e();function ga(e,t={}){let n,r,s=Bt;const o=l=>{clearTimeout(l),s(),s=Bt};return l=>{const c=Fe(e),a=Fe(t.maxWait);return n&&o(n),c<=0||a!==void 0&&a<=0?(r&&(o(r),r=null),Promise.resolve(l())):new Promise((f,h)=>{s=t.rejectOnCancel?h:f,a&&!r&&(r=setTimeout(()=>{n&&o(n),r=null,f(l())},a)),n=setTimeout(()=>{r&&o(r),r=null,f(l())},c)})}}function ma(e=hi){const t=se(!0);function n(){t.value=!1}function r(){t.value=!0}const s=(...o)=>{t.value&&e(...o)};return{isActive:Ln(t),pause:n,resume:r,eventFilter:s}}function ya(e){return jn()}function pi(...e){if(e.length!==1)return vl(...e);const t=e[0];return typeof t=="function"?Ln(ml(()=>({get:t,set:Bt}))):se(t)}function gi(e,t,n={}){const{eventFilter:r=hi,...s}=n;return Ne(e,pa(r,t),s)}function _a(e,t,n={}){const{eventFilter:r,...s}=n,{eventFilter:o,pause:i,resume:l,isActive:c}=ma(r);return{stop:gi(e,t,{...s,eventFilter:o}),pause:i,resume:l,isActive:c}}function Kr(e,t=!0,n){ya()?xt(e,n):t?e():In(e)}function Su(e,t,n={}){const{debounce:r=0,maxWait:s=void 0,...o}=n;return gi(e,t,{...o,eventFilter:ga(r,{maxWait:s})})}function Tu(e,t,n){let r;de(n)?r={evaluating:n}:r={};const{lazy:s=!1,evaluating:o=void 0,shallow:i=!0,onError:l=Bt}=r,c=se(!s),a=i?Fr(t):se(t);let f=0;return Ur(async h=>{if(!c.value)return;f++;const m=f;let _=!1;o&&Promise.resolve().then(()=>{o.value=!0});try{const C=await e(I=>{h(()=>{o&&(o.value=!1),_||I()})});m===f&&(a.value=C)}catch(C){l(C)}finally{o&&m===f&&(o.value=!1),_=!0}}),s?re(()=>(c.value=!0,a.value)):a}function mi(e){var t;const n=Fe(e);return(t=n==null?void 0:n.$el)!=null?t:n}const Oe=di?window:void 0;function Ct(...e){let t,n,r,s;if(typeof e[0]=="string"||Array.isArray(e[0])?([n,r,s]=e,t=Oe):[t,n,r,s]=e,!t)return Bt;Array.isArray(n)||(n=[n]),Array.isArray(r)||(r=[r]);const o=[],i=()=>{o.forEach(f=>f()),o.length=0},l=(f,h,m,_)=>(f.addEventListener(h,m,_),()=>f.removeEventListener(h,m,_)),c=Ne(()=>[mi(t),Fe(s)],([f,h])=>{if(i(),!f)return;const m=da(h)?{...h}:h;o.push(...n.flatMap(_=>r.map(C=>l(f,_,C,m))))},{immediate:!0,flush:"post"}),a=()=>{c(),i()};return kr(a),a}function va(e){return typeof e=="function"?e:typeof e=="string"?t=>t.key===e:Array.isArray(e)?t=>e.includes(t.key):()=>!0}function Au(...e){let t,n,r={};e.length===3?(t=e[0],n=e[1],r=e[2]):e.length===2?typeof e[1]=="object"?(t=!0,n=e[0],r=e[1]):(t=e[0],n=e[1]):(t=!0,n=e[0]);const{target:s=Oe,eventName:o="keydown",passive:i=!1,dedupe:l=!1}=r,c=va(t);return Ct(s,o,f=>{f.repeat&&Fe(l)||c(f)&&n(f)},i)}function ba(){const e=se(!1),t=jn();return t&&xt(()=>{e.value=!0},t),e}function wa(e){const t=ba();return re(()=>(t.value,!!e()))}function yi(e,t={}){const{window:n=Oe}=t,r=wa(()=>n&&"matchMedia"in n&&typeof n.matchMedia=="function");let s;const o=se(!1),i=a=>{o.value=a.matches},l=()=>{s&&("removeEventListener"in s?s.removeEventListener("change",i):s.removeListener(i))},c=Ur(()=>{r.value&&(l(),s=n.matchMedia(Fe(e)),"addEventListener"in s?s.addEventListener("change",i):s.addListener(i),o.value=s.matches)});return kr(()=>{c(),l(),s=void 0}),o}const ln=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},cn="__vueuse_ssr_handlers__",Ea=Ca();function Ca(){return cn in ln||(ln[cn]=ln[cn]||{}),ln[cn]}function _i(e,t){return Ea[e]||t}function xa(e){return e==null?"any":e instanceof Set?"set":e instanceof Map?"map":e instanceof Date?"date":typeof e=="boolean"?"boolean":typeof e=="string"?"string":typeof e=="object"?"object":Number.isNaN(e)?"any":"number"}const Sa={boolean:{read:e=>e==="true",write:e=>String(e)},object:{read:e=>JSON.parse(e),write:e=>JSON.stringify(e)},number:{read:e=>Number.parseFloat(e),write:e=>String(e)},any:{read:e=>e,write:e=>String(e)},string:{read:e=>e,write:e=>String(e)},map:{read:e=>new Map(JSON.parse(e)),write:e=>JSON.stringify(Array.from(e.entries()))},set:{read:e=>new Set(JSON.parse(e)),write:e=>JSON.stringify(Array.from(e))},date:{read:e=>new Date(e),write:e=>e.toISOString()}},Ks="vueuse-storage";function Wr(e,t,n,r={}){var s;const{flush:o="pre",deep:i=!0,listenToStorageChanges:l=!0,writeDefaults:c=!0,mergeDefaults:a=!1,shallow:f,window:h=Oe,eventFilter:m,onError:_=w=>{console.error(w)},initOnMounted:C}=r,I=(f?Fr:se)(typeof t=="function"?t():t);if(!n)try{n=_i("getDefaultStorage",()=>{var w;return(w=Oe)==null?void 0:w.localStorage})()}catch(w){_(w)}if(!n)return I;const H=Fe(t),W=xa(H),D=(s=r.serializer)!=null?s:Sa[W],{pause:p,resume:y}=_a(I,()=>A(I.value),{flush:o,deep:i,eventFilter:m});h&&l&&Kr(()=>{Ct(h,"storage",$),Ct(h,Ks,L),C&&$()}),C||$();function M(w,N){h&&h.dispatchEvent(new CustomEvent(Ks,{detail:{key:e,oldValue:w,newValue:N,storageArea:n}}))}function A(w){try{const N=n.getItem(e);if(w==null)M(N,null),n.removeItem(e);else{const T=D.write(w);N!==T&&(n.setItem(e,T),M(N,T))}}catch(N){_(N)}}function F(w){const N=w?w.newValue:n.getItem(e);if(N==null)return c&&H!=null&&n.setItem(e,D.write(H)),H;if(!w&&a){const T=D.read(N);return typeof a=="function"?a(T,H):W==="object"&&!Array.isArray(T)?{...H,...T}:T}else return typeof N!="string"?N:D.read(N)}function $(w){if(!(w&&w.storageArea!==n)){if(w&&w.key==null){I.value=H;return}if(!(w&&w.key!==e)){p();try{(w==null?void 0:w.newValue)!==D.write(I.value)&&(I.value=F(w))}catch(N){_(N)}finally{w?In(y):y()}}}}function L(w){$(w.detail)}return I}function vi(e){return yi("(prefers-color-scheme: dark)",e)}function Ta(e={}){const{selector:t="html",attribute:n="class",initialValue:r="auto",window:s=Oe,storage:o,storageKey:i="vueuse-color-scheme",listenToStorageChanges:l=!0,storageRef:c,emitAuto:a,disableTransition:f=!0}=e,h={auto:"",light:"light",dark:"dark",...e.modes||{}},m=vi({window:s}),_=re(()=>m.value?"dark":"light"),C=c||(i==null?pi(r):Wr(i,r,o,{window:s,listenToStorageChanges:l})),I=re(()=>C.value==="auto"?_.value:C.value),H=_i("updateHTMLAttrs",(y,M,A)=>{const F=typeof y=="string"?s==null?void 0:s.document.querySelector(y):mi(y);if(!F)return;let $;if(f&&($=s.document.createElement("style"),$.appendChild(document.createTextNode("*,*::before,*::after{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}")),s.document.head.appendChild($)),M==="class"){const L=A.split(/\s/g);Object.values(h).flatMap(w=>(w||"").split(/\s/g)).filter(Boolean).forEach(w=>{L.includes(w)?F.classList.add(w):F.classList.remove(w)})}else F.setAttribute(M,A);f&&(s.getComputedStyle($).opacity,document.head.removeChild($))});function W(y){var M;H(t,n,(M=h[y])!=null?M:y)}function D(y){e.onChanged?e.onChanged(y,W):W(y)}Ne(I,D,{flush:"post",immediate:!0}),Kr(()=>D(I.value));const p=re({get(){return a?C.value:I.value},set(y){C.value=y}});try{return Object.assign(p,{store:C,system:_,state:I})}catch{return p}}function Aa(e={}){const{valueDark:t="dark",valueLight:n="",window:r=Oe}=e,s=Ta({...e,onChanged:(l,c)=>{var a;e.onChanged?(a=e.onChanged)==null||a.call(e,l==="dark",c,l):c(l)},modes:{dark:t,light:n}}),o=re(()=>s.system?s.system.value:vi({window:r}).value?"dark":"light");return re({get(){return s.value==="dark"},set(l){const c=l?"dark":"light";o.value===c?s.value="auto":s.value=c}})}function Zn(e){return typeof Window<"u"&&e instanceof Window?e.document.documentElement:typeof Document<"u"&&e instanceof Document?e.documentElement:e}function Ru(e,t,n={}){const{window:r=Oe}=n;return Wr(e,t,r==null?void 0:r.localStorage,n)}function bi(e){const t=window.getComputedStyle(e);if(t.overflowX==="scroll"||t.overflowY==="scroll"||t.overflowX==="auto"&&e.clientWidth<e.scrollWidth||t.overflowY==="auto"&&e.clientHeight<e.scrollHeight)return!0;{const n=e.parentNode;return!n||n.tagName==="BODY"?!1:bi(n)}}function Ra(e){const t=e||window.event,n=t.target;return bi(n)?!1:t.touches.length>1?!0:(t.preventDefault&&t.preventDefault(),!1)}const er=new WeakMap;function Ou(e,t=!1){const n=se(t);let r=null,s="";Ne(pi(e),l=>{const c=Zn(Fe(l));if(c){const a=c;if(er.get(a)||er.set(a,a.style.overflow),a.style.overflow!=="hidden"&&(s=a.style.overflow),a.style.overflow==="hidden")return n.value=!0;if(n.value)return a.style.overflow="hidden"}},{immediate:!0});const o=()=>{const l=Zn(Fe(e));!l||n.value||(ks&&(r=Ct(l,"touchmove",c=>{Ra(c)},{passive:!1})),l.style.overflow="hidden",n.value=!0)},i=()=>{const l=Zn(Fe(e));!l||!n.value||(ks&&(r==null||r()),l.style.overflow=s,er.delete(l),n.value=!1)};return kr(i),re({get(){return n.value},set(l){l?o():i()}})}function Lu(e,t,n={}){const{window:r=Oe}=n;return Wr(e,t,r==null?void 0:r.sessionStorage,n)}function Iu(e={}){const{window:t=Oe,behavior:n="auto"}=e;if(!t)return{x:se(0),y:se(0)};const r=se(t.scrollX),s=se(t.scrollY),o=re({get(){return r.value},set(l){scrollTo({left:l,behavior:n})}}),i=re({get(){return s.value},set(l){scrollTo({top:l,behavior:n})}});return Ct(t,"scroll",()=>{r.value=t.scrollX,s.value=t.scrollY},{capture:!1,passive:!0}),{x:o,y:i}}function Mu(e={}){const{window:t=Oe,initialWidth:n=Number.POSITIVE_INFINITY,initialHeight:r=Number.POSITIVE_INFINITY,listenOrientation:s=!0,includeScrollbar:o=!0}=e,i=se(n),l=se(r),c=()=>{t&&(o?(i.value=t.innerWidth,l.value=t.innerHeight):(i.value=t.document.documentElement.clientWidth,l.value=t.document.documentElement.clientHeight))};if(c(),Kr(c),Ct("resize",c,{passive:!0}),s){const a=yi("(orientation: portrait)");Ne(a,()=>c())}return{width:i,height:l}}var tr={BASE_URL:"/coa6/",MODE:"production",DEV:!1,PROD:!0,SSR:!1},nr={};const wi=/^(?:[a-z]+:|\/\/)/i,Oa="vitepress-theme-appearance",La=/#.*$/,Ia=/[?#].*$/,Ma=/(?:(^|\/)index)?\.(?:md|html)$/,he=typeof document<"u",Ei={relativePath:"404.md",filePath:"",title:"404",description:"Not Found",headers:[],frontmatter:{sidebar:!1,layout:"page"},lastUpdated:0,isNotFound:!0};function Pa(e,t,n=!1){if(t===void 0)return!1;if(e=Ws(`/${e}`),n)return new RegExp(t).test(e);if(Ws(t)!==e)return!1;const r=t.match(La);return r?(he?location.hash:"")===r[0]:!0}function Ws(e){return decodeURI(e).replace(Ia,"").replace(Ma,"$1")}function Na(e){return wi.test(e)}function Fa(e,t){return Object.keys((e==null?void 0:e.locales)||{}).find(n=>n!=="root"&&!Na(n)&&Pa(t,`/${n}/`,!0))||"root"}function $a(e,t){var r,s,o,i,l,c,a;const n=Fa(e,t);return Object.assign({},e,{localeIndex:n,lang:((r=e.locales[n])==null?void 0:r.lang)??e.lang,dir:((s=e.locales[n])==null?void 0:s.dir)??e.dir,title:((o=e.locales[n])==null?void 0:o.title)??e.title,titleTemplate:((i=e.locales[n])==null?void 0:i.titleTemplate)??e.titleTemplate,description:((l=e.locales[n])==null?void 0:l.description)??e.description,head:xi(e.head,((c=e.locales[n])==null?void 0:c.head)??[]),themeConfig:{...e.themeConfig,...(a=e.locales[n])==null?void 0:a.themeConfig}})}function Ci(e,t){const n=t.title||e.title,r=t.titleTemplate??e.titleTemplate;if(typeof r=="string"&&r.includes(":title"))return r.replace(/:title/g,n);const s=Ha(e.title,r);return n===s.slice(3)?n:`${n}${s}`}function Ha(e,t){return t===!1?"":t===!0||t===void 0?` | ${e}`:e===t?"":` | ${t}`}function ja(e,t){const[n,r]=t;if(n!=="meta")return!1;const s=Object.entries(r)[0];return s==null?!1:e.some(([o,i])=>o===n&&i[s[0]]===s[1])}function xi(e,t){return[...e.filter(n=>!ja(t,n)),...t]}const Va=/[\u0000-\u001F"#$&*+,:;<=>?[\]^`{|}\u007F]/g,Da=/^[a-z]:/i;function qs(e){const t=Da.exec(e),n=t?t[0]:"";return n+e.slice(n.length).replace(Va,"_").replace(/(^|\/)_+(?=[^/]*$)/,"$1")}const rr=new Set;function Ua(e){if(rr.size===0){const n=typeof process=="object"&&(nr==null?void 0:nr.VITE_EXTRA_EXTENSIONS)||(tr==null?void 0:tr.VITE_EXTRA_EXTENSIONS)||"";("3g2,3gp,aac,ai,apng,au,avif,bin,bmp,cer,class,conf,crl,css,csv,dll,doc,eps,epub,exe,gif,gz,ics,ief,jar,jpe,jpeg,jpg,js,json,jsonld,m4a,man,mid,midi,mjs,mov,mp2,mp3,mp4,mpe,mpeg,mpg,mpp,oga,ogg,ogv,ogx,opus,otf,p10,p7c,p7m,p7s,pdf,png,ps,qt,roff,rtf,rtx,ser,svg,t,tif,tiff,tr,ts,tsv,ttf,txt,vtt,wav,weba,webm,webp,woff,woff2,xhtml,xml,yaml,yml,zip"+(n&&typeof n=="string"?","+n:"")).split(",").forEach(r=>rr.add(r))}const t=e.split(".").pop();return t==null||!rr.has(t.toLowerCase())}function Pu(e){return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}const Ba=Symbol(),ut=Fr(ua);function Nu(e){const t=re(()=>$a(ut.value,e.data.relativePath)),n=t.value.appearance,r=n==="force-dark"?se(!0):n?Aa({storageKey:Oa,initialValue:()=>typeof n=="string"?n:"auto",...typeof n=="object"?n:{}}):se(!1),s=se(he?location.hash:"");return he&&window.addEventListener("hashchange",()=>{s.value=location.hash}),Ne(()=>e.data,()=>{s.value=he?location.hash:""}),{site:t,theme:re(()=>t.value.themeConfig),page:re(()=>e.data),frontmatter:re(()=>e.data.frontmatter),params:re(()=>e.data.params),lang:re(()=>t.value.lang),dir:re(()=>e.data.frontmatter.dir||t.value.dir),localeIndex:re(()=>t.value.localeIndex||"root"),title:re(()=>Ci(t.value,e.data)),description:re(()=>e.data.description||t.value.description),isDark:r,hash:re(()=>s.value)}}function ka(){const e=wt(Ba);if(!e)throw new Error("vitepress data not properly injected in app");return e}function Ka(e,t){return`${e}${t}`.replace(/\/+/g,"/")}function Gs(e){return wi.test(e)||!e.startsWith("/")?e:Ka(ut.value.base,e)}function Wa(e){let t=e.replace(/\.html$/,"");if(t=decodeURIComponent(t),t=t.replace(/\/$/,"/index"),he){const n="/coa6/";t=qs(t.slice(n.length).replace(/\//g,"_")||"index")+".md";let r=__VP_HASH_MAP__[t.toLowerCase()];if(r||(t=t.endsWith("_index.md")?t.slice(0,-9)+".md":t.slice(0,-3)+"_index.md",r=__VP_HASH_MAP__[t.toLowerCase()]),!r)return null;t=`${n}assets/${t}.${r}.js`}else t=`./${qs(t.slice(1).replace(/\//g,"_"))}.md.js`;return t}let gn=[];function Fu(e){gn.push(e),$n(()=>{gn=gn.filter(t=>t!==e)})}function qa(){let e=ut.value.scrollOffset,t=0,n=24;if(typeof e=="object"&&"padding"in e&&(n=e.padding,e=e.selector),typeof e=="number")t=e;else if(typeof e=="string")t=Xs(e,n);else if(Array.isArray(e))for(const r of e){const s=Xs(r,n);if(s){t=s;break}}return t}function Xs(e,t){const n=document.querySelector(e);if(!n)return 0;const r=n.getBoundingClientRect().bottom;return r<0?0:r+t}const Ga=Symbol(),Si="http://a.com",Xa=()=>({path:"/",component:null,data:Ei});function $u(e,t){const n=On(Xa()),r={route:n,go:s};async function s(l=he?location.href:"/"){var c,a;l=sr(l),await((c=r.onBeforeRouteChange)==null?void 0:c.call(r,l))!==!1&&(he&&l!==sr(location.href)&&(history.replaceState({scrollPosition:window.scrollY},""),history.pushState({},"",l)),await i(l),await((a=r.onAfterRouteChanged)==null?void 0:a.call(r,l)))}let o=null;async function i(l,c=0,a=!1){var m;if(await((m=r.onBeforePageLoad)==null?void 0:m.call(r,l))===!1)return;const f=new URL(l,Si),h=o=f.pathname;try{let _=await e(h);if(!_)throw new Error(`Page not found: ${h}`);if(o===h){o=null;const{default:C,__pageData:I}=_;if(!C)throw new Error(`Invalid route component: ${C}`);n.path=he?h:Gs(h),n.component=dn(C),n.data=dn(I),he&&In(()=>{let H=ut.value.base+I.relativePath.replace(/(?:(^|\/)index)?\.md$/,"$1");if(!ut.value.cleanUrls&&!H.endsWith("/")&&(H+=".html"),H!==f.pathname&&(f.pathname=H,l=H+f.search+f.hash,history.replaceState({},"",l)),f.hash&&!c){let W=null;try{W=document.getElementById(decodeURIComponent(f.hash).slice(1))}catch(D){console.warn(D)}if(W){Ys(W,f.hash);return}}window.scrollTo(0,c)})}}catch(_){if(!/fetch|Page not found/.test(_.message)&&!/^\/404(\.html|\/)?$/.test(l)&&console.error(_),!a)try{const C=await fetch(ut.value.base+"hashmap.json");window.__VP_HASH_MAP__=await C.json(),await i(l,c,!0);return}catch{}if(o===h){o=null,n.path=he?h:Gs(h),n.component=t?dn(t):null;const C=he?h.replace(/(^|\/)$/,"$1index").replace(/(\.html)?$/,".md").replace(/^\//,""):"404.md";n.data={...Ei,relativePath:C}}}}return he&&(history.state===null&&history.replaceState({},""),window.addEventListener("click",l=>{if(l.target.closest("button"))return;const a=l.target.closest("a");if(a&&!a.closest(".vp-raw")&&(a instanceof SVGElement||!a.download)){const{target:f}=a,{href:h,origin:m,pathname:_,hash:C,search:I}=new URL(a.href instanceof SVGAnimatedString?a.href.animVal:a.href,a.baseURI),H=new URL(location.href);!l.ctrlKey&&!l.shiftKey&&!l.altKey&&!l.metaKey&&!f&&m===H.origin&&Ua(_)&&(l.preventDefault(),_===H.pathname&&I===H.search?(C!==H.hash&&(history.pushState({},"",h),window.dispatchEvent(new HashChangeEvent("hashchange",{oldURL:H.href,newURL:h}))),C?Ys(a,C,a.classList.contains("header-anchor")):window.scrollTo(0,0)):s(h))}},{capture:!0}),window.addEventListener("popstate",async l=>{var c;l.state!==null&&(await i(sr(location.href),l.state&&l.state.scrollPosition||0),(c=r.onAfterRouteChanged)==null||c.call(r,location.href))}),window.addEventListener("hashchange",l=>{l.preventDefault()})),r}function Ya(){const e=wt(Ga);if(!e)throw new Error("useRouter() is called without provider.");return e}function Ti(){return Ya().route}function Ys(e,t,n=!1){let r=null;try{r=e.classList.contains("header-anchor")?e:document.getElementById(decodeURIComponent(t).slice(1))}catch(s){console.warn(s)}if(r){let s=function(){!n||Math.abs(i-window.scrollY)>window.innerHeight?window.scrollTo(0,i):window.scrollTo({left:0,top:i,behavior:"smooth"})};const o=parseInt(window.getComputedStyle(r).paddingTop,10),i=window.scrollY+r.getBoundingClientRect().top-qa()+o;requestAnimationFrame(s)}}function sr(e){const t=new URL(e,Si);return t.pathname=t.pathname.replace(/(^|\/)index(\.html)?$/,"$1"),ut.value.cleanUrls?t.pathname=t.pathname.replace(/\.html$/,""):!t.pathname.endsWith("/")&&!t.pathname.endsWith(".html")&&(t.pathname+=".html"),t.pathname+t.search+t.hash}const or=()=>gn.forEach(e=>e()),Hu=Hr({name:"VitePressContent",props:{as:{type:[Object,String],default:"div"}},setup(e){const t=Ti(),{site:n}=ka();return()=>br(e.as,n.value.contentProps??{style:{position:"relative"}},[t.component?br(t.component,{onVnodeMounted:or,onVnodeUpdated:or,onVnodeUnmounted:or}):"404 Page Not Found"])}}),ju=Hr({setup(e,{slots:t}){const n=se(!1);return xt(()=>{n.value=!0}),()=>n.value&&t.default?t.default():null}});function Vu(){he&&window.addEventListener("click",e=>{var n;const t=e.target;if(t.matches(".vp-code-group input")){const r=(n=t.parentElement)==null?void 0:n.parentElement;if(!r)return;const s=Array.from(r.querySelectorAll("input")).indexOf(t);if(s<0)return;const o=r.querySelector(".blocks");if(!o)return;const i=Array.from(o.children).find(a=>a.classList.contains("active"));if(!i)return;const l=o.children[s];if(!l||i===l)return;i.classList.remove("active"),l.classList.add("active");const c=r==null?void 0:r.querySelector(`label[for="${t.id}"]`);c==null||c.scrollIntoView({block:"nearest"})}})}function Du(){if(he){const e=new WeakMap;window.addEventListener("click",t=>{var r;const n=t.target;if(n.matches('div[class*="language-"] > button.copy')){const s=n.parentElement,o=(r=n.nextElementSibling)==null?void 0:r.nextElementSibling;if(!s||!o)return;const i=/language-(shellscript|shell|bash|sh|zsh)/.test(s.className),l=[".vp-copy-ignore",".diff.remove"],c=o.cloneNode(!0);c.querySelectorAll(l.join(",")).forEach(f=>f.remove());let a=c.textContent||"";i&&(a=a.replace(/^ *(\$|>) /gm,"").trim()),za(a).then(()=>{n.classList.add("copied"),clearTimeout(e.get(n));const f=setTimeout(()=>{n.classList.remove("copied"),n.blur(),e.delete(n)},2e3);e.set(n,f)})}})}}async function za(e){try{return navigator.clipboard.writeText(e)}catch{const t=document.createElement("textarea"),n=document.activeElement;t.value=e,t.setAttribute("readonly",""),t.style.contain="strict",t.style.position="absolute",t.style.left="-9999px",t.style.fontSize="12pt";const r=document.getSelection(),s=r?r.rangeCount>0&&r.getRangeAt(0):null;document.body.appendChild(t),t.select(),t.selectionStart=0,t.selectionEnd=e.length,document.execCommand("copy"),document.body.removeChild(t),s&&(r.removeAllRanges(),r.addRange(s)),n&&n.focus()}}function Uu(e,t){let n=!0,r=[];const s=o=>{if(n){n=!1,o.forEach(l=>{const c=ir(l);for(const a of document.head.children)if(a.isEqualNode(c)){r.push(a);return}});return}const i=o.map(ir);r.forEach((l,c)=>{const a=i.findIndex(f=>f==null?void 0:f.isEqualNode(l??null));a!==-1?delete i[a]:(l==null||l.remove(),delete r[c])}),i.forEach(l=>l&&document.head.appendChild(l)),r=[...r,...i].filter(Boolean)};Ur(()=>{const o=e.data,i=t.value,l=o&&o.description,c=o&&o.frontmatter.head||[],a=Ci(i,o);a!==document.title&&(document.title=a);const f=l||i.description;let h=document.querySelector("meta[name=description]");h?h.getAttribute("content")!==f&&h.setAttribute("content",f):ir(["meta",{name:"description",content:f}]),s(xi(i.head,Qa(c)))})}function ir([e,t,n]){const r=document.createElement(e);for(const s in t)r.setAttribute(s,t[s]);return n&&(r.innerHTML=n),e==="script"&&!t.async&&(r.async=!1),r}function Ja(e){return e[0]==="meta"&&e[1]&&e[1].name==="description"}function Qa(e){return e.filter(t=>!Ja(t))}const lr=new Set,Ai=()=>document.createElement("link"),Za=e=>{const t=Ai();t.rel="prefetch",t.href=e,document.head.appendChild(t)},eu=e=>{const t=new XMLHttpRequest;t.open("GET",e,t.withCredentials=!0),t.send()};let an;const tu=he&&(an=Ai())&&an.relList&&an.relList.supports&&an.relList.supports("prefetch")?Za:eu;function Bu(){if(!he||!window.IntersectionObserver)return;let e;if((e=navigator.connection)&&(e.saveData||/2g/.test(e.effectiveType)))return;const t=window.requestIdleCallback||setTimeout;let n=null;const r=()=>{n&&n.disconnect(),n=new IntersectionObserver(o=>{o.forEach(i=>{if(i.isIntersecting){const l=i.target;n.unobserve(l);const{pathname:c}=l;if(!lr.has(c)){lr.add(c);const a=Wa(c);a&&tu(a)}}})}),t(()=>{document.querySelectorAll("#app a").forEach(o=>{const{hostname:i,pathname:l}=new URL(o.href instanceof SVGAnimatedString?o.href.animVal:o.href,o.baseURI),c=l.match(/\.\w+$/);c&&c[0]!==".html"||o.target!=="_blank"&&i===location.hostname&&(l!==location.pathname?n.observe(o):lr.add(l))})})};xt(r);const s=Ti();Ne(()=>s.path,r),$n(()=>{n&&n.disconnect()})}export{bu as $,hu as A,Fl as B,qa as C,ou as D,cu as E,_e as F,Fr as G,Fu as H,ie as I,iu as J,wi as K,Ti as L,Ec as M,wt as N,Mu as O,Sr as P,Au as Q,In as R,Iu as S,li as T,he as U,Ln as V,au as W,xu as X,Ou as Y,Yl as Z,Cu as _,ri as a,fu as a0,vu as a1,du as a2,wu as a3,br as a4,mu as a5,Uu as a6,Ga as a7,Nu as a8,Ba as a9,Hu as aa,ju as ab,ut as ac,Eu as ad,$u as ae,Wa as af,Bu as ag,Du as ah,Vu as ai,mi as aj,kr as ak,Tu as al,Lu as am,Ru as an,Su as ao,Ya as ap,Ct as aq,Lo as ar,lu as as,_u as at,de as au,pu as av,dn as aw,Pu as ax,ei as b,gu as c,Hr as d,yu as e,Ua as f,Gs as g,re as h,Na as i,ni as j,bo as k,su as l,Pa as m,Tr as n,Qo as o,ru as p,yi as q,uu as r,se as s,nu as t,ka as u,Ne as v,Al as w,Ur as x,xt as y,$n as z};
|
66
assets/chunks/giscus-aTimukGI.CKTvSCx2.js
Normal file
@ -0,0 +1,66 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 Google LLC
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/const x=globalThis,j=x.ShadowRoot&&(x.ShadyCSS===void 0||x.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,W=Symbol(),q=new WeakMap;let ot=class{constructor(s,t,e){if(this._$cssResult$=!0,e!==W)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=s,this.t=t}get styleSheet(){let s=this.o;const t=this.t;if(j&&s===void 0){const e=t!==void 0&&t.length===1;e&&(s=q.get(t)),s===void 0&&((this.o=s=new CSSStyleSheet).replaceSync(this.cssText),e&&q.set(t,s))}return s}toString(){return this.cssText}};const pt=s=>new ot(typeof s=="string"?s:s+"",void 0,W),_t=(s,...t)=>{const e=s.length===1?s[0]:t.reduce((i,r,o)=>i+(n=>{if(n._$cssResult$===!0)return n.cssText;if(typeof n=="number")return n;throw Error("Value passed to 'css' function must be a 'css' function result: "+n+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(r)+s[o+1],s[0]);return new ot(e,s,W)},gt=(s,t)=>{if(j)s.adoptedStyleSheets=t.map(e=>e instanceof CSSStyleSheet?e:e.styleSheet);else for(const e of t){const i=document.createElement("style"),r=x.litNonce;r!==void 0&&i.setAttribute("nonce",r),i.textContent=e.cssText,s.appendChild(i)}},K=j?s=>s:s=>s instanceof CSSStyleSheet?(t=>{let e="";for(const i of t.cssRules)e+=i.cssText;return pt(e)})(s):s;/**
|
||||
* @license
|
||||
* Copyright 2017 Google LLC
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/const{is:$t,defineProperty:ft,getOwnPropertyDescriptor:mt,getOwnPropertyNames:vt,getOwnPropertySymbols:At,getPrototypeOf:yt}=Object,E=globalThis,Y=E.trustedTypes,St=Y?Y.emptyScript:"",J=E.reactiveElementPolyfillSupport,U=(s,t)=>s,H={toAttribute(s,t){switch(t){case Boolean:s=s?St:null;break;case Object:case Array:s=s==null?s:JSON.stringify(s)}return s},fromAttribute(s,t){let e=s;switch(t){case Boolean:e=s!==null;break;case Number:e=s===null?null:Number(s);break;case Object:case Array:try{e=JSON.parse(s)}catch{e=null}}return e}},V=(s,t)=>!$t(s,t),F={attribute:!0,type:String,converter:H,reflect:!1,hasChanged:V};Symbol.metadata??(Symbol.metadata=Symbol("metadata")),E.litPropertyMetadata??(E.litPropertyMetadata=new WeakMap);class S extends HTMLElement{static addInitializer(t){this._$Ei(),(this.l??(this.l=[])).push(t)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(t,e=F){if(e.state&&(e.attribute=!1),this._$Ei(),this.elementProperties.set(t,e),!e.noAccessor){const i=Symbol(),r=this.getPropertyDescriptor(t,i,e);r!==void 0&&ft(this.prototype,t,r)}}static getPropertyDescriptor(t,e,i){const{get:r,set:o}=mt(this.prototype,t)??{get(){return this[e]},set(n){this[e]=n}};return{get(){return r==null?void 0:r.call(this)},set(n){const a=r==null?void 0:r.call(this);o.call(this,n),this.requestUpdate(t,a,i)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??F}static _$Ei(){if(this.hasOwnProperty(U("elementProperties")))return;const t=yt(this);t.finalize(),t.l!==void 0&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties)}static finalize(){if(this.hasOwnProperty(U("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(U("properties"))){const e=this.properties,i=[...vt(e),...At(e)];for(const r of i)this.createProperty(r,e[r])}const t=this[Symbol.metadata];if(t!==null){const e=litPropertyMetadata.get(t);if(e!==void 0)for(const[i,r]of e)this.elementProperties.set(i,r)}this._$Eh=new Map;for(const[e,i]of this.elementProperties){const r=this._$Eu(e,i);r!==void 0&&this._$Eh.set(r,e)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const i=new Set(t.flat(1/0).reverse());for(const r of i)e.unshift(K(r))}else t!==void 0&&e.push(K(t));return e}static _$Eu(t,e){const i=e.attribute;return i===!1?void 0:typeof i=="string"?i:typeof t=="string"?t.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){var t;this._$Eg=new Promise(e=>this.enableUpdating=e),this._$AL=new Map,this._$ES(),this.requestUpdate(),(t=this.constructor.l)==null||t.forEach(e=>e(this))}addController(t){var e;(this._$E_??(this._$E_=new Set)).add(t),this.renderRoot!==void 0&&this.isConnected&&((e=t.hostConnected)==null||e.call(t))}removeController(t){var e;(e=this._$E_)==null||e.delete(t)}_$ES(){const t=new Map,e=this.constructor.elementProperties;for(const i of e.keys())this.hasOwnProperty(i)&&(t.set(i,this[i]),delete this[i]);t.size>0&&(this._$Ep=t)}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return gt(t,this.constructor.elementStyles),t}connectedCallback(){var t;this.renderRoot??(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),(t=this._$E_)==null||t.forEach(e=>{var i;return(i=e.hostConnected)==null?void 0:i.call(e)})}enableUpdating(t){}disconnectedCallback(){var t;(t=this._$E_)==null||t.forEach(e=>{var i;return(i=e.hostDisconnected)==null?void 0:i.call(e)})}attributeChangedCallback(t,e,i){this._$AK(t,i)}_$EO(t,e){var i;const r=this.constructor.elementProperties.get(t),o=this.constructor._$Eu(t,r);if(o!==void 0&&r.reflect===!0){const n=(((i=r.converter)==null?void 0:i.toAttribute)!==void 0?r.converter:H).toAttribute(e,r.type);this._$Em=t,n==null?this.removeAttribute(o):this.setAttribute(o,n),this._$Em=null}}_$AK(t,e){var i;const r=this.constructor,o=r._$Eh.get(t);if(o!==void 0&&this._$Em!==o){const n=r.getPropertyOptions(o),a=typeof n.converter=="function"?{fromAttribute:n.converter}:((i=n.converter)==null?void 0:i.fromAttribute)!==void 0?n.converter:H;this._$Em=o,this[o]=a.fromAttribute(e,n.type),this._$Em=null}}requestUpdate(t,e,i,r=!1,o){if(t!==void 0){if(i??(i=this.constructor.getPropertyOptions(t)),!(i.hasChanged??V)(r?o:this[t],e))return;this.C(t,e,i)}this.isUpdatePending===!1&&(this._$Eg=this._$EP())}C(t,e,i){this._$AL.has(t)||this._$AL.set(t,e),i.reflect===!0&&this._$Em!==t&&(this._$Ej??(this._$Ej=new Set)).add(t)}async _$EP(){this.isUpdatePending=!0;try{await this._$Eg}catch(e){Promise.reject(e)}const t=this.scheduleUpdate();return t!=null&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var t;if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??(this.renderRoot=this.createRenderRoot()),this._$Ep){for(const[o,n]of this._$Ep)this[o]=n;this._$Ep=void 0}const r=this.constructor.elementProperties;if(r.size>0)for(const[o,n]of r)n.wrapped!==!0||this._$AL.has(o)||this[o]===void 0||this.C(o,this[o],n)}let e=!1;const i=this._$AL;try{e=this.shouldUpdate(i),e?(this.willUpdate(i),(t=this._$E_)==null||t.forEach(r=>{var o;return(o=r.hostUpdate)==null?void 0:o.call(r)}),this.update(i)):this._$ET()}catch(r){throw e=!1,this._$ET(),r}e&&this._$AE(i)}willUpdate(t){}_$AE(t){var e;(e=this._$E_)==null||e.forEach(i=>{var r;return(r=i.hostUpdated)==null?void 0:r.call(i)}),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$ET(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$Eg}shouldUpdate(t){return!0}update(t){this._$Ej&&(this._$Ej=this._$Ej.forEach(e=>this._$EO(e,this[e]))),this._$ET()}updated(t){}firstUpdated(t){}}S.elementStyles=[],S.shadowRootOptions={mode:"open"},S[U("elementProperties")]=new Map,S[U("finalized")]=new Map,J==null||J({ReactiveElement:S}),(E.reactiveElementVersions??(E.reactiveElementVersions=[])).push("2.0.2");/**
|
||||
* @license
|
||||
* Copyright 2017 Google LLC
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/const L=globalThis,k=L.trustedTypes,Q=k?k.createPolicy("lit-html",{createHTML:s=>s}):void 0,at="$lit$",m=`lit$${(Math.random()+"").slice(9)}$`,ht="?"+m,Et=`<${ht}>`,y=document,O=()=>y.createComment(""),R=s=>s===null||typeof s!="object"&&typeof s!="function",lt=Array.isArray,bt=s=>lt(s)||typeof(s==null?void 0:s[Symbol.iterator])=="function",z=`[
|
||||
\f\r]`,w=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,Z=/-->/g,X=/>/g,v=RegExp(`>|${z}(?:([^\\s"'>=/]+)(${z}*=${z}*(?:[^
|
||||
\f\r"'\`<>=]|("|')|))|$)`,"g"),tt=/'/g,et=/"/g,ct=/^(?:script|style|textarea|title)$/i,Ct=s=>(t,...e)=>({_$litType$:s,strings:t,values:e}),wt=Ct(1),b=Symbol.for("lit-noChange"),c=Symbol.for("lit-nothing"),st=new WeakMap,A=y.createTreeWalker(y,129);function dt(s,t){if(!Array.isArray(s)||!s.hasOwnProperty("raw"))throw Error("invalid template strings array");return Q!==void 0?Q.createHTML(t):t}const Ut=(s,t)=>{const e=s.length-1,i=[];let r,o=t===2?"<svg>":"",n=w;for(let a=0;a<e;a++){const h=s[a];let g,u,l=-1,$=0;for(;$<h.length&&(n.lastIndex=$,u=n.exec(h),u!==null);)$=n.lastIndex,n===w?u[1]==="!--"?n=Z:u[1]!==void 0?n=X:u[2]!==void 0?(ct.test(u[2])&&(r=RegExp("</"+u[2],"g")),n=v):u[3]!==void 0&&(n=v):n===v?u[0]===">"?(n=r??w,l=-1):u[1]===void 0?l=-2:(l=n.lastIndex-u[2].length,g=u[1],n=u[3]===void 0?v:u[3]==='"'?et:tt):n===et||n===tt?n=v:n===Z||n===X?n=w:(n=v,r=void 0);const f=n===v&&s[a+1].startsWith("/>")?" ":"";o+=n===w?h+Et:l>=0?(i.push(g),h.slice(0,l)+at+h.slice(l)+m+f):h+m+(l===-2?a:f)}return[dt(s,o+(s[e]||"<?>")+(t===2?"</svg>":"")),i]};class N{constructor({strings:t,_$litType$:e},i){let r;this.parts=[];let o=0,n=0;const a=t.length-1,h=this.parts,[g,u]=Ut(t,e);if(this.el=N.createElement(g,i),A.currentNode=this.el.content,e===2){const l=this.el.content.firstChild;l.replaceWith(...l.childNodes)}for(;(r=A.nextNode())!==null&&h.length<a;){if(r.nodeType===1){if(r.hasAttributes())for(const l of r.getAttributeNames())if(l.endsWith(at)){const $=u[n++],f=r.getAttribute(l).split(m),I=/([.?@])?(.*)/.exec($);h.push({type:1,index:o,name:I[2],strings:f,ctor:I[1]==="."?Tt:I[1]==="?"?Ot:I[1]==="@"?Rt:D}),r.removeAttribute(l)}else l.startsWith(m)&&(h.push({type:6,index:o}),r.removeAttribute(l));if(ct.test(r.tagName)){const l=r.textContent.split(m),$=l.length-1;if($>0){r.textContent=k?k.emptyScript:"";for(let f=0;f<$;f++)r.append(l[f],O()),A.nextNode(),h.push({type:2,index:++o});r.append(l[$],O())}}}else if(r.nodeType===8)if(r.data===ht)h.push({type:2,index:o});else{let l=-1;for(;(l=r.data.indexOf(m,l+1))!==-1;)h.push({type:7,index:o}),l+=m.length-1}o++}}static createElement(t,e){const i=y.createElement("template");return i.innerHTML=t,i}}function C(s,t,e=s,i){var r,o;if(t===b)return t;let n=i!==void 0?(r=e._$Co)==null?void 0:r[i]:e._$Cl;const a=R(t)?void 0:t._$litDirective$;return(n==null?void 0:n.constructor)!==a&&((o=n==null?void 0:n._$AO)==null||o.call(n,!1),a===void 0?n=void 0:(n=new a(s),n._$AT(s,e,i)),i!==void 0?(e._$Co??(e._$Co=[]))[i]=n:e._$Cl=n),n!==void 0&&(t=C(s,n._$AS(s,t.values),n,i)),t}let Pt=class{constructor(s,t){this._$AV=[],this._$AN=void 0,this._$AD=s,this._$AM=t}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(s){const{el:{content:t},parts:e}=this._$AD,i=((s==null?void 0:s.creationScope)??y).importNode(t,!0);A.currentNode=i;let r=A.nextNode(),o=0,n=0,a=e[0];for(;a!==void 0;){if(o===a.index){let h;a.type===2?h=new M(r,r.nextSibling,this,s):a.type===1?h=new a.ctor(r,a.name,a.strings,this,s):a.type===6&&(h=new Nt(r,this,s)),this._$AV.push(h),a=e[++n]}o!==(a==null?void 0:a.index)&&(r=A.nextNode(),o++)}return A.currentNode=y,i}p(s){let t=0;for(const e of this._$AV)e!==void 0&&(e.strings!==void 0?(e._$AI(s,e,t),t+=e.strings.length-2):e._$AI(s[t])),t++}};class M{get _$AU(){var t;return((t=this._$AM)==null?void 0:t._$AU)??this._$Cv}constructor(t,e,i,r){this.type=2,this._$AH=c,this._$AN=void 0,this._$AA=t,this._$AB=e,this._$AM=i,this.options=r,this._$Cv=(r==null?void 0:r.isConnected)??!0}get parentNode(){let t=this._$AA.parentNode;const e=this._$AM;return e!==void 0&&(t==null?void 0:t.nodeType)===11&&(t=e.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,e=this){t=C(this,t,e),R(t)?t===c||t==null||t===""?(this._$AH!==c&&this._$AR(),this._$AH=c):t!==this._$AH&&t!==b&&this._(t):t._$litType$!==void 0?this.g(t):t.nodeType!==void 0?this.$(t):bt(t)?this.T(t):this._(t)}k(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}$(t){this._$AH!==t&&(this._$AR(),this._$AH=this.k(t))}_(t){this._$AH!==c&&R(this._$AH)?this._$AA.nextSibling.data=t:this.$(y.createTextNode(t)),this._$AH=t}g(t){var e;const{values:i,_$litType$:r}=t,o=typeof r=="number"?this._$AC(t):(r.el===void 0&&(r.el=N.createElement(dt(r.h,r.h[0]),this.options)),r);if(((e=this._$AH)==null?void 0:e._$AD)===o)this._$AH.p(i);else{const n=new Pt(o,this),a=n.u(this.options);n.p(i),this.$(a),this._$AH=n}}_$AC(t){let e=st.get(t.strings);return e===void 0&&st.set(t.strings,e=new N(t)),e}T(t){lt(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let i,r=0;for(const o of t)r===e.length?e.push(i=new M(this.k(O()),this.k(O()),this,this.options)):i=e[r],i._$AI(o),r++;r<e.length&&(this._$AR(i&&i._$AB.nextSibling,r),e.length=r)}_$AR(t=this._$AA.nextSibling,e){var i;for((i=this._$AP)==null?void 0:i.call(this,!1,!0,e);t&&t!==this._$AB;){const r=t.nextSibling;t.remove(),t=r}}setConnected(t){var e;this._$AM===void 0&&(this._$Cv=t,(e=this._$AP)==null||e.call(this,t))}}class D{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(t,e,i,r,o){this.type=1,this._$AH=c,this._$AN=void 0,this.element=t,this.name=e,this._$AM=r,this.options=o,i.length>2||i[0]!==""||i[1]!==""?(this._$AH=Array(i.length-1).fill(new String),this.strings=i):this._$AH=c}_$AI(t,e=this,i,r){const o=this.strings;let n=!1;if(o===void 0)t=C(this,t,e,0),n=!R(t)||t!==this._$AH&&t!==b,n&&(this._$AH=t);else{const a=t;let h,g;for(t=o[0],h=0;h<o.length-1;h++)g=C(this,a[i+h],e,h),g===b&&(g=this._$AH[h]),n||(n=!R(g)||g!==this._$AH[h]),g===c?t=c:t!==c&&(t+=(g??"")+o[h+1]),this._$AH[h]=g}n&&!r&&this.O(t)}O(t){t===c?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t??"")}}class Tt extends D{constructor(){super(...arguments),this.type=3}O(t){this.element[this.name]=t===c?void 0:t}}class Ot extends D{constructor(){super(...arguments),this.type=4}O(t){this.element.toggleAttribute(this.name,!!t&&t!==c)}}class Rt extends D{constructor(t,e,i,r,o){super(t,e,i,r,o),this.type=5}_$AI(t,e=this){if((t=C(this,t,e,0)??c)===b)return;const i=this._$AH,r=t===c&&i!==c||t.capture!==i.capture||t.once!==i.once||t.passive!==i.passive,o=t!==c&&(i===c||r);r&&this.element.removeEventListener(this.name,this,i),o&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){var e;typeof this._$AH=="function"?this._$AH.call(((e=this.options)==null?void 0:e.host)??this.element,t):this._$AH.handleEvent(t)}}class Nt{constructor(t,e,i){this.element=t,this.type=6,this._$AN=void 0,this._$AM=e,this.options=i}get _$AU(){return this._$AM._$AU}_$AI(t){C(this,t)}}const it=L.litHtmlPolyfillSupport;it==null||it(N,M),(L.litHtmlVersions??(L.litHtmlVersions=[])).push("3.1.0");const Mt=(s,t,e)=>{const i=(e==null?void 0:e.renderBefore)??t;let r=i._$litPart$;if(r===void 0){const o=(e==null?void 0:e.renderBefore)??null;i._$litPart$=r=new M(t.insertBefore(O(),o),o,void 0,e??{})}return r._$AI(s),r};/**
|
||||
* @license
|
||||
* Copyright 2017 Google LLC
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/let P=class extends S{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){var s;const t=super.createRenderRoot();return(s=this.renderOptions).renderBefore??(s.renderBefore=t.firstChild),t}update(s){const t=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(s),this._$Do=Mt(t,this.renderRoot,this.renderOptions)}connectedCallback(){var s;super.connectedCallback(),(s=this._$Do)==null||s.setConnected(!0)}disconnectedCallback(){var s;super.disconnectedCallback(),(s=this._$Do)==null||s.setConnected(!1)}render(){return b}};var rt;P._$litElement$=!0,P.finalized=!0,(rt=globalThis.litElementHydrateSupport)==null||rt.call(globalThis,{LitElement:P});const nt=globalThis.litElementPolyfillSupport;nt==null||nt({LitElement:P});(globalThis.litElementVersions??(globalThis.litElementVersions=[])).push("4.0.2");/**
|
||||
* @license
|
||||
* Copyright 2017 Google LLC
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/const It=s=>(t,e)=>{e!==void 0?e.addInitializer(()=>{customElements.define(s,t)}):customElements.define(s,t)};/**
|
||||
* @license
|
||||
* Copyright 2017 Google LLC
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/const xt={attribute:!0,type:String,converter:H,reflect:!1,hasChanged:V},Ht=(s=xt,t,e)=>{const{kind:i,metadata:r}=e;let o=globalThis.litPropertyMetadata.get(r);if(o===void 0&&globalThis.litPropertyMetadata.set(r,o=new Map),o.set(e.name,s),i==="accessor"){const{name:n}=e;return{set(a){const h=t.get.call(this);t.set.call(this,a),this.requestUpdate(n,h,s)},init(a){return a!==void 0&&this.C(n,void 0,s),a}}}if(i==="setter"){const{name:n}=e;return function(a){const h=this[n];t.call(this,a),this.requestUpdate(n,h,s)}}throw Error("Unsupported decorator location: "+i)};function _(s){return(t,e)=>typeof e=="object"?Ht(s,t,e):((i,r,o)=>{const n=r.hasOwnProperty(o);return r.constructor.createProperty(o,n?{...i,wrapped:!0}:i),n?Object.getOwnPropertyDescriptor(r,o):void 0})(s,t,e)}/**
|
||||
* @license
|
||||
* Copyright 2020 Google LLC
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/const Lt=s=>s.strings===void 0;/**
|
||||
* @license
|
||||
* Copyright 2017 Google LLC
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/const kt={ATTRIBUTE:1,CHILD:2,PROPERTY:3,BOOLEAN_ATTRIBUTE:4,EVENT:5,ELEMENT:6},Gt=s=>(...t)=>({_$litDirective$:s,values:t});let Dt=class{constructor(s){}get _$AU(){return this._$AM._$AU}_$AT(s,t,e){this._$Ct=s,this._$AM=t,this._$Ci=e}_$AS(s,t){return this.update(s,t)}update(s,t){return this.render(...t)}};/**
|
||||
* @license
|
||||
* Copyright 2017 Google LLC
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/const T=(s,t)=>{var e;const i=s._$AN;if(i===void 0)return!1;for(const r of i)(e=r._$AO)==null||e.call(r,t,!1),T(r,t);return!0},G=s=>{let t,e;do{if((t=s._$AM)===void 0)break;e=t._$AN,e.delete(s),s=t}while((e==null?void 0:e.size)===0)},ut=s=>{for(let t;t=s._$AM;s=t){let e=t._$AN;if(e===void 0)t._$AN=e=new Set;else if(e.has(s))break;e.add(s),jt(t)}};function zt(s){this._$AN!==void 0?(G(this),this._$AM=s,ut(this)):this._$AM=s}function Bt(s,t=!1,e=0){const i=this._$AH,r=this._$AN;if(r!==void 0&&r.size!==0)if(t)if(Array.isArray(i))for(let o=e;o<i.length;o++)T(i[o],!1),G(i[o]);else i!=null&&(T(i,!1),G(i));else T(this,s)}const jt=s=>{s.type==kt.CHILD&&(s._$AP??(s._$AP=Bt),s._$AQ??(s._$AQ=zt))};class Wt extends Dt{constructor(){super(...arguments),this._$AN=void 0}_$AT(t,e,i){super._$AT(t,e,i),ut(this),this.isConnected=t._$AU}_$AO(t,e=!0){var i,r;t!==this.isConnected&&(this.isConnected=t,t?(i=this.reconnected)==null||i.call(this):(r=this.disconnected)==null||r.call(this)),e&&(T(this,t),G(this))}setValue(t){if(Lt(this._$Ct))this._$Ct._$AI(t,this);else{const e=[...this._$Ct._$AH];e[this._$Ci]=t,this._$Ct._$AI(e,this,0)}}disconnected(){}reconnected(){}}/**
|
||||
* @license
|
||||
* Copyright 2020 Google LLC
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/const Vt=()=>new qt;class qt{}const B=new WeakMap,Kt=Gt(class extends Wt{render(s){return c}update(s,[t]){var e;const i=t!==this.G;return i&&this.G!==void 0&&this.ot(void 0),(i||this.rt!==this.lt)&&(this.G=t,this.ct=(e=s.options)==null?void 0:e.host,this.ot(this.lt=s.element)),c}ot(s){if(typeof this.G=="function"){const t=this.ct??globalThis;let e=B.get(t);e===void 0&&(e=new WeakMap,B.set(t,e)),e.get(this.G)!==void 0&&this.G.call(this.ct,void 0),e.set(this.G,s),s!==void 0&&this.G.call(this.ct,s)}else this.G.value=s}get rt(){var s,t;return typeof this.G=="function"?(s=B.get(this.ct??globalThis))==null?void 0:s.get(this.G):(t=this.G)==null?void 0:t.value}disconnected(){this.rt===this.lt&&this.ot(void 0)}reconnected(){this.ot(this.lt)}});var Yt=Object.defineProperty,Jt=Object.getOwnPropertyDescriptor,p=(s,t,e,i)=>{for(var r=i>1?void 0:i?Jt(t,e):t,o=s.length-1,n;o>=0;o--)(n=s[o])&&(r=(i?n(t,e,r):n(r))||r);return i&&r&&Yt(t,e,r),r};function Ft(s){return customElements.get(s)?t=>t:It(s)}let d=class extends P{constructor(){super(),this.GISCUS_SESSION_KEY="giscus-session",this.GISCUS_DEFAULT_HOST="https://giscus.app",this.ERROR_SUGGESTION="Please consider reporting this error at https://github.com/giscus/giscus/issues/new.",this.__session="",this._iframeRef=Vt(),this.messageEventHandler=this.handleMessageEvent.bind(this),this.hasLoaded=!1,this.host=this.GISCUS_DEFAULT_HOST,this.strict="0",this.reactionsEnabled="1",this.emitMetadata="0",this.inputPosition="bottom",this.theme="light",this.lang="en",this.loading="eager",this.setupSession(),window.addEventListener("message",this.messageEventHandler)}get iframeRef(){var s;return(s=this._iframeRef)==null?void 0:s.value}get _host(){try{return new URL(this.host),this.host}catch{return this.GISCUS_DEFAULT_HOST}}disconnectedCallback(){super.disconnectedCallback(),window.removeEventListener("message",this.messageEventHandler)}_formatError(s){return`[giscus] An error occurred. Error message: "${s}".`}setupSession(){const s=location.href,t=new URL(s),e=localStorage.getItem(this.GISCUS_SESSION_KEY),i=t.searchParams.get("giscus")??"";if(this.__session="",i){localStorage.setItem(this.GISCUS_SESSION_KEY,JSON.stringify(i)),this.__session=i,t.searchParams.delete("giscus"),t.hash="",history.replaceState(void 0,document.title,t.toString());return}if(e)try{this.__session=JSON.parse(e)}catch(r){localStorage.removeItem(this.GISCUS_SESSION_KEY),console.warn(`${this._formatError(r==null?void 0:r.message)} Session has been cleared.`)}}signOut(){localStorage.removeItem(this.GISCUS_SESSION_KEY),this.__session="",this.update(new Map)}handleMessageEvent(s){if(s.origin!==this._host)return;const{data:t}=s;if(!(typeof t=="object"&&t.giscus))return;if(this.iframeRef&&t.giscus.resizeHeight&&(this.iframeRef.style.height=`${t.giscus.resizeHeight}px`),t.giscus.signOut){console.info("[giscus] User has logged out. Session has been cleared."),this.signOut();return}if(!t.giscus.error)return;const e=t.giscus.error;if(e.includes("Bad credentials")||e.includes("Invalid state value")||e.includes("State has expired")){if(localStorage.getItem(this.GISCUS_SESSION_KEY)!==null){console.warn(`${this._formatError(e)} Session has been cleared.`),this.signOut();return}console.error(`${this._formatError(e)} No session is stored initially. ${this.ERROR_SUGGESTION}`)}if(e.includes("Discussion not found")){console.warn(`[giscus] ${e}. A new discussion will be created if a comment/reaction is submitted.`);return}console.error(`${this._formatError(e)} ${this.ERROR_SUGGESTION}`)}sendMessage(s){var t;!((t=this.iframeRef)!=null&&t.contentWindow)||!this.hasLoaded||this.iframeRef.contentWindow.postMessage({giscus:s},this._host)}updateConfig(){const s={setConfig:{repo:this.repo,repoId:this.repoId,category:this.category,categoryId:this.categoryId,term:this.getTerm(),number:+this.getNumber(),strict:this.strict==="1",reactionsEnabled:this.reactionsEnabled==="1",emitMetadata:this.emitMetadata==="1",inputPosition:this.inputPosition,theme:this.theme,lang:this.lang}};this.sendMessage(s)}firstUpdated(){var s;(s=this.iframeRef)==null||s.addEventListener("load",()=>{var t;(t=this.iframeRef)==null||t.classList.remove("loading"),this.hasLoaded=!0,this.updateConfig()})}requestUpdate(s,t,e){if(!this.hasUpdated||s==="host"){super.requestUpdate(s,t,e);return}this.updateConfig()}getMetaContent(s,t=!1){const e=t?`meta[property='og:${s}'],`:"",i=document.querySelector(e+`meta[name='${s}']`);return i?i.content:""}_getCleanedUrl(){const s=new URL(location.href);return s.searchParams.delete("giscus"),s.hash="",s}getTerm(){switch(this.mapping){case"url":return this._getCleanedUrl().toString();case"title":return document.title;case"og:title":return this.getMetaContent("title",!0);case"specific":return this.term??"";case"number":return"";case"pathname":default:return location.pathname.length<2?"index":location.pathname.substring(1).replace(/\.\w+$/,"")}}getNumber(){return this.mapping==="number"?this.term??"":""}getIframeSrc(){const s=this._getCleanedUrl().toString(),t=`${s}${this.id?"#"+this.id:""}`,e=this.getMetaContent("description",!0),i=this.getMetaContent("giscus:backlink")||s,r={origin:t,session:this.__session,repo:this.repo,repoId:this.repoId??"",category:this.category??"",categoryId:this.categoryId??"",term:this.getTerm(),number:this.getNumber(),strict:this.strict,reactionsEnabled:this.reactionsEnabled,emitMetadata:this.emitMetadata,inputPosition:this.inputPosition,theme:this.theme,description:e,backLink:i},o=this._host,n=this.lang?`/${this.lang}`:"",a=new URLSearchParams(r);return`${o}${n}/widget?${a.toString()}`}render(){return wt`
|
||||
<iframe
|
||||
title="Comments"
|
||||
scrolling="no"
|
||||
class="loading"
|
||||
${Kt(this._iframeRef)}
|
||||
src=${this.getIframeSrc()}
|
||||
loading=${this.loading}
|
||||
allow="clipboard-write"
|
||||
part="iframe"
|
||||
></iframe>
|
||||
`}};d.styles=_t`
|
||||
:host,
|
||||
iframe {
|
||||
width: 100%;
|
||||
border: none;
|
||||
min-height: 150px;
|
||||
color-scheme: light dark;
|
||||
}
|
||||
|
||||
iframe.loading {
|
||||
opacity: 0;
|
||||
}
|
||||
`;p([_({reflect:!0})],d.prototype,"host",2);p([_({reflect:!0})],d.prototype,"repo",2);p([_({reflect:!0})],d.prototype,"repoId",2);p([_({reflect:!0})],d.prototype,"category",2);p([_({reflect:!0})],d.prototype,"categoryId",2);p([_({reflect:!0})],d.prototype,"mapping",2);p([_({reflect:!0})],d.prototype,"term",2);p([_({reflect:!0})],d.prototype,"strict",2);p([_({reflect:!0})],d.prototype,"reactionsEnabled",2);p([_({reflect:!0})],d.prototype,"emitMetadata",2);p([_({reflect:!0})],d.prototype,"inputPosition",2);p([_({reflect:!0})],d.prototype,"theme",2);p([_({reflect:!0})],d.prototype,"lang",2);p([_({reflect:!0})],d.prototype,"loading",2);d=p([Ft("giscus-widget")],d);export{d as GiscusWidget};
|
4
assets/chunks/theme.DstJSxiY.js
Normal file
1
assets/index.md.LKQAh9T8.js
Normal file
@ -0,0 +1 @@
|
||||
import{_ as t,c as e,o as a}from"./chunks/framework.D1oHBMsh.js";const c=JSON.parse('{"title":"许大仙的博客","titleTemplate":"Hi,终于等到你","description":"许大仙前端、Java、大数据、云原生","frontmatter":{"layout":"home","home":true,"title":"许大仙的博客","titleTemplate":"Hi,终于等到你","editLink":true,"lastUpdated":true,"head":[["meta",{"name":"description","content":"许大仙前端、Java、大数据、云原生"}],["meta",{"name":"keywords","content":"许大仙,许大仙的博客"}]],"hero":{"name":"许大仙同学","text":"","tagline":"『这个世纪疯狂,没人性,腐败;你却一直清醒,温柔,一尘不染。』","actions":[{"theme":"brand","text":"首页","link":"https://aexiar.github.io"},{"theme":"alt","text":"c/c++","link":"/notes/"},{"theme":"alt","text":"计组6件套","link":"https://aexiar.github.io/coa6/notes/"},{"theme":"alt","text":"前端","link":"https://aexiar.github.io/web-design/notes/"},{"theme":"alt","text":"Java","link":"https://aexiar.github.io/java/notes/"},{"theme":"alt","text":"大数据","link":"https://aexiar.github.io/big-data/notes/"},{"theme":"alt","text":"云原生","link":"https://aexiar.github.io/linux/notes/"}]},"features":[{"title":"学习思路","details":"学习思路就这么几条:模仿、遍历、分治、动态规划、……"},{"title":"学习手法","details":"学习手法就这么几种:缓存、索引、信号/事件、回调/消息循环/dispatcher、……"},{"title":"注意事项","details":"注意事项就这么几点:边界值、等价类、数据完整性原子性、死锁、空转、……"}]},"headers":[],"relativePath":"index.md","filePath":"index.md","lastUpdated":1720685105000}'),i={name:"index.md"};function n(o,s,l,r,d,h){return a(),e("div")}const p=t(i,[["render",n]]);export{c as __pageData,p as default};
|
1
assets/index.md.LKQAh9T8.lean.js
Normal file
@ -0,0 +1 @@
|
||||
import{_ as t,c as e,o as a}from"./chunks/framework.D1oHBMsh.js";const c=JSON.parse('{"title":"许大仙的博客","titleTemplate":"Hi,终于等到你","description":"许大仙前端、Java、大数据、云原生","frontmatter":{"layout":"home","home":true,"title":"许大仙的博客","titleTemplate":"Hi,终于等到你","editLink":true,"lastUpdated":true,"head":[["meta",{"name":"description","content":"许大仙前端、Java、大数据、云原生"}],["meta",{"name":"keywords","content":"许大仙,许大仙的博客"}]],"hero":{"name":"许大仙同学","text":"","tagline":"『这个世纪疯狂,没人性,腐败;你却一直清醒,温柔,一尘不染。』","actions":[{"theme":"brand","text":"首页","link":"https://aexiar.github.io"},{"theme":"alt","text":"c/c++","link":"/notes/"},{"theme":"alt","text":"计组6件套","link":"https://aexiar.github.io/coa6/notes/"},{"theme":"alt","text":"前端","link":"https://aexiar.github.io/web-design/notes/"},{"theme":"alt","text":"Java","link":"https://aexiar.github.io/java/notes/"},{"theme":"alt","text":"大数据","link":"https://aexiar.github.io/big-data/notes/"},{"theme":"alt","text":"云原生","link":"https://aexiar.github.io/linux/notes/"}]},"features":[{"title":"学习思路","details":"学习思路就这么几条:模仿、遍历、分治、动态规划、……"},{"title":"学习手法","details":"学习手法就这么几种:缓存、索引、信号/事件、回调/消息循环/dispatcher、……"},{"title":"注意事项","details":"注意事项就这么几点:边界值、等价类、数据完整性原子性、死锁、空转、……"}]},"headers":[],"relativePath":"index.md","filePath":"index.md","lastUpdated":1720685105000}'),i={name:"index.md"};function n(o,s,l,r,d,h){return a(),e("div")}const p=t(i,[["render",n]]);export{c as __pageData,p as default};
|
BIN
assets/inter-italic-cyrillic-ext.r48I6akx.woff2
Normal file
BIN
assets/inter-italic-cyrillic.By2_1cv3.woff2
Normal file
BIN
assets/inter-italic-greek-ext.1u6EdAuj.woff2
Normal file
BIN
assets/inter-italic-greek.DJ8dCoTZ.woff2
Normal file
BIN
assets/inter-italic-latin-ext.CN1xVJS-.woff2
Normal file
BIN
assets/inter-italic-latin.C2AdPX0b.woff2
Normal file
BIN
assets/inter-italic-vietnamese.BSbpV94h.woff2
Normal file
BIN
assets/inter-roman-cyrillic-ext.BBPuwvHQ.woff2
Normal file
BIN
assets/inter-roman-cyrillic.C5lxZ8CY.woff2
Normal file
BIN
assets/inter-roman-greek-ext.CqjqNYQ-.woff2
Normal file
BIN
assets/inter-roman-greek.BBVDIX6e.woff2
Normal file
BIN
assets/inter-roman-latin-ext.4ZJIpNVo.woff2
Normal file
BIN
assets/inter-roman-latin.Di8DUHzh.woff2
Normal file
BIN
assets/inter-roman-vietnamese.BjW4sHH5.woff2
Normal file
226
assets/notes_01_c-basic_01_xdx_index.md.D1hb9NAd.js
Normal file
@ -0,0 +1,226 @@
|
||||
import{_ as s,c as a,o as i,a5 as n}from"./chunks/framework.D1oHBMsh.js";const l="/coa6/assets/1.D4a42fT1.jpg",e="/coa6/assets/2.D2wnxl5F.png",t="/coa6/assets/3.Dq625oo9.jpg",p="/coa6/assets/4.uqu1DEK4.png",r="/coa6/assets/5.C6Q0Q8kf.jpg",c="/coa6/assets/6.B4Srsb-0.png",o="/coa6/assets/7._D_c8Lrn.png",h="/coa6/assets/8.DlIyFGDg.png",d="/coa6/assets/9.7zkUmpQw.png",k="/coa6/assets/10.h1ugtjyX.png",u="/coa6/assets/11.D5PWTabw.png",g="/coa6/assets/12.Bvs6QYjl.jpg",b="/coa6/assets/9.7zkUmpQw.png",m="/coa6/assets/14.CsR5exrN.png",E="/coa6/assets/15.BRG9GQdT.png",y="/coa6/assets/16.C2sciGZn.png",C="/coa6/assets/17.DdyXXyxJ.png",F="/coa6/assets/18.DIeb_KXW.png",_="/coa6/assets/19.C-kvMz2p.png",v="/coa6/assets/20.CQqFxmDa.png",A="/coa6/assets/21.CjMWyIiX.png",f="/coa6/assets/22.DFQhcDgs.png",x="/coa6/assets/23.Cco1vsW8.png",B="/coa6/assets/24.D60Zf6_d.png",D="/coa6/assets/25.D2-G6nV2.png",q="/coa6/assets/26.DpzkVk5V.png",w="/coa6/assets/27.BXk95GIP.png",S="/coa6/assets/28.CbWTB08W.png",P="/coa6/assets/29.twO9TCIg.png",L="/coa6/assets/30.CKOjeIvS.png",W="/coa6/assets/31.DKmR0CxE.png",T="/coa6/assets/32.Cudf77_s.gif",I="/coa6/assets/33.BBUUlhRC.png",O="/coa6/assets/34.iLABkB7O.png",M="/coa6/assets/35.BQuYWOU9.png",N="/coa6/assets/36.CslpH6j0.png",U="/coa6/assets/37.BAyvZdKq.png",R="/coa6/assets/38.C3oC1iUd.png",G="/coa6/assets/39.Ds-jsEZn.png",H="/coa6/assets/40.Cd37gMYs.png",V="/coa6/assets/41.CAw2z3gc.png",X="/coa6/assets/42.DdPThnr-.png",K="/coa6/assets/43.q_rvlDnY.png",Q="/coa6/assets/44.JRHg9RZA.png",j="/coa6/assets/45.Baq-Hb06.png",J="/coa6/assets/46.c1ht53mu.png",$="/coa6/assets/47.CAZmH5Py.png",Y="/coa6/assets/48.DWeCYBe9.png",z="/coa6/assets/49.2XM8pYni.png",Z="/coa6/assets/50.CN0t-fuo.png",ss="/coa6/assets/51.AcDh3LXQ.png",as="/coa6/assets/52.CUkDFAc6.png",is="/coa6/assets/53.picNTNaJ.png",ns="/coa6/assets/54.DKX92RgJ.png",ls="/coa6/assets/55.Bxr7QKI3.png",es="/coa6/assets/56.DuFWsOgW.png",ts="/coa6/assets/57.Da9qUcfr.png",ps="/coa6/assets/58.7_gEABSX.gif",rs="/coa6/assets/59.C2KQYoVC.gif",cs="/coa6/assets/60.RTUP8Vtx.png",os="/coa6/assets/61.Dq21DxwL.png",hs="/coa6/assets/62.QmpUaNxU.png",ds="/coa6/assets/63.DP0C29gZ.png",ks="/coa6/assets/64.DwzHokd4.png",us="/coa6/assets/65.Bi6K26yA.png",gs="/coa6/assets/66.Bw8DcEQ_.png",bs="/coa6/assets/67.DPc8Z9rS.png",ms="/coa6/assets/68.S84xHMTl.png",Es="/coa6/assets/69.iw3JQUkn.png",ys="/coa6/assets/70.ILeJt-HK.png",Cs="/coa6/assets/71.CHgm7khh.png",Fs="/coa6/assets/72.N1nqJaEg.png",_s="/coa6/assets/73.DHsnibMi.png",vs="/coa6/assets/74.BQr6Q0uV.png",As="/coa6/assets/75.BVemi2Lh.png",fs="/coa6/assets/76.BHR69UXx.png",xs="/coa6/assets/77.CPSU5SJI.png",Bs="/coa6/assets/78.CaQLoDlw.png",Ds="/coa6/assets/79.aRGy4XbL.png",qs="/coa6/assets/80.kNO9fmPR.png",ws="/coa6/assets/81.D4EkoC4o.png",Ss="/coa6/assets/82.V23Lo9e_.png",Ps="/coa6/assets/83.Du9LVeMB.png",Ls="/coa6/assets/84.DdFg75U9.png",Ws="/coa6/assets/85.C6bz6KtT.png",Ts="/coa6/assets/86.CB6LAhB5.png",Is="/coa6/assets/87.Bip8bkua.png",Os="/coa6/assets/88.DRNHRduW.png",Ms="/coa6/assets/89.Cth4qqEn.png",Ns="/coa6/assets/90.DWGWZ64P.png",Us="/coa6/assets/91.3hDIDdvx.png",Rs="/coa6/assets/92.Bw_dQ4ap.png",Gs="/coa6/assets/93.Cn_ubTyA.png",Hs="/coa6/assets/94.C84EBqwB.png",Vs="/coa6/assets/95.dZfJY4eR.png",Xs="/coa6/assets/96.B0zm0Z79.png",Ks="/coa6/assets/97.CaTcEy1Q.png",Qs="/coa6/assets/98.iEc8mo9g.png",js="/coa6/assets/99.Co2KxM6t.png",Js="/coa6/assets/100.CaUm8Qhc.png",$s="/coa6/assets/101.kOkqIKG6.png",Ys="/coa6/assets/102.CyeASH-c.png",zs="/coa6/assets/103.CFdk60La.png",Zs="/coa6/assets/104.Bhl-0uK_.png",sa="/coa6/assets/105.Dni9KbXV.png",aa="/coa6/assets/106.BXx10MCV.png",ia="/coa6/assets/107.CXcIKX1T.png",na="/coa6/assets/108.CQ3_QCQT.png",la="/coa6/assets/109.CQoDRJM5.gif",ea="/coa6/assets/110.CPfwZvD9.gif",ta="/coa6/assets/111.bxEomEjU.gif",pa="/coa6/assets/112.C_onhf2k.png",ra="/coa6/assets/113.Budj3s38.gif",ca="/coa6/assets/114.CH8koQdu.gif",oa="/coa6/assets/115.kUJhxMtg.png",ha="/coa6/assets/116.BJeJJW4_.png",da="/coa6/assets/117.BCuK6eJL.gif",ka="/coa6/assets/118.rKC-z4z-.gif",ua="/coa6/assets/119.BJE3xxuT.gif",ga="/coa6/assets/120.DJOq__O0.gif",ba="/coa6/assets/121.BDt_0fRR.png",ma="/coa6/assets/122.Bo5OawW8.png",Ea="/coa6/assets/123.sUWUfl5e.png",ya="/coa6/assets/124.BK4jpnB8.png",Ca="/coa6/assets/125.EF8vdbSq.png",Fa="/coa6/assets/126.DjxdA_Co.png",_a="/coa6/assets/127.sp68q1hh.gif",va="/coa6/assets/128.DhMRyxNN.gif",Aa="/coa6/assets/129.CdcLZM0R.gif",fa="/coa6/assets/130.D-5AsTTr.png",xa="/coa6/assets/131.2RQKmAUa.png",Ba="/coa6/assets/132.CI4xX8SM.png",Da="/coa6/assets/133.C8QUZ9v3.gif",qa="/coa6/assets/134.g5tQfhWz.gif",wa="/coa6/assets/135.CX0_1NsE.gif",Sa="/coa6/assets/136.BrFJeoK6.png",Pa="/coa6/assets/137.58TjSSjH.gif",La="/coa6/assets/138.CgqNV2hL.png",Wa="/coa6/assets/139.BasYWvkM.png",Ta="/coa6/assets/140.CjFxJpBr.png",Ia="/coa6/assets/141.Dm5Jspvp.gif",Oa="/coa6/assets/142.1krCh8cy.gif",Ma="/coa6/assets/143.DOSyahv7.gif",Na="/coa6/assets/144.BHEvX_FI.gif",Ua="/coa6/assets/145.DFA0g1_d.gif",Ra="/coa6/assets/146.D50nO5eA.gif",Ga="/coa6/assets/147.cAvG1Qfq.png",Ha="/coa6/assets/148.DpakQFWz.gif",Va="/coa6/assets/149.Bg61j9QI.gif",Xa="/coa6/assets/150.DPvD9UCw.gif",Ka="/coa6/assets/151.Ceu65U_n.gif",Qa="/coa6/assets/152.BWPFRK_8.gif",ja="/coa6/assets/153.Ct4TfxPf.gif",Ja="/coa6/assets/154.zsKtx_jV.png",$a="/coa6/assets/155.3oqDAW0w.png",Ya="/coa6/assets/156.D9TSeAa9.gif",za="/coa6/assets/157.CCRgYIVq.png",Za="/coa6/assets/158.C1t2T6FV.gif",si="/coa6/assets/159.Rqa4uHq6.png",ai="/coa6/assets/160.6yQYnjOa.gif",ii="/coa6/assets/161.hYR9GiiD.gif",ni="/coa6/assets/162.D3b-QIrA.gif",li="/coa6/assets/163.DGbA6qsW.gif",ei="/coa6/assets/164.BToOkxf2.gif",mi=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":1720685105000}'),ti={name:"notes/01_c-basic/01_xdx/index.md"},pi=n('<h1 id="第一章-计算机组成原理" tabindex="-1">第一章:计算机组成原理 <a class="header-anchor" href="#第一章-计算机组成原理" aria-label="Permalink to "第一章:计算机组成原理""></a></h1><h2 id="_1-1-计算机系统" tabindex="-1">1.1 计算机系统 <a class="header-anchor" href="#_1-1-计算机系统" aria-label="Permalink to "1.1 计算机系统""></a></h2><ul><li>计算机(Computer),俗称<code>"电脑"</code>,是一种能够接收和存储信息,并按照存储在其内部的程序对海量的数据进行自动、高速的处理,然后将处理结果输出的现代化智能电子设备。</li><li>计算机有很多形式,如:台式电脑、笔记本电脑、智能手机、平板电脑等,还有生产环境中提供重要业务支撑的各种服务器。</li></ul><p><img src="'+l+'" alt=""></p><ul><li>一个完整的<code>计算机系统</code>由<code>硬件(Hardware)系统</code>和<code>软件(Software)系统</code>两大部分组成,即:</li></ul><p><img src="'+e+'" alt=""></p><h2 id="_1-2-冯·诺依曼体系结构" tabindex="-1">1.2 冯·诺依曼体系结构 <a class="header-anchor" href="#_1-2-冯·诺依曼体系结构" aria-label="Permalink to "1.2 冯·诺依曼体系结构""></a></h2><ul><li><code>冯·诺依曼</code>是一位多才多艺的科学家,他在数学、物理学、计算机科学、经济学等领域都有杰出的贡献。</li></ul><p><img src="'+t+'" alt=""></p><ul><li><code>冯·诺依曼</code>的主要成就: <ul><li>在计算机科学领域的最著名贡献是提出了<code>冯·诺依曼</code>体系结构(1946 年),这是<code>现代计算机设计的基础</code>。</li><li>促进了计算机的可编程性和通用性,使得计算机能够执行各种复杂的任务。</li><li>对核武器设计、自动化控制系统、人工智能等领域的发展产生了重要影响。</li><li>……</li></ul></li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p><code>冯·诺依曼体系结构</code>是现代计算机(量子计算机除外)设计的<code>基础</code>。</p></div><ul><li><p><code>冯·诺依曼</code>体系结构的理论要点如下:</p><ul><li><p>① <strong>存储程序</strong>:<code>程序指令</code>和<code>数据</code>都存储在计算机的内存中,这使得程序可以在运行时修改。</p></li><li><p>② <strong>二进制逻辑</strong>:所有<code>数据</code>和<code>指令</code>都以<code>二进制</code>形式表示。</p></li><li><p>③ <strong>顺序执行</strong>:指令按照它们在内存中的顺序执行,但可以有条件地改变执行顺序。</p></li><li><p>④ <strong>五大部件</strong>:计算机由<code>运算器</code>、<code>控制器</code>、<code>存储器</code>、<code>输入设备</code>和<code>输出设备</code>组成。</p></li><li><p>⑤ <strong>指令结构</strong>:指令由操作码和地址码组成,操作码指示要执行的操作,地址码指示操作数的位置。</p></li><li><p>⑥ <strong>中心化控制</strong>:计算机的控制单元(CPU)负责解释和执行指令,控制数据流。</p></li></ul></li></ul><p><img src="'+p+'" alt=""></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>上述的组件协同工作,构成了一个完整的计算机系统:</p><ul><li><strong>运算器</strong>和<strong>控制器</strong>通常被集成在一起,组成中央处理器(CPU),负责数据处理和指令执行。</li><li><strong>存储器</strong>保存数据和程序,是计算机运作的基础。</li><li><strong>输入设备</strong>和<strong>输出设备</strong>负责与外界的交互,确保用户能够输入信息并接收计算机的处理结果。</li></ul></div><h2 id="_1-3-各种硬件处理速度和性能优化" tabindex="-1">1.3 各种硬件处理速度和性能优化 <a class="header-anchor" href="#_1-3-各种硬件处理速度和性能优化" aria-label="Permalink to "1.3 各种硬件处理速度和性能优化""></a></h2><ul><li>计算机的性能短板:如果 CPU 有每秒处理 1000 个服务请求的能力,各种总线的负载能力能达到 500 个, 但网卡只能接受 200个请求,而硬盘只能负担 150 个的话,那这台服务器得处理能力只能是 150 个请求/ 秒,有 85% 的处理器计算能力浪费了,在计算机系统当中,<code>硬盘</code>的读写速率已经成为影响系统性能进一 步提高的瓶颈。</li></ul><p><img src="'+r+'" alt="img"></p><ul><li>计算机的各个设备部件的延迟从高到低的排列,依次是机械硬盘(HDD)、固态硬盘(SSD)、内存、CPU 。</li></ul><p><img src="'+c+`" alt="img"></p><ul><li>从上图中,我们可以知道,CPU 是最快的,一个时钟周期是 0.3 ns ,内存访问需要 120 ns ,固态硬盘访问需要 50-150 us,传统的硬盘访问需要 1-10 ms,而网络访问是最慢,需要 40 ms 以上。</li><li>时间的单位换算如下:</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>1 秒 = 1000 毫秒,即 1 s = 1000 ms。</span></span>
|
||||
<span class="line"><span>1 毫秒 = 1000 微妙,即 1 ms = 1000 us 。</span></span>
|
||||
<span class="line"><span>1 微妙 = 1000 纳秒,即 1 us = 1000 ns。</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-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>如果 CPU 的时钟周期按照 1 秒计算,</span></span>
|
||||
<span class="line"><span>那么,内存访问就需要 6 分钟;</span></span>
|
||||
<span class="line"><span>那么,固态硬盘就需要 2-6 天;</span></span>
|
||||
<span class="line"><span>那么,传统硬盘就需要 1-12 个月;</span></span>
|
||||
<span class="line"><span>那么,网络访问就需要 4 年以上。</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>所以,对于 CPU 来说,这个世界真的是太慢了!!!</li><li>其实,中国古代中的文人,通常以<code>蜉蝣</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>鹤寿千岁,以极其游,蜉蝣朝生而暮死,尽其乐,盖其旦暮为期,远不过三日尔。</span></span>
|
||||
<span class="line"><span> --- 出自 西汉淮南王刘安《淮南子》</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><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>寄蜉蝣于天地,渺沧海之一粟。 哀吾生之须臾,羡长江之无穷。 </span></span>
|
||||
<span class="line"><span>挟飞仙以遨游,抱明月而长终。 知不可乎骤得,托遗响于悲风。</span></span>
|
||||
<span class="line"><span> --- 出自 苏轼《赤壁赋》</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><p>对于<code>蜉蝣</code>来说,从早到晚就是一生;而对于我们<code>人类</code>而言,却仅仅只是一天。</p></div><ul><li>存储器的层次结构(CPU 中也有存储器,即:寄存器、高速缓存 L1、L2 和 L3),如下所示:</li></ul><p><img src="`+o+'" alt="img"></p><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><h2 id="_1-4-计算机软件" tabindex="-1">1.4 计算机软件 <a class="header-anchor" href="#_1-4-计算机软件" aria-label="Permalink to "1.4 计算机软件""></a></h2><h3 id="_1-4-1-操作系统的来源" tabindex="-1">1.4.1 操作系统的来源 <a class="header-anchor" href="#_1-4-1-操作系统的来源" aria-label="Permalink to "1.4.1 操作系统的来源""></a></h3><ul><li>在上古时期,硬件资源不够丰富,计算机设计的也非常简陋。那个时候,很多应用程序都是直接跑在硬件上的,即:一个计算机只能跑一个应用程序。</li></ul><p><img src="'+h+'" alt=""></p><ul><li>随着技术的发展,硬件越来越丰富,功能也越来越强大,性能也越来越好。这种情况下,如果一台计算机只能跑一个程序,实在是太浪费了。而且,底层硬件不断丰富,应用程序需要对接的硬件也将越来越多,如果每个应用程序都这么干,不显示工作很重复吗?于是,操作系统应运而生了。</li></ul><p><img src="'+d+'" alt=""></p><ul><li>操作系统的功能: <ul><li>硬件驱动。</li><li>进程管理。</li><li>内存管理。</li><li>网络管理。</li><li>安全管理。</li><li>文件管理。</li></ul></li></ul><ul><li>那么,操作系统的作用,就是这样的,即: <ul><li>对下,管理计算机的硬件资源。</li><li>对上,提供使用计算机资源的操作方式,有: <ul><li><code>系统调用</code>:是一套已经写好的代码接口,应用程序通过调用这些接口来请求操作系统执行特定的硬件操作。它们直接与硬件交互,提供底层功能支持,如:文件操作、进程管理、内存管理等。<code>开发者</code>通过系统调用可以实现对底层资源的直接控制,确保程序能够高效、安全地运行。</li><li><code>终端命令</code>:是一种文本命令接口,通过命令行输入各种指令来控制操作系统和软件的行为。终端命令可以执行文件操作、系统配置、网络管理等各种任务。主要针对<code>开发人员</code>和<code>高级用户</code>,他们通过命令行可以快速、精确地完成各种操作,提高工作效率。</li><li><code>图形用户界面</code>(GUI)是通过图形元素(如:窗口、图标、按钮等)与用户进行交互的界面。供直观、易用的操作方式,使用户能够通过鼠标点击、拖拽等简单操作完成复杂任务。主要面向<code>普通用户</code>,降低了计算机操作的门槛,提高了用户体验和工作效率。</li></ul></li></ul></li></ul><p><img src="'+k+'" alt=""></p><h3 id="_1-4-2-用户态和内核态" tabindex="-1">1.4.2 用户态和内核态 <a class="header-anchor" href="#_1-4-2-用户态和内核态" aria-label="Permalink to "1.4.2 用户态和内核态""></a></h3><ul><li>在现代操作系统中,<code>用户态(User Mode)</code>和<code>内核态(Kernel Mode)</code>是两种不同的执行模式,它们对系统资源的访问权限有着本质的区别。这种区分是为了提供一个稳定和安全的运行环境,防止用户程序直接操作硬件设备和关键的系统资源,从而可能引起系统的不稳定或安全问题。</li></ul><p><img src="'+u+`" alt=""></p><ul><li>核态(Kernel Mode) VS 用户态(User Mode):</li></ul><table tabindex="0"><thead><tr><th style="text-align:left;">类型</th><th style="text-align:left;">内核态(Kernel Mode)</th><th style="text-align:left;">用户态(User Mode)</th></tr></thead><tbody><tr><td style="text-align:left;">权限</td><td style="text-align:left;">内核态是操作系统代码运行的模式,拥有访问系统全部资源和执行硬件操作的<code>最高权限</code>。在这种模式下,操作系统的核心部分可以直接访问内存、硬件设备控制、管理文件系统和网络通信等。</td><td style="text-align:left;">用户态是普通应用程序运行的模式,具有<code>较低</code>的系统资源访问权限。在用户态,程序不能直接执行硬件操作,必须通过操作系统提供的接口(即系统调用)来请求服务。</td></tr><tr><td style="text-align:left;">安全性</td><td style="text-align:left;">由于内核态具有如此高的权限,因此只有可信的、经过严格审查的操作系统核心组件才被允许在此模式下运行。这样可以保护系统不被恶意软件破坏。</td><td style="text-align:left;">用户态为系统提供了一层保护,确保用户程序不能直接访问关键的系统资源,防止系统崩溃和数据泄露。</td></tr><tr><td style="text-align:left;">功能</td><td style="text-align:left;">内核态提供了<code>系统调用</code>的接口,允许用户态程序安全地请求使用操作系统提供的服务,比如:文件操作、网络通信、内存管理等。</td><td style="text-align:left;">用户态保证了操作系统的稳定性和安全性,同时也使得多个程序可以在相互隔离的环境中同时运行,避免相互干扰。</td></tr></tbody></table><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 操作系统通过用户态和内核态的分离,实现了对系统资源的保护和控制。</li><li>② 当用户程序需要进行文件读写、网络通信或其他需要操作系统介入的操作时,会发生从用户态到内核态的切换。这通过系统调用(System Call)实现,系统调用是用户程序与操作系统内核通信的桥梁。</li><li>③ 执行完毕后,系统从内核态返回用户态,继续执行用户程序。</li><li>④ 用户态和内核态的这种分离设计是现代操作系统中实现安全、稳定运行的关键机制之一。</li></ul></div><ul><li>示例:</li></ul><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;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> java.io.IOException;</span></span>
|
||||
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> java.nio.file.Files;</span></span>
|
||||
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> java.nio.file.Path;</span></span>
|
||||
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> java.nio.file.Paths;</span></span>
|
||||
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> java.util.List;</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;"> Demo</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;"> writeFile</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(String </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">filePath</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, String </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">content</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
|
||||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Path path </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Paths.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">get</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(filePath);</span></span>
|
||||
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> try</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
|
||||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Files.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">write</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(path, content.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">getBytes</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;">catch</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (IOException </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">e</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
|
||||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> e.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">printStackTrace</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;"> 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:#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 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;"> b </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 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;"> c </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> a </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> b; </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 用户态</span></span>
|
||||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> string filePath </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "c:/demo.txt"</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;"> string txt </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> a </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> b </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> c; </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;"> writeFile</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(filePath, a); </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;"> System.out.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">println</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(a); </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 从内核态切换回用户态</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;">(b); </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 用户态</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;">(c); </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></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><h3 id="_1-4-3-isa、abi-和-api" tabindex="-1">1.4.3 ISA、ABI 和 API <a class="header-anchor" href="#_1-4-3-isa、abi-和-api" aria-label="Permalink to "1.4.3 ISA、ABI 和 API""></a></h3><ul><li>ISA 、ABI 和 API 的参考模型如下:</li></ul><p><img src="`+g+'" alt=""></p><ul><li>在底层,硬件模型以指令集架构 (ISA) 表示,该架构定义了处理器、寄存器、存储器和中断管理的指令集。ISA 是硬件和软件之间的接口,对于操作系统 (OS) 开发人员 (System ISA) 和直接管理底层硬件的应用程序 (User ISA) 的开发人员来说非常重要。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① ISA 是计算机体系结构中定义的一组指令,它规定了处理器能够执行的操作。ISA 包括指令的编码、寄存器的使用、内存访问模式等。不同的处理器可能有不同的 ISA,例如:x86、ARM、MIPS 等。</li><li>② 在设计一个新的操作系统时,开发者需要确保操作系统能够支持特定的 ISA ,以便在特定的硬件上运行。例如:如果操作系统旨在运行在 ARM 架构的处理器上,那么它必须能够理解和执行 ARM ISA 定义的指令集。</li></ul></div><ul><li>应用程序二进制接口 (ABI) 将<code>操作系统层</code>与由操作系统管理的<code>应用程序</code>和<code>库</code>分开。ABI 涵盖了低级数据类型、对齐方式和调用约定等详细信息,并定义了可执行程序的格式。系统调用在此级别定义。此接口允许应用程序和库在实现相同 ABI 的操作系统之间移植。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① ABI 是指在二进制级别上,应用程序与操作系统、库或应用程序的不同部分之间的接口。它定义了数据类型的大小、布局、对齐方式,以及函数调用的约定(如参数如何传递、返回值如何处理等)。ABI 确保了编译后的二进制文件能够在特定的操作系统和硬件平台上正确地运行。</li><li>② 在 windows 上的应用程序的运行格式是:<code>PE</code>(portable executable)格式、<code>.dll</code> (dynamic link library)格式和 <code>.lib</code> 格式;而在 Linux 上的应用程序的运行格式是:<code>ELF</code>(executable and linking format)格式、<code>.so</code> (shared object)格式和 <code>.a</code> 格式。</li><li>③ 在 Linux 中可以通过 <code>file /bin/ls</code> 命令查看指定可执行应用程序的 ABI 格式;从而也可以论证,在 Windows 上可以运行的程序,在 Linux 上运行不了。</li><li>④ 当开发者在 Linux 系统上编写 C 语言程序,并使用特定的编译器(如:GCC)编译时,编译器会遵循 Linux 平台的 ABI 规范来生成二进制文件。这样,生成的可执行文件就可以在任何遵循相同 ABI 规范的 Linux 系统上运行。</li><li>⑤ 如果一个应用程序需要跨平台(操作系统)运行,就需要使用<code>一套代码,多平台编译</code>的方式(针对 C 或 C++ 等),即:相同的源代码,在不同平台(操作系统)上使用特定平台的编译器(如:GCC)来分别编译成符合自己平台的 ABI 规范的二进制文件。</li></ul></div><ul><li>最高级别的抽象由应用程序编程接口 (API) 表示,它将<code>应用程序</code>连接到<code>库</code>或<code>底层操作系统</code>。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① API 是一组预定义的函数、协议和工具,用于构建软件和应用程序。API 允许不同的软件系统相互交互,它定义了软件组件之间如何相互通信。API 可以是库、框架、协议或服务。</li><li>② 在 Web 开发中,开发者可能会使用 JavaScript 的 Fetch API 来与服务器进行通信,获取数据或提交表单。这个 API 提供了一种标准化的方式来发送 HTTP 请求和处理响应,而不需要开发者关心底层的网络协议细节。</li></ul></div><h3 id="_1-4-4-系统调用-system-call-和函数库-library-call" tabindex="-1">1.4.4 系统调用(System Call)和函数库(Library Call) <a class="header-anchor" href="#_1-4-4-系统调用-system-call-和函数库-library-call" aria-label="Permalink to "1.4.4 系统调用(System Call)和函数库(Library Call)""></a></h3><ul><li>在现代操作系统中,应用程序都不能直接作用于硬件,而是运行在操作系统之上。</li></ul><p><img src="'+b+'" alt=""></p><ul><li>并且,在上文的图示中,我们也会看到<code>系统调用(System Call)</code>和<code>函数库(Library Call)</code>的身影,如下:</li></ul><p><img src="'+m+'" alt=""></p><p><img src="'+E+`" alt=""></p><ul><li>其实,<code>系统调用(System Call)</code>和<code>函数库(Library Call)</code>的区别如下:</li></ul><table tabindex="0"><thead><tr><th style="text-align:left;">类型</th><th style="text-align:left;">系统调用(System Call)</th><th style="text-align:left;">函数库(Library Call)</th></tr></thead><tbody><tr><td style="text-align:left;">定义</td><td style="text-align:left;">系统调用是操作系统提供给程序员的一组接口,这些接口允许用户空间的程序请求操作系统内核提供的服务,比如文件操作、进程控制、通信和内存管理等。</td><td style="text-align:left;">函数库调用是指使用高级语言编写的一组预先编译好的函数,这些函数实现了一些常用的功能,比如:字符串处理、数学计算等。程序员可以在自己的程序中直接调用这些函数,而无需重新实现它们。</td></tr><tr><td style="text-align:left;">权限</td><td style="text-align:left;">执行系统调用时,会从用户态切换到内核态。这是因为系统调用涉及到访问受保护的系统资源,这些操作必须由操作系统控制以确保系统的稳定性和安全性。</td><td style="text-align:left;">函数库调用通常在用户态执行,不涉及到用户态与内核态之间的切换。它们直接使用操作系统通过系统调用提供的服务,或者完全在用户空间内完成计算,不需要操作系统介入。</td></tr><tr><td style="text-align:left;">性能开销</td><td style="text-align:left;">由于涉及到用户态与内核态之间的切换,系统调用的执行成本相对较高。因此,频繁的系统调用可能会影响程序的性能。</td><td style="text-align:left;">相对于系统调用,函数库调用的性能开销较小。因为它们通常不涉及到模式切换,且执行的操作多在用户空间完成。</td></tr><tr><td style="text-align:left;">示例</td><td style="text-align:left;">open(),read(),write(),fork(),exec() 等 UNIX/Linux 系统调用。</td><td style="text-align:left;">C 标准库中的 printf() 等函数;数学库中的 sin(),cos() 等函数。</td></tr></tbody></table><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① <strong>执行层级</strong>:系统调用直接与操作系统内核交互,执行更底层的操作;而函数库调用运行在用户空间,通常使用系统调用来实现其功能。</li><li>② <strong>性能开销</strong>:系统调用由于涉及到用户态与内核态的切换,性能开销相对较大;函数库调用则因为主要在用户态执行,性能开销较小。</li><li>③ <strong>使用目的</strong>:系统调用提供了访问操作系统资源和服务的能力;函数库调用则提供了方便、高效执行常见任务的手段。</li></ul></div><h1 id="第二章-初识计算机语言" tabindex="-1">第二章:初识计算机语言 <a class="header-anchor" href="#第二章-初识计算机语言" aria-label="Permalink to "第二章:初识计算机语言""></a></h1><h2 id="_2-1-计算机语言是什么" tabindex="-1">2.1 计算机语言是什么? <a class="header-anchor" href="#_2-1-计算机语言是什么" aria-label="Permalink to "2.1 计算机语言是什么?""></a></h2><ul><li><code>人类语言</code>是人和人之间用于沟通的一种方式,例如:中国人和中国人之间使用普通话沟通,而中国人和美国人交流,则可以使用英语。</li><li><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、C++、Java、Go、JavaScript、Python、Scala 等。</p></div><h2 id="_2-2-为什么要学习计算机语言" tabindex="-1">2.2 为什么要学习计算机语言? <a class="header-anchor" href="#_2-2-为什么要学习计算机语言" aria-label="Permalink to "2.2 为什么要学习计算机语言?""></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;"> <stdio.h></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;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</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;">"你好,世界!!!"</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 style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 函数执行完毕时返回函数值0</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></div></div><ul><li>编程语言就是用于控制计算机,让其完成我们需要的功能。而我们学习编程语言,其实就是学习这些文字和符号编写的规则。</li><li>因为 CPU 只能识别二进制的指令,而我们<code>编写</code>的程序叫做<code>源代码</code>,是人类能看懂;但是,计算机却不能识别。那么,我们就需要让计算机能识别我们编写的源程序,就需要将我们编写的源代码交给编译器程序,其会帮助我们将所编写的源代码转换为计算机能够识别的二进制指令。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>编译器就是运行在操作系统之上的程序,其作用就是用来将程序员编写的源代码转换为计算机能够识别的二进制指令。</p></div><ul><li>如果我们用 Java 语言编写了程序(源代码),那么编写的程序也是不能直接运行的,需要通过 Java 语言的编译器将 Java 程序编译为计算机能够识别的二进制指令。</li><li>如果我们用 Python 语言编写了程序(源代码),那么编写的程序也是不能直接运行的,需要通过 Python 语言的编译器将 Python 程序编译为计算机能够识别的二进制指令。</li><li>……</li><li>总而言之,无论我们学习任何一门编程语言,想要将程序运行起来,都必须做如下的两件事情: <ul><li>① 学习该语言的文字和符号编写的规则,即:<code>语法规则</code>。</li><li>② 需要在操作系统上安装对应编程语言的<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 "2.3 计算机语言简史""></a></h2><h3 id="_2-3-1-机器语言-相当于人类的石器时代" tabindex="-1">2.3.1 机器语言(相当于人类的石器时代) <a class="header-anchor" href="#_2-3-1-机器语言-相当于人类的石器时代" aria-label="Permalink to "2.3.1 机器语言(相当于人类的石器时代)""></a></h3><ul><li>1946 年 2 月 14 日,世界上第一台计算机 <code>ENIAC</code> 诞生,使用的是最原始的<code>穿透卡片</code>。</li></ul><p><img src="`+y+`" alt=""></p><ul><li>这种卡片使用的是用<code>二进制代码</code>表示的语言,和人类语言差别极大,这种语言就称为<code>机器语言</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>0000,0000,000000010000 代表 LOAD A, 16</span></span>
|
||||
<span class="line"><span>0000,0001,000000000001 代表 LOAD B, 1</span></span>
|
||||
<span class="line"><span>0001,0001,000000010000 代表 STORE B, 16</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>这种语言本质上是计算机能识别的<code>唯一语言</code>,人类很难理解;换言之,当时的程序员 99.9% 都是异类!!!</li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p>不同类型(CPU 架构,如:x86_64、arm 等)的处理器有不同的机器语言指令集,指令集架构(ISA)决定了机器语言的具体形式;换言之,机器语言与特定硬件架构紧密相关,机器语言程序几乎没有可移植性。</p></div><h3 id="_2-3-2-汇编语言-相当于人类的青铜-铁器时代" tabindex="-1">2.3.2 汇编语言(相当于人类的青铜&铁器时代) <a class="header-anchor" href="#_2-3-2-汇编语言-相当于人类的青铜-铁器时代" aria-label="Permalink to "2.3.2 汇编语言(相当于人类的青铜&铁器时代)""></a></h3><ul><li><code>汇编语言</code>使用<code>助记符</code>(如:MOV、ADD、SUB)代替二进制操作码,使程序更易于人类编写和理解;因此,<code>汇编语言</code>也被称为<code>符号语言</code>。</li></ul><p><img src="`+C+'" alt=""></p><ul><li>汇编语言的<code>优点</code>是能编写<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>汇编语言,目前仍然应用于工业电子编程领域、软件的加密解密、计算机病毒分析等。</p></div><h3 id="_2-3-3-高级语言-相当于人类的信息时代" tabindex="-1">2.3.3 高级语言(相当于人类的信息时代) <a class="header-anchor" href="#_2-3-3-高级语言-相当于人类的信息时代" aria-label="Permalink to "2.3.3 高级语言(相当于人类的信息时代)""></a></h3><ul><li><code>高级语言</code>是一种<code>接近于人们使用习惯</code>的程序设计语言。<code>它允许程序员使用接近日常英语的指令来编写程序</code>,程序中的符号和算式也和<code>日常使用的数学公式</code>差不多,接近于自然语言和数学语言,容易被人们掌握。</li></ul><p><img src="'+F+'" alt=""></p><ul><li>高级语言<code>独立于计算机硬件</code>,有一定的通用性;计算机不能直接识别和执行用高级语言编写的程序,需要使用<code>编译器</code>或<code>解释器</code>转换为机器语言,才能被计算机识别和执行。</li></ul><p><img src="'+_+'" alt=""></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>普遍使用的高级编程语言,有:C、C++、Java、Python、C#、JavaScript、Go、SQL 等。</p></div><h3 id="_2-3-4-总结" tabindex="-1">2.3.4 总结 <a class="header-anchor" href="#_2-3-4-总结" aria-label="Permalink to "2.3.4 总结""></a></h3><ul><li>编写语言的对比,如下所示:</li></ul><table tabindex="0"><thead><tr><th style="text-align:left;">类别</th><th style="text-align:left;">特征</th><th style="text-align:left;">优点</th><th style="text-align:left;">缺点</th><th style="text-align:left;">示例</th></tr></thead><tbody><tr><td style="text-align:left;"><strong>机器语言</strong></td><td style="text-align:left;">直接由计算机执行的二进制代码</td><td style="text-align:left;">执行速度快</td><td style="text-align:left;">编写困难,可读性差,与具体硬件强绑定</td><td style="text-align:left;">二进制代码</td></tr><tr><td style="text-align:left;"><strong>汇编语言</strong></td><td style="text-align:left;">用助记符代替二进制代码的低级语言</td><td style="text-align:left;">相对机器语言更易编写和理解,允许直接控制硬件资源</td><td style="text-align:left;">依然需要了解硬件,不够抽象,与具体硬件或平台相关</td><td style="text-align:left;">MOV,ADD 等助记符</td></tr><tr><td style="text-align:left;"><strong>高级语言</strong></td><td style="text-align:left;">接近人类语言,提供了更高层次的抽象</td><td style="text-align:left;">易于编写和维护,可移植性好,支持多种编程范式</td><td style="text-align:left;">需要通过编译器或解释器转换为机器语言,可能存在一定的性能损失</td><td style="text-align:left;">C,Java, Python 等</td></tr></tbody></table><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 这三种编程语言类型从低级到高级提供了不同层次的抽象,以满足不同的编程需求和场景。</li><li>② 随着计算机科学的发展,高级语言因其强大的表达能力、良好的可移植性和易用性,成为了日常软件开发的主流选择。</li></ul></div><h1 id="第三章-初识-c-语言" tabindex="-1">第三章:初识 C 语言 <a class="header-anchor" href="#第三章-初识-c-语言" aria-label="Permalink to "第三章:初识 C 语言""></a></h1><h2 id="_3-1-c-语言的由来" tabindex="-1">3.1 C 语言的由来 <a class="header-anchor" href="#_3-1-c-语言的由来" aria-label="Permalink to "3.1 C 语言的由来""></a></h2><ul><li>1969 年,美国贝尔实验室的<code>肯·汤姆森</code>(Ken Thompson)和<code>丹尼斯·里奇</code>(Dennis Ritchie)一起开发了 Unix 操作系统。Unix 最初是使用<code>汇编语言</code>编写的,依赖于计算机硬件。为了程序的<code>可读性</code>和<code>可移植性</code>,它们决定使用高级语言重写。但是。当时的高级语言无法满足他们的要求,<code>肯·汤姆森</code>就在 BCPL 语言的基础上发明了 <code>B</code> 语言。</li><li>1972 年,<code>丹尼斯·里奇</code>(Dennis Ritchie)在 <code>B</code> 语言的基础上重新设计了一种新的语言,这种新语言取代了 <code>B</code> 语言,即 <code>C</code> 语言。</li></ul><p><img src="'+v+'" alt=""></p><ul><li>1973 年,<code>整个 Unix 系统都使用 C 语言重写</code>。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>C 语言最初是作为 Unix 系统的开发工具而发明的。</p></div><ul><li>此后,这种语言快速流传,广泛用于各种操作系统和系统软件的开发,如:Unix、MS-DOS、Microsoft Windows 以及 Linux 等。</li></ul><p><img src="'+A+'" alt=""></p><ul><li>1988 年,美国国家标准协会(ANSI)正式将 <code>C 语言标准化</code>,标志着 C 语言开始稳定和规范化。</li></ul><h2 id="_3-2-为什么要学习-c-语言" tabindex="-1">3.2 为什么要学习 C 语言? <a class="header-anchor" href="#_3-2-为什么要学习-c-语言" aria-label="Permalink to "3.2 为什么要学习 C 语言?""></a></h2><ul><li>① <code>C 语言具有可移植好、跨平台的特点</code>:用 C 语言编写的代码可以在不同的操作系统和硬件平台上编译和运行。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>C 语言的最原始的设计目的,就是为了将 Unix 操作系统移植到其他的计算机架构上,这使得它从一开始就非常注重可移植性。</p></div><ul><li>② <code>C 语言在许多领域应用广泛</code>。 <ul><li><code>操作系统</code>:C 广泛用于开发操作系统,如:Unix、Linux 和 Windows。</li><li><code>嵌入式系统</code>:C 是一种用于开发嵌入式系统(如:微控制器、微处理器和其它电子设备)的流程语言。</li><li><code>系统软件</code>:C 用于开发设备驱动程序、编译器和汇编器等系统软件。</li><li><code>网络</code>:C 语言广泛用于开发网络应用程序,例如:Web 服务器、网络协议和网络驱动程序。</li><li><code>数据库系统</code>:C 用于开发数据库系统,例如:Oracle、MySQL 和 PostgreSQL 。</li><li><code>游戏</code>:由于 C 能够处理低级硬件交互,因此经常用于开发计算机游戏。</li><li><code>人工智能</code>:C 用于开发人工智能和机器学习的应用程序,例如:神经网络和深度学习算法。</li><li><code>科学应用</code>:C 用于开发科学应用程序,例如:仿真软件和数值分析工具。</li><li><code>金融应用</code>:C 用于开发股票市场分析和交易系统等金融应用。</li></ul></li><li>③ C 语言能够直接对硬件进行操作、管理内存以及和操作系统对话,这使得它是一种非常接近底层的语言,非常适合<code>写需要和硬件交互、有极高性能要求</code>的程序。</li><li>④ <code>学习 C 语言有助于快速上手其他编程语言</code>,如:C++(原先是 C 语言的一个扩展,在 C 语言的基础上嫁接了面向对象编程思想)、C#、Java 等,这些语言都继承或深受 C 语言的影响和启发。</li><li>⑤ C 语言长盛不衰。<code>C 语言至今,依然是最广泛使用、最流行的编程语言之一</code>,包括很多大学将 C 语言作为计算机教学的入门语言,拥有庞大而活跃的用户社区,这意味着有许多资源和库可供开发人员使用。</li></ul><h2 id="_3-3-计算机语言排行榜" tabindex="-1">3.3 计算机语言排行榜 <a class="header-anchor" href="#_3-3-计算机语言排行榜" aria-label="Permalink to "3.3 计算机语言排行榜""></a></h2><ul><li><a href="https://www.tiobe.com/tiobe-index/" target="_blank" rel="noreferrer">TIOBE</a> 是一个流行编程语言排行,每月更新。排名权重基于世界范围内工程师数量,Google、Bing、Yahoo! 、Wikipedia、Amazon、Youtube 和百度这些主流的搜索引擎,也将作为排名权重的参考指标。</li></ul><p><img src="'+f+'" alt=""></p><ul><li>计算机语言走势图:</li></ul><p><img src="'+x+'" alt=""></p><h2 id="_3-4-c-语言的版本选择" tabindex="-1">3.4 C 语言的版本选择 <a class="header-anchor" href="#_3-4-c-语言的版本选择" aria-label="Permalink to "3.4 C 语言的版本选择""></a></h2><ul><li><p>随着微型计算机的日益普及,出现了许多 C 语言版本(标准)。</p><ul><li>版本 1(K&R C):K&R C 指的是 C 语言的原始版本。1978年,C 语言的发明者布莱恩·柯林(Brian <code>K</code>ernighan)和丹尼斯·里奇(Dennis <code>R</code>itchie)合写了一本著名的教材《C 编程语言》(The C programming language)。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>由于 C 语言还没有成文的语法标准,这本书就成了公认标准,以两位作者的姓氏首字母作为版本简称 “K&R C”。</p></div><ul><li><p>版本 2(ANSI C,又称 C89 或 C90):C 语言的原始版本非常简单,对很多情况的描述非常模糊,加上 C 语法依然在快速发展,要求将 C 语言标准化的呼声越来越高。1989 年,美国国家标准协会(ANSI)制定了一套 C 语言标准,并于次年被国际标准化组织(ISO)通过。它被称为 “ANSI C”,也可以按照发布年份,称为 “C89 或 C90”。</p></li><li><p>版本 3(C99):C 语言标准的第一次<code>大型修订</code>,发生在 1999 年,增加了许多语言特性,比如:双斜杠( // )的注释语法,可变长度数组、灵活的数组成员、复数、内联函数和指定的初始值设定项,这个版本称为 C99,<code>是目前最流行的 C 版本</code>。</p></li><li><p>版本 4(C11):2011 年,标准化组织再一次对 C 语言进行修订,增加了_Generic、static_assert 和原子类型限定符。这个版本称为 C11。</p></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>需要强调的是,修订标准的原因并不是因为原标准不能用,而是需要跟进新的技术。</p></div><ul><li>版本 5(C17):C11 标准在 2017 年进行了修补,但发布是在 2018 年。新版本只是解决了 C11 的一些缺陷,没有引入任何新功能。这个版本称为 C17。</li><li>版本 6(C23):2023 年发布,计划进一步增强安全性,消除实现定义的行为,引入模块化语言概念等新特性,使 C 语言在安全和可靠性方面有重大提高。</li><li>……</li></ul></li><li><p>需要注意的是,C 语言的标准并没有强制性的约束,只是个说明文档而已。不同的编译器产商,对 C 语言的标准有不同的实现,甚至会出现某些 C 语言的标准在这个编译器下实现了;但是,在另外的编辑器下却没有实现,导致编译程序错误的现象。常见的 C/C++ 编译器如下:</p><ul><li>Borland C++ 宝蓝公司。</li><li>Intel C++ 英特尔编译器。</li><li>MSVC 微软公司。</li><li>g++ 编译器(GCC,编译套件), Linux 操作系统。</li></ul></li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p>GCC 编译套件对标准的支持是最好的;所以,在实际项目开发中,我们首先会选用 GCC 编译套件来进行开发。</p></div><h2 id="_3-5-c-语言的优缺点" tabindex="-1">3.5 C 语言的优缺点 <a class="header-anchor" href="#_3-5-c-语言的优缺点" aria-label="Permalink to "3.5 C 语言的优缺点""></a></h2><ul><li><p>C 语言的优点:</p><ul><li>① 高效:C 语言生成的代码非常高效,执行速度快,这使得其非常适合用于操作系统、嵌入式系统等需要高性能的场景。</li><li>② 灵活性和低级控制:C 语言允许直接操作内存和硬件,可以进行位操作、指针运算等底层编程,非常适合开发需要直接硬件控制的应用。</li><li>③ 广泛的硬件和平台支持:C 语言几乎可以在所有的计算机平台上运行,从微处理器到超级计算机,几乎所有的硬件平台都支持 C 语言。</li><li>④ 标准库丰富:C 语言有一个标准库(C Standard Library),提供了大量常用的函数,涵盖了文件操作、字符串处理、内存管理等多种功能。</li><li>⑤ 语言简洁:语法规则相对简单,没有过多的复杂特性,使得语言本身比较容易学习和掌握。</li></ul></li><li><p>C 语言的缺点:</p><ul><li>① 缺乏高级特性:和现代编程语言相对,C 语言缺乏一些高级特性,如:面向对象编程、垃圾回收机制等,这使得某些类型的应用程序开发可能会更加复杂。</li><li>② 安全性问题:C 语言允许直接操作内存,可能会导致缓冲区溢出、空指针引用等安全漏洞。如果不小心处理,容易产生难以调试的错误和安全隐患。</li><li>③ 手动管理内存:C 语言需要程序员手动管理内存,即:分配内存和释放内存,这增加了内存泄露和悬空指针等问题的风险。</li><li>④ 错误调试困难:由于 C 语言的底层操作特点,调试和排查错误可能比较困难,尤其是在处理复杂指针和内存操作的时候。</li><li>⑤ 标准库有限:虽然 C 语言的标准库涵盖了很多基本功能,但相比现代编程语言的标准库,功能相对有限,尤其是在网络编程、多线程编程等方面。</li></ul></li><li><p>总而言之,C 语言的高效性和灵活性使其在系统级编程和嵌入式系统中占据重要地位,但其缺乏高级特性和内存管理上的挑战也使得开发过程可能更加复杂和容易出错。对于需要高性能和底层控制的应用,C 语言依然是不可替代的选择。</p></li></ul><h1 id="第四章-c-语言入门-hello-world-⭐" tabindex="-1">第四章:C 语言入门(Hello World,⭐) <a class="header-anchor" href="#第四章-c-语言入门-hello-world-⭐" aria-label="Permalink to "第四章:C 语言入门(Hello World,⭐)""></a></h1><h2 id="_4-1-环境的安装和配置" tabindex="-1">4.1 环境的安装和配置 <a class="header-anchor" href="#_4-1-环境的安装和配置" aria-label="Permalink to "4.1 环境的安装和配置""></a></h2><h3 id="_4-1-1-概述" tabindex="-1">4.1.1 概述 <a class="header-anchor" href="#_4-1-1-概述" aria-label="Permalink to "4.1.1 概述""></a></h3><ul><li><p>要开发 C/C++ 程序,需要安装 C/C++ 编译器,目前有两种主流实现,即:</p><ul><li>GCC(GNU Compiler Collection):全平台实现,即支持 Windows、MacOS、Linux 等。</li><li>MSVC(Microsoft Visual C++):只支持 Windows 系统。</li></ul></li><li><p>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>。它们之间的区别,如下所示:</p></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></ul></div><h3 id="_4-1-2-mingw-w64-的安装和配置" tabindex="-1">4.1.2 MinGW-w64 的安装和配置 <a class="header-anchor" href="#_4-1-2-mingw-w64-的安装和配置" aria-label="Permalink to "4.1.2 MinGW-w64 的安装和配置""></a></h3><h4 id="_4-1-2-1-安装" tabindex="-1">4.1.2.1 安装 <a class="header-anchor" href="#_4-1-2-1-安装" aria-label="Permalink to "4.1.2.1 安装""></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="'+B+'" alt=""></p><ul><li>解压到指定的目录,即:</li></ul><p><img src="'+D+'" alt=""></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="_4-1-2-2-配置-path-环境变量" tabindex="-1">4.1.2.2 配置 path 环境变量 <a class="header-anchor" href="#_4-1-2-2-配置-path-环境变量" aria-label="Permalink to "4.1.2.2 配置 path 环境变量""></a></h4><ul><li>配置环境变量,以便任意目录都可以执行 gcc 命令,即:</li></ul><p><img src="'+q+'" alt=""></p><p><img src="'+w+'" alt=""></p><p><img src="'+S+'" alt=""></p><p><img src="'+P+'" alt=""></p><p><img src="'+L+'" alt=""></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="'+W+'" alt=""></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="'+T+'" alt=""></p><h3 id="_4-1-3-cygwin-的安装和配置" tabindex="-1">4.1.3 Cygwin 的安装和配置 <a class="header-anchor" href="#_4-1-3-cygwin-的安装和配置" aria-label="Permalink to "4.1.3 Cygwin 的安装和配置""></a></h3><h4 id="_4-1-3-1-安装" tabindex="-1">4.1.3.1 安装 <a class="header-anchor" href="#_4-1-3-1-安装" aria-label="Permalink to "4.1.3.1 安装""></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="'+I+'" alt=""></p><ul><li>点击安装:</li></ul><p><img src="'+O+'" alt=""></p><p><img src="'+M+'" alt=""></p><p><img src="'+N+'" alt=""></p><p><img src="'+U+'" alt=""></p><p><img src="'+R+'" alt=""></p><p><img src="'+G+'" alt=""></p><p><img src="'+H+'" alt=""></p><p><img src="'+V+'" alt=""></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="'+X+'" alt=""></p><p><img src="'+K+'" alt=""></p><p><img src="'+Q+'" alt=""></p><p><img src="'+j+'" alt=""></p><p><img src="'+J+'" alt=""></p><p><img src="'+$+'" alt=""></p><p><img src="'+Y+'" alt=""></p><p><img src="'+z+'" alt=""></p><p><img src="'+Z+'" alt=""></p><h4 id="_4-1-3-2-配置-path-环境变量" tabindex="-1">4.1.3.2 配置 path 环境变量 <a class="header-anchor" href="#_4-1-3-2-配置-path-环境变量" aria-label="Permalink to "4.1.3.2 配置 path 环境变量""></a></h4><ul><li>和 <code>3.1.2.2 配置 path 环境变量</code> 步骤相同:略。</li></ul><h3 id="_4-1-4-msys2-推荐" tabindex="-1">4.1.4 MSYS2(推荐) <a class="header-anchor" href="#_4-1-4-msys2-推荐" aria-label="Permalink to "4.1.4 MSYS2(推荐)""></a></h3><h4 id="_4-1-4-1-安装" tabindex="-1">4.1.4.1 安装 <a class="header-anchor" href="#_4-1-4-1-安装" aria-label="Permalink to "4.1.4.1 安装""></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="'+ss+'" alt=""></p><ul><li>点击安装:</li></ul><p><img src="'+as+'" alt=""></p><p><img src="'+is+'" alt=""></p><p><img src="'+ns+'" alt=""></p><p><img src="'+ls+'" alt=""></p><p><img src="'+es+'" alt=""></p><ul><li>出现命令终端:</li></ul><p><img src="'+ts+'" alt=""></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;">sed</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -i</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "s#https\\?://mirror.msys2.org/#https://mirrors.tuna.tsinghua.edu.cn/msys2/#g"</span><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></div></div><p><img src="'+ps+'" alt=""></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-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><p><img src="'+rs+'" alt=""></p><h4 id="_4-1-4-2-配置-path-环境变量" tabindex="-1">4.1.4.2 配置 path 环境变量 <a class="header-anchor" href="#_4-1-4-2-配置-path-环境变量" aria-label="Permalink to "4.1.4.2 配置 path 环境变量""></a></h4><ul><li>和 <code>3.1.2.2 配置 path 环境变量</code> 步骤相同:略。</li></ul><h2 id="_4-2-ide-的安装和配置" tabindex="-1">4.2 IDE 的安装和配置 <a class="header-anchor" href="#_4-2-ide-的安装和配置" aria-label="Permalink to "4.2 IDE 的安装和配置""></a></h2><h3 id="_4-2-1-clion" tabindex="-1">4.2.1 CLion <a class="header-anchor" href="#_4-2-1-clion" aria-label="Permalink to "4.2.1 CLion""></a></h3><h4 id="_4-2-1-1-概述" tabindex="-1">4.2.1.1 概述 <a class="header-anchor" href="#_4-2-1-1-概述" aria-label="Permalink to "4.2.1.1 概述""></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><h4 id="_4-2-1-2-安装" tabindex="-1">4.2.1.2 安装 <a class="header-anchor" href="#_4-2-1-2-安装" aria-label="Permalink to "4.2.1.2 安装""></a></h4><ul><li>鼠标双击,进入安装:</li></ul><p><img src="'+cs+'" alt=""></p><ul><li>下一步:</li></ul><p><img src="'+os+'" alt=""></p><ul><li>下一步:</li></ul><p><img src="'+hs+'" alt=""></p><ul><li>下一步:</li></ul><p><img src="'+ds+'" alt=""></p><ul><li>安装:</li></ul><p><img src="'+ks+'" alt=""></p><ul><li>安装完成:</li></ul><p><img src="'+us+'" alt=""></p><h4 id="_4-2-1-3-配置" tabindex="-1">4.2.1.3 配置 <a class="header-anchor" href="#_4-2-1-3-配置" aria-label="Permalink to "4.2.1.3 配置""></a></h4><ul><li>打开 CLion :</li></ul><p><img src="'+gs+'" alt=""></p><ul><li>安装中文插件(可选):</li></ul><p><img src="'+bs+'" alt=""></p><p><img src="'+ms+'" alt=""></p><ul><li>配置新 UI :</li></ul><p><img src="'+Es+'" alt=""></p><p><img src="'+ys+'" alt=""></p><ul><li>新 UI 配置自定义字体(可选):</li></ul><p><img src="'+Cs+'" alt=""></p><ul><li>配置<code>自动保存</code>功能:</li></ul><p><img src="'+Fs+'" alt=""></p><ul><li>配置<code>文件编码</code> 为 UTF-8:</li></ul><p><img src="'+_s+'" alt=""></p><ul><li>配置<code>控制台编码</code>为 UTF-8:</li></ul><p><img src="'+vs+'" alt=""></p><ul><li>配置<code>显示方法分隔符</code>功能:</li></ul><p><img src="'+As+'" alt=""></p><ul><li>配置<code>编辑器</code>的字体(可选):</li></ul><p><img src="'+fs+'" alt=""></p><ul><li>检测 GCC 工具链是否安装成功:</li></ul><p><img src="'+xs+'" alt=""></p><h3 id="_4-2-2-vs-code" tabindex="-1">4.2.2 VS Code <a class="header-anchor" href="#_4-2-2-vs-code" aria-label="Permalink to "4.2.2 VS Code""></a></h3><h4 id="_4-2-2-1-概述" tabindex="-1">4.2.2.1 概述 <a class="header-anchor" href="#_4-2-2-1-概述" aria-label="Permalink to "4.2.2.1 概述""></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><p>Visual Studio Code 需要安装对应的插件,才能运行 C/C++ 代码。</p></div><h4 id="_4-2-2-2-安装" tabindex="-1">4.2.2.2 安装 <a class="header-anchor" href="#_4-2-2-2-安装" aria-label="Permalink to "4.2.2.2 安装""></a></h4><ul><li>鼠标双击,进入安装:</li></ul><p><img src="'+Bs+'" alt=""></p><ul><li>同意协议:</li></ul><p><img src="'+Ds+'" alt=""></p><ul><li>下一步:</li></ul><p><img src="'+qs+'" alt=""></p><ul><li>下一步:</li></ul><p><img src="'+ws+'" alt=""></p><ul><li>下一步:</li></ul><p><img src="'+Ss+'" alt=""></p><ul><li>安装:</li></ul><p><img src="'+Ps+'" alt=""></p><ul><li>安装过程:</li></ul><p><img src="'+Ls+'" alt=""></p><ul><li>安装完成:</li></ul><p><img src="'+Ws+'" alt=""></p><h4 id="_4-2-2-3-配置" tabindex="-1">4.2.2.3 配置 <a class="header-anchor" href="#_4-2-2-3-配置" aria-label="Permalink to "4.2.2.3 配置""></a></h4><ul><li>安装<code>中文</code>插件:</li></ul><p><img src="'+Ts+'" alt=""></p><p><img src="'+Is+'" alt=""></p><ul><li>安装 <code>C/C++</code> 插件:</li></ul><p><img src="'+Os+'" alt=""></p><p><img src="'+Ms+'" alt=""></p><h3 id="_4-2-3-microsoft-visual-studio" tabindex="-1">4.2.3 Microsoft Visual Studio <a class="header-anchor" href="#_4-2-3-microsoft-visual-studio" aria-label="Permalink to "4.2.3 Microsoft Visual Studio""></a></h3><h4 id="_4-2-3-1-概述" tabindex="-1">4.2.3.1 概述 <a class="header-anchor" href="#_4-2-3-1-概述" aria-label="Permalink to "4.2.3.1 概述""></a></h4><ul><li><p><a href="https://visualstudio.microsoft.com/" target="_blank" rel="noreferrer">Visual Studio</a>(简称 VS)是由微软公司发布的集成开发环境。它包括了整个软件生命周期中所需要的大部分工具,如:UML工具、代码管控工具、集成开发环境(IDE)等。</p></li><li><p>Visual Studio 支持 C/C++、C#、F#、VB 等多种程序语言的开发和测试,可以用于生成Web应用程序,也可以生成桌面应用程序,功能十分强大,但下载和安装很可能耗时数小时,还可能会塞满磁盘。</p></li><li><p>Visual Studio 2022 有三种版本:社区版(免费,不支持企业使用),专业版(第一年 1199 美元/ 799 美元续订)和企业版(第一年 5999 美元/ 2569 美元续订)。企业版拥有面向架构师的功能、高级调试和测试,这些功能是另两种 SKU 所没有的。</p></li><li><p>Visual Studio 旨在成为世界上最好的 IDE(集成开发环境),目前最新版本为 Visual Studio 2022。</p></li></ul><h4 id="_4-2-3-2-安装" tabindex="-1">4.2.3.2 安装 <a class="header-anchor" href="#_4-2-3-2-安装" aria-label="Permalink to "4.2.3.2 安装""></a></h4><ul><li>鼠标双击,进入安装:</li></ul><p><img src="'+Ns+'" alt=""></p><ul><li>继续:</li></ul><p><img src="'+Us+'" alt=""></p><ul><li>等待:</li></ul><p><img src="'+Rs+'" alt=""></p><ul><li>工作负荷(使用 C++ 的桌面开发):</li></ul><p><img src="'+Gs+'" alt=""></p><ul><li>单个组件:</li></ul><p><img src="'+Hs+'" alt=""></p><ul><li>语言包:</li></ul><p><img src="'+Vs+'" alt=""></p><ul><li>安装位置(修改默认的安装位置):</li></ul><p><img src="'+Xs+'" alt=""></p><ul><li>如果不是第一次安装,可能会出现<code>共享组件、工具和 SDK</code>不可以修改,即:</li></ul><p><img src="'+Ks+'" alt=""></p><ul><li>此时,就需要打开<code>注册表编辑器</code>,将如下图中的除了第一个选项,全部删除,然后关闭再重新安装,即:</li></ul><p><img src="'+Qs+'" alt=""></p><ul><li>开始安装:</li></ul><p><img src="'+js+'" alt=""></p><ul><li>安装中:</li></ul><p><img src="'+Js+'" alt=""></p><ul><li>安装完成,然后关闭:</li></ul><p><img src="'+$s+'" alt=""></p><h4 id="_4-2-3-3-配置" tabindex="-1">4.2.3.3 配置 <a class="header-anchor" href="#_4-2-3-3-配置" aria-label="Permalink to "4.2.3.3 配置""></a></h4><ul><li>在开始菜单处,启动 VS :</li></ul><p><img src="'+Ys+'" alt=""></p><ul><li>登录或跳过该选项(有微软账号就注册,没有就暂时跳过):</li></ul><p><img src="'+zs+'" alt=""></p><ul><li>继续:</li></ul><p><img src="'+Zs+'" alt=""></p><ul><li>注册 VS :</li></ul><p><img src="'+sa+'" alt=""></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="'+aa+'" alt=""></p><p><img src="'+ia+'" alt=""></p><h2 id="_4-3-helloworld" tabindex="-1">4.3 HelloWorld <a class="header-anchor" href="#_4-3-helloworld" aria-label="Permalink to "4.3 HelloWorld""></a></h2><h3 id="_4-3-1-手动版" tabindex="-1">4.3.1 手动版 <a class="header-anchor" href="#_4-3-1-手动版" aria-label="Permalink to "4.3.1 手动版""></a></h3><ul><li>① 新建一个 <code>HelloWorld.c</code> 的文件:</li></ul><p><img src="'+na+`" alt=""></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;"> <stdio.h></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;">"Hello World"</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></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></div></div><p><img src="`+la+'" alt=""></p><ul><li>③ 通过 <code>gcc</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;">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="'+ea+'" alt=""></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;">./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="'+ta+'" alt=""></p><h3 id="_4-3-2-vs-code-版" tabindex="-1">4.3.2 VS Code 版 <a class="header-anchor" href="#_4-3-2-vs-code-版" aria-label="Permalink to "4.3.2 VS Code 版""></a></h3><ul><li>① 新建一个<code>空</code>文件夹(目录),用于存放代码:</li></ul><p><img src="'+pa+'" alt=""></p><ul><li>② 通过 <code>vscode</code> 打开该目录:</li></ul><p><img src="'+ra+'" alt=""></p><ul><li>③ 在 <code>vscode</code> 中新建 <code>HelloWorld.c</code> 文件:</li></ul><p><img src="'+ca+'" alt=""></p><ul><li>④ 设置 VSCode 中 C/C++ 的代码格式为行尾风格(可选):</li></ul><p><img src="'+oa+'" alt=""></p><p><img src="'+ha+`" alt=""></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;"> <stdio.h></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;">"Hello World"</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></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></div></div><p><img src="`+da+'" alt=""></p><ul><li>⑥ 通过 <code>gcc</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;">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="'+ka+'" alt=""></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;">./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="'+ua+'" alt=""></p><ul><li>⑧ 安装 Code Runner 插件(步骤略),实现右键直接编译执行(可选):</li></ul><p><img src="'+ga+'" alt=""></p><h3 id="_4-3-3-vs-版" tabindex="-1">4.3.3 VS 版 <a class="header-anchor" href="#_4-3-3-vs-版" aria-label="Permalink to "4.3.3 VS 版""></a></h3><ul><li>① 新建空项目:</li></ul><p><img src="'+ba+'" alt=""></p><p><img src="'+ma+'" alt=""></p><p><img src="'+Ea+'" alt=""></p><p><img src="'+ya+'" alt=""></p><ul><li>② 打开<code>解决方案资源管理器</code>:</li></ul><p><img src="'+Ca+'" alt=""></p><p><img src="'+Fa+'" alt=""></p><ul><li>③ 新建 <code>HelloWorld.c</code> 文件:</li></ul><p><img src="'+_a+`" alt=""></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;"> <stdio.h></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;">"Hello World"</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></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></div></div><p><img src="`+va+'" alt=""></p><ul><li>⑤ 编译和执行:</li></ul><p><img src="'+Aa+'" alt=""></p><h3 id="_4-3-4-clion" tabindex="-1">4.3.4 CLion <a class="header-anchor" href="#_4-3-4-clion" aria-label="Permalink to "4.3.4 CLion""></a></h3><ul><li>① 新建空项目:</li></ul><p><img src="'+fa+'" alt=""></p><p><img src="'+xa+'" alt=""></p><p><img src="'+Ba+`" alt=""></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;"> <stdio.h></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;">"Hello World"</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></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></div></div><p><img src="`+Da+'" alt=""></p><ul><li>③ 编译和运行:</li></ul><p><img src="'+qa+'" alt=""></p><ul><li>④ 默认情况下,一个项目只能有一个 c 源文件包含 main 函数,但是 CLion 可以有多个,如下:</li></ul><p><img src="'+wa+'" alt=""></p><ul><li>⑤ 如果之后,有中文乱码问题,那么请做如下步骤:</li></ul><p><img src="'+Sa+'" alt=""></p><p><img src="'+Pa+`" alt=""></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>内容如下所示:</p><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>-Dfile.encoding=UTF-8</span></span>
|
||||
<span class="line"><span>-Dconsole.encoding=UTF-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></div></div></div><h1 id="第五章-注释" tabindex="-1">第五章:注释 <a class="header-anchor" href="#第五章-注释" aria-label="Permalink to "第五章:注释""></a></h1><h2 id="_5-1-概述" tabindex="-1">5.1 概述 <a class="header-anchor" href="#_5-1-概述" aria-label="Permalink to "5.1 概述""></a></h2><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>② 在实际开发中,程序员可以将自己的思路通过<code>注释</code>整理出来,然后再用<code>代码</code>去实现。</li></ul></div><h2 id="_5-2-单行注释" tabindex="-1">5.2 单行注释 <a class="header-anchor" href="#_5-2-单行注释" aria-label="Permalink to "5.2 单行注释""></a></h2><ul><li>C 语言中的单行注释的格式,如下所示:</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;">// 单行注释</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>在 CLion 中的快捷键是 <code>Ctrl + /</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;"> <stdio.h></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;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</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;">"你好,世界!!!"</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 style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 函数执行完毕时返回函数值0</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></div></div><h2 id="_5-3-多行注释" tabindex="-1">5.3 多行注释 <a class="header-anchor" href="#_5-3-多行注释" aria-label="Permalink to "5.3 多行注释""></a></h2><ul><li>C 语言中的多行注释的格式,如下所示:</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;">/*</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;"> 这是第二行注释</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;">*/</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>① 多行注释不能嵌套使用!!!</li><li>② 在 CLion 中的快捷键是 <code>Ctrl + Alt + /</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;"> <stdio.h></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:#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:#6A737D;--shiki-dark:#6A737D;"> printf(1);</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> printf(2);</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;">"你好,世界!!!"</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></div></div><h1 id="第六章-helloworld-的规范-⭐" tabindex="-1">第六章:HelloWorld 的规范(⭐) <a class="header-anchor" href="#第六章-helloworld-的规范-⭐" aria-label="Permalink to "第六章:HelloWorld 的规范(⭐)""></a></h1><h2 id="_6-1-规范的代码风格" tabindex="-1">6.1 规范的代码风格 <a class="header-anchor" href="#_6-1-规范的代码风格" aria-label="Permalink to "6.1 规范的代码风格""></a></h2><h3 id="_6-1-1-正确的缩进和空白" tabindex="-1">6.1.1 正确的缩进和空白 <a class="header-anchor" href="#_6-1-1-正确的缩进和空白" aria-label="Permalink to "6.1.1 正确的缩进和空白""></a></h3><ul><li>① 使用一次 <code>tab</code> 操作,实现缩进,默认整体向右边移动;如果使用 <code>shift + tab</code> 则整体向左移动。</li><li>② 运算符两边习惯各加一个空格,如:<code>2 + 4 = 6</code>。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>各种 IDE 都有格式化的快捷键,如:CLion 的格式化快捷键是 <code>Ctrl + Alt + L</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;"> <stdio.h></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;"> a </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;"> b </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:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> c </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> a </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> b;</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;">"c = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</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></div></div><h3 id="_6-1-2-代码风格" tabindex="-1">6.1.2 代码风格 <a class="header-anchor" href="#_6-1-2-代码风格" aria-label="Permalink to "6.1.2 代码风格""></a></h3><ul><li>在 C 语言中,有两种代码风格:<code>行尾风格</code>和<code>次行风格</code>。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>看个人爱好,任选一种即可,本人喜欢<code>行尾分格</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;">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;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(a </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">></span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> b) {</span></span>
|
||||
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> a;</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;"> return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> b;</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></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;"> 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;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(a </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">></span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> b) </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:#24292E;--shiki-dark:#E1E4E8;"> a;</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;"> else</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:#24292E;--shiki-dark:#E1E4E8;"> b;</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></div></div><h2 id="_6-2-代码细节剖析" tabindex="-1">6.2 代码细节剖析 <a class="header-anchor" href="#_6-2-代码细节剖析" aria-label="Permalink to "6.2 代码细节剖析""></a></h2><h3 id="_6-2-1-main-函数" tabindex="-1">6.2.1 main() 函数 <a class="header-anchor" href="#_6-2-1-main-函数" aria-label="Permalink to "6.2.1 main() 函数""></a></h3><ul><li>在 C 语言中,一个程序或工程可以定义很多函数,但是有且只有一个 main() 函数,作为程序执行的入口,并且在 main() 函数结尾结束整个程序的运行,即:</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;"> main</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></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>如果 main() 函数是空括号,即表示 main() 函数不接收任何参数。</li><li>在 main() 函数之前的 <code>int</code> 称为关键字,代表数据类型是<code>整型</code>,它是 main() 函数的返回值的类型,即在执行 main() 函数之后一定会得到一个整数类型的值,即函数值。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 在 C 语言中,人们约定,如果 <code>return 0</code>,就表示 main() 函数终止运行,且运行成功;如果返回其它非零整数,则表示运行失败。</li><li>② 默认情况下,如果 main() 函数中省略 <code>return 0</code> ,则编译器会自动加上;但是,为了保持统一的代码风格,不建议省略。</li></ul></div><h3 id="_6-2-2-函数体" tabindex="-1">6.2.2 函数体 <a class="header-anchor" href="#_6-2-2-函数体" aria-label="Permalink to "6.2.2 函数体""></a></h3><ul><li>① 一对花括号 <code>{}</code> 定义了函数的主体,所有函数都必须以大括号开头和结尾,成对出现。</li><li>② C 程序中的函数体指的是作为该函数一部分的语句。它可以是任何操作,比如:搜索、排序、打印等。</li><li>③ 每一个执行语句后面都会有一个英文分号<code>;</code>作为语句结束的标志。</li><li>④ 一行内可写几条语句,一条语句也可写在几行上。</li></ul><h3 id="_6-2-3-printf-函数" tabindex="-1">6.2.3 printf() 函数 <a class="header-anchor" href="#_6-2-3-printf-函数" aria-label="Permalink to "6.2.3 printf() 函数""></a></h3><ul><li>printf() 函数的格式,如下所示:</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;">printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">__format</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>printf() 函数是产生格式化输出的函数,作用是将参数文本输出到屏幕,f 表示 format(格式化),表示可以指定输出文本的格式,即:</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;">printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"Hello World"</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><ul><li>如果想让光标移动到下一行的开头,可以在输出文本的结尾,可以添加一个换行符 <code>\\n</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:#6F42C1;--shiki-dark:#B392F0;">printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"Hello World</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</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><h3 id="_6-2-4-标准库和头文件" tabindex="-1">6.2.4 标准库和头文件 <a class="header-anchor" href="#_6-2-4-标准库和头文件" aria-label="Permalink to "6.2.4 标准库和头文件""></a></h3><h4 id="_6-2-4-1-概述" tabindex="-1">6.2.4.1 概述 <a class="header-anchor" href="#_6-2-4-1-概述" aria-label="Permalink to "6.2.4.1 概述""></a></h4><ul><li>printf() 函数是在标准库的头文件 <code>stdio.h</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;"> <stdio.h></span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><h4 id="_6-2-4-2-标准库-standard-library" tabindex="-1">6.2.4.2 标准库(Standard Library) <a class="header-anchor" href="#_6-2-4-2-标准库-standard-library" aria-label="Permalink to "6.2.4.2 标准库(Standard Library)""></a></h4><ul><li>C 语言的<code>标准库</code>是由一组函数组成,这些函数提供了许多常用的操作和功能,如:输入输出、字符串处理、内存管理、数学计算等。标准库中的函数由编译器提供,遵循 ANSI C 标准(如:C89/C90、C99、C11等)。</li><li>换言之,C 语言的<code>标准库</code>就是包含函数的实际代码,这些代码在编译的时候被链接到我们的程序中,无需手动包含。C 语言的<code>标准库</code>提供了可重用的函数实现,使得程序员不必编写常用的功能。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>实际的 printf() 函数的实现代码通常位于标准库的实现文件中,如:在 Linux 中的标准库<code>libc.so.6</code> 就包含了 printf() 函数的实现。</p></div><h4 id="_6-2-4-3-头文件-header-files" tabindex="-1">6.2.4.3 头文件(Header Files) <a class="header-anchor" href="#_6-2-4-3-头文件-header-files" aria-label="Permalink to "6.2.4.3 头文件(Header Files)""></a></h4><ul><li><p><code>头文件</code>是包含函数声明、宏定义、数据类型定义等内容的文件。头文件的作用是为源代码提供必要的声明和定义,以便编译器能够正确解析和链接函数调用。头文件通常以<code>.h</code>作为文件扩展名。</p></li><li><p>换言之,头文件包含函数声明、宏定义和数据类型定义,但不包含函数的实现。头文件告知编译器如何使用标准库中的函数和定义,确保编译时的正确性。头文件需要在源代码文件中使用<code>#include</code>指令显式包含,如:<code>#include <stdio.h></code>。</p></li><li><p>常见的 C 语言头文件及其功能和常用函数、宏等,如下所示:</p></li></ul><table tabindex="0"><thead><tr><th>头文件</th><th>功能说明</th><th>常用函数和宏</th></tr></thead><tbody><tr><td><strong>stdio.h</strong></td><td>标准输入输出库</td><td><code>printf</code>, <code>scanf</code>, <code>fprintf</code>,<code>fscanf</code>,<code>fopen</code>, <code>fclose</code>,<code>fgets</code>, <code>fputs</code></td></tr><tr><td><strong>stdlib.h</strong></td><td>标准库,提供内存分配、程序控制、类型转换、随机数生成等功能</td><td><code>malloc</code>, <code>free</code>, <code>exit</code>, <code>atoi</code>, <code>atof</code>,<code>rand</code>,<code>srand</code></td></tr><tr><td><strong>string.h</strong></td><td>字符串处理库</td><td><code>strlen</code>, <code>strcpy</code>, <code>strncpy</code>, <code>strcat</code>, <code>strcmp</code>,<code>strstr</code>, <code>memset</code>, <code>memcpy</code></td></tr><tr><td><strong>math.h</strong></td><td>数学库</td><td><code>sin</code>, <code>cos</code>, <code>tan</code>, <code>exp</code>, <code>log</code>, <code>sqrt</code>, <code>pow</code></td></tr><tr><td><strong>time.h</strong></td><td>时间和日期库</td><td><code>time</code>, <code>clock</code>, <code>difftime</code>, <code>mktime</code>, <code>strftime</code>, <code>localtime</code>,<code>gmtime</code></td></tr><tr><td><strong>ctype.h</strong></td><td>字符处理库</td><td><code>isalnum</code>, <code>isalpha</code>, <code>isdigit</code>, <code>islower</code>, <code>isupper</code>, <code>tolower</code>, <code>toupper</code></td></tr><tr><td><strong>stdbool.h</strong></td><td>布尔类型库</td><td><code>bool</code>, <code>true</code>, <code>false</code></td></tr><tr><td><strong>assert.h</strong></td><td>断言库</td><td><code>assert</code></td></tr></tbody></table><h4 id="_6-2-4-4-预处理命令" tabindex="-1">6.2.4.4 预处理命令 <a class="header-anchor" href="#_6-2-4-4-预处理命令" aria-label="Permalink to "6.2.4.4 预处理命令""></a></h4><ul><li><code>#include</code> 命令的作用是将指定文件的内容插入到包含该命令的源文件中。这通常用于包含头文件,以便使用头文件中声明的函数、宏和数据类型。</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:#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:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> <filename></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:#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:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "filename"</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><h1 id="第七章-clion-高级配置-⭐" tabindex="-1">第七章:CLion 高级配置(⭐) <a class="header-anchor" href="#第七章-clion-高级配置-⭐" aria-label="Permalink to "第七章:CLion 高级配置(⭐)""></a></h1><h2 id="_7-1-安装和配置-wsl2" tabindex="-1">7.1 安装和配置 WSL2 <a class="header-anchor" href="#_7-1-安装和配置-wsl2" aria-label="Permalink to "7.1 安装和配置 WSL2""></a></h2><h3 id="_7-1-1-概述" tabindex="-1">7.1.1 概述 <a class="header-anchor" href="#_7-1-1-概述" aria-label="Permalink to "7.1.1 概述""></a></h3><ul><li>WSL 2,全称为 Windows Subsystem for Linux 2,是微软提供的一种技术,允许用户在 Windows 操作系统上运行 Linux 内核。WSL 2 是 WSL 的升级版,它引入了一个真正的 Linux 内核来代替 WSL 1 中使用的兼容层,从而提供更高的性能和更广泛的系统调用支持。</li><li>其架构图,如下所示:</li></ul><p><img src="`+La+'" alt=""></p><ul><li><p>WSL2 的功能,如下所示:</p><ul><li>① <strong>真实的Linux内核</strong>:WSL 2 使用了微软开发的轻量级虚拟机,它包含了一个完整的 Linux 内核。这意味着 WSL 2 能够运行更多的 Linux 应用程序,并且支持更多的系统调用。</li><li>② <strong>文件系统性能提升</strong>:WSL 2 的文件系统性能比 WSL 1 有显著提升。对于 I/O 密集型的操作,如:编译代码或数据库操作,WSL 2 能够提供更快的速度。</li><li>③ <strong>兼容性增强</strong>:由于使用了真实的 Linux 内核,WSL 2 对 Linux 应用程序的兼容性大幅提高。许多在 WSL 1上不能运行或需要调整的应用程序,可以在 WSL 2上直接运行。</li><li>④ <strong>网络功能改进</strong>:WSL 2 提供了更好的网络集成,能够更容易地与 Windows 上的其他网络资源进行交互。</li><li>⑤ <strong>资源使用优化</strong>:WSL 2 使用轻量级虚拟机,比传统的虚拟机占用更少的资源,同时提供了类似的隔离和安全性。</li></ul></li><li><p>WSL 的用途,如下所示:</p><ul><li>① <strong>开发环境</strong>:WSL 2 为开发者提供了一个原生的Linux开发环境,而无需离开 Windows 。这对于需要在 Linux 上开发、测试或运行应用程序的开发者非常有帮助。</li><li>② <strong>学习和实验</strong>:用户可以使用 WSL 2 在Windows上学习和实验 Linux 命令行工具和应用程序,而无需设置双重引导系统或安装虚拟机。</li><li>③ <strong>多平台开发</strong>:对于跨平台开发者来说,WSL 2 允许他们在一个操作系统上同时进行 Windows 和 Linux 平台的开发和测试,提高工作效率。</li><li>④ <strong>运行 Linux 工具和应用程序</strong>:WSL 2 支持在 Windows 上直接运行各种 Linux 工具和应用程序,如:Docker、数据库、编程语言环境等。</li></ul></li></ul><h3 id="_7-1-2-wsl2-的安装" tabindex="-1">7.1.2 WSL2 的安装 <a class="header-anchor" href="#_7-1-2-wsl2-的安装" aria-label="Permalink to "7.1.2 WSL2 的安装""></a></h3><ul><li>① BIOS 或 UEFI 中,开启虚拟化:步骤略。</li></ul><p><img src="'+Wa+'" alt=""></p><ul><li>② 查看是否开启了虚拟化:</li></ul><p><img src="'+Ta+'" alt=""></p><ul><li>③ 启用适用于 Linux 的 Windows 子系统:</li></ul><div class="language-powershell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">powershell</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;">dism.exe</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> /</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">online </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">enable-feature</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> /</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">featurename:Microsoft</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">Windows</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">Subsystem</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">Linux </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">all </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">norestart</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>以管理员身份打开 PowerShell 并运行,执行完上述命令之后,如果提示需要重启计算机,那就重启计算机。</p></div><p><img src="'+Ia+'" alt=""></p><ul><li>④ 启用虚拟机功能:</li></ul><div class="language-powershell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">powershell</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;">dism.exe</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> /</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">online </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">enable-feature</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> /</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">featurename:VirtualMachinePlatform </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">all </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">norestart</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>以管理员身份打开 PowerShell 并运行,执行完上述命令之后,如果提示需要重启计算机,那就重启计算机。</p></div><p><img src="'+Oa+'" alt=""></p><ul><li>⑤ 更新 Linux 内核包:</li></ul><div class="language-powershell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">powershell</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;">wsl </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">--</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">update</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>wsl2 的最新 Linux 内核包托管在 GitHub 上,某些国家可能会污染 Github 相关的域名,那么就需要手动下载,然后安装即可,下载地址在<a href="https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi" target="_blank" rel="noreferrer">这里</a>。</p></div><p><img src="'+Ma+'" alt=""></p><ul><li>⑥ 将 wsl2 设置为默认版本:</li></ul><div class="language-powershell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">powershell</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;">wsl </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">--</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">set-default</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">version </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+Na+'" alt=""></p><ul><li>⑦ 查看官方在线支持的 Linux 版本:</li></ul><div class="language-powershell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">powershell</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;">wsl </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">--</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">list </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">--</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">online</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+Ua+'" alt=""></p><ul><li>⑧ 安装指定版本的 Linux :</li></ul><div class="language-powershell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">powershell</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;">wsl </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">--</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">install Ubuntu</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">24.04</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>官方支持的 Linux 版本,托管在 Github 上,某些国家可能会污染 Github 的域名;此时,要么走科学上网,要么在 <code>Microsoft Store</code> 中搜索并安装。</p></div><p><img src="'+Ra+'" alt=""></p><ul><li>⑨ 在 Microsoft Store 中搜索并安装(可选):</li></ul><p><img src="'+Ga+'" alt=""></p><ul><li>⑩ 查询本地安装的 Linux 版本:</li></ul><div class="language-powershell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">powershell</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;">wsl </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">--</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">list</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+Ha+`" alt=""></p><h3 id="_7-1-3-配置-wsl2" tabindex="-1">7.1.3 配置 WSL2 <a class="header-anchor" href="#_7-1-3-配置-wsl2" aria-label="Permalink to "7.1.3 配置 WSL2""></a></h3><ul><li>本人的安装的是 AlmaLinux9 ,所以需要执行如下命令,以便安装 cmake 相关工具链:</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;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dnf</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:#6A737D;--shiki-dark:#6A737D;"> # 更新包管理器 </span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dnf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> groupinstall</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "Development Tools"</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 安装开发工具包</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dnf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> gcc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> gcc-c++</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 安装GCC相关工具链</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dnf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> cmake</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 安装 cmake</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dnf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> make</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 安装 make</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dnf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> gdb</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 安装 gdb</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></div></div><p><img src="`+Va+'" alt=""></p><ul><li>可以通过 CLion 测试是否安装成功:</li></ul><p><img src="'+Xa+`" alt=""></p><h3 id="_7-1-4-配置-wsl2" tabindex="-1">7.1.4 配置 WSL2 <a class="header-anchor" href="#_7-1-4-配置-wsl2" aria-label="Permalink to "7.1.4 配置 WSL2""></a></h3><ul><li>本人的安装的是 Ubuntu 24.04,所以需要执行如下命令,以便安装 cmake 相关工具链:</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;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> apt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> update</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> && </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> apt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> upgrade</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 更新包管理器</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> apt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> build-essential</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 安装开发工具包</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> apt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> gcc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> g++</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 安装 GCC 相关工具链</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> apt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> cmake</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 安装 cmake</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> apt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> gdb</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 安装 gdb</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><p><img src="`+Ka+'" alt=""></p><ul><li>可以通过 CLion 测试是否安装成功:</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>默认仓库中的 GDB 的版本会很高,CLion 会不支持,那么就需要手动下载源码,自行编译,本次不再演示!!!</p></div><p><img src="'+Qa+'" alt=""></p><h2 id="_7-2-切换-clion-中的-cmake-的工具链" tabindex="-1">7.2 切换 CLion 中的 cmake 的工具链 <a class="header-anchor" href="#_7-2-切换-clion-中的-cmake-的工具链" aria-label="Permalink to "7.2 切换 CLion 中的 cmake 的工具链""></a></h2><ul><li>可以在 CLoin 中切换 cmake 的工具链,以便支持不同平台的 cmake ,即:</li></ul><p><img src="'+ja+'" alt=""></p><h2 id="_7-3-修改-cmakelists-txt-文件" tabindex="-1">7.3 修改 CMakeLists.txt 文件 <a class="header-anchor" href="#_7-3-修改-cmakelists-txt-文件" aria-label="Permalink to "7.3 修改 CMakeLists.txt 文件""></a></h2><ul><li>前文也提到了,在一个 C 语言项目中,只能有一个 main() 函数;但是,我们可以修改 <code>CMakeLists.txt</code> 文件的内容,以便其支持在一个 C 语言项目中,可以有多个包含 main() 函数的文件,如下所示:</li></ul><p><img src="'+Ja+`" alt=""></p><ul><li><code>CMakeLists.txt</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>cmake_minimum_required(VERSION 3.10)</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span># 项目名称和版本号</span></span>
|
||||
<span class="line"><span>project(c-study VERSION 1.0 LANGUAGES C)</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span># 设置 C 标准</span></span>
|
||||
<span class="line"><span>set(CMAKE_C_STANDARD 11)</span></span>
|
||||
<span class="line"><span>set(CMAKE_C_STANDARD_REQUIRED True)</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span># 辅助函数,用于递归查找所有源文件</span></span>
|
||||
<span class="line"><span>function(collect_sources result dir)</span></span>
|
||||
<span class="line"><span> file(GLOB_RECURSE new_sources "\${dir}/*.c")</span></span>
|
||||
<span class="line"><span> set(\${result} \${\${result}} \${new_sources} PARENT_SCOPE)</span></span>
|
||||
<span class="line"><span>endfunction()</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span># 查找顶层 include 目录(如果存在)</span></span>
|
||||
<span class="line"><span>if (EXISTS "\${CMAKE_SOURCE_DIR}/include")</span></span>
|
||||
<span class="line"><span> include_directories(\${CMAKE_SOURCE_DIR}/include)</span></span>
|
||||
<span class="line"><span>endif ()</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span># 查找所有源文件</span></span>
|
||||
<span class="line"><span>set(SOURCES)</span></span>
|
||||
<span class="line"><span>collect_sources(SOURCES \${CMAKE_SOURCE_DIR})</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span># 用于存储已经处理过的可执行文件名,防止重复</span></span>
|
||||
<span class="line"><span>set(EXECUTABLE_NAMES)</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span># 创建可执行文件</span></span>
|
||||
<span class="line"><span>foreach (SOURCE \${SOURCES})</span></span>
|
||||
<span class="line"><span> # 获取文件的相对路径</span></span>
|
||||
<span class="line"><span> file(RELATIVE_PATH REL_PATH \${CMAKE_SOURCE_DIR} \${SOURCE})</span></span>
|
||||
<span class="line"><span> # 将路径中的斜杠替换为下划线,生成唯一的可执行文件名</span></span>
|
||||
<span class="line"><span> string(REPLACE "/" "_" EXECUTABLE_NAME \${REL_PATH})</span></span>
|
||||
<span class="line"><span> string(REPLACE "\\\\" "_" EXECUTABLE_NAME \${EXECUTABLE_NAME})</span></span>
|
||||
<span class="line"><span> string(REPLACE "." "_" EXECUTABLE_NAME \${EXECUTABLE_NAME})</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span> # 处理与 CMakeLists.txt 文件同名的问题</span></span>
|
||||
<span class="line"><span> if (\${EXECUTABLE_NAME} STREQUAL "CMakeLists_txt")</span></span>
|
||||
<span class="line"><span> set(EXECUTABLE_NAME "\${EXECUTABLE_NAME}_exec")</span></span>
|
||||
<span class="line"><span> endif ()</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span> # 检查是否已经创建过同名的可执行文件</span></span>
|
||||
<span class="line"><span> if (NOT EXECUTABLE_NAME IN_LIST EXECUTABLE_NAMES)</span></span>
|
||||
<span class="line"><span> list(APPEND EXECUTABLE_NAMES \${EXECUTABLE_NAME})</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span> # 创建可执行文件</span></span>
|
||||
<span class="line"><span> add_executable(\${EXECUTABLE_NAME} \${SOURCE})</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span> # 查找源文件所在的目录,并添加为包含目录(头文件可能在同一目录下)</span></span>
|
||||
<span class="line"><span> get_filename_component(DIR \${SOURCE} DIRECTORY)</span></span>
|
||||
<span class="line"><span> target_include_directories(\${EXECUTABLE_NAME} PRIVATE \${DIR})</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span> # 检查并添加子目录中的 include 目录(如果存在)</span></span>
|
||||
<span class="line"><span> if (EXISTS "\${DIR}/include")</span></span>
|
||||
<span class="line"><span> target_include_directories(\${EXECUTABLE_NAME} PRIVATE \${DIR}/include)</span></span>
|
||||
<span class="line"><span> endif ()</span></span>
|
||||
<span class="line"><span> endif ()</span></span>
|
||||
<span class="line"><span>endforeach ()</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="_7-4-配置-clang-format-文件" tabindex="-1">7.4 配置 .clang-format 文件 <a class="header-anchor" href="#_7-4-配置-clang-format-文件" aria-label="Permalink to "7.4 配置 .clang-format 文件""></a></h2><ul><li>配置 <code>.clang-format</code> 格式化文件,以便写代码的时候,可以自动保存并格式化 C 程序代码,如下所示:</li></ul><p><img src="`+$a+`" alt=""></p><ul><li><code>.clang-format</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>BasedOnStyle: Google</span></span>
|
||||
<span class="line"><span>IndentWidth: 4</span></span>
|
||||
<span class="line"><span>UseTab: Never</span></span>
|
||||
<span class="line"><span>ColumnLimit: 0</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span># 控制大括号的位置</span></span>
|
||||
<span class="line"><span>BreakBeforeBraces: Attach</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span># 控制空行的使用</span></span>
|
||||
<span class="line"><span>EmptyLineBeforeAccessModifier: Never</span></span>
|
||||
<span class="line"><span>KeepEmptyLinesAtTheStartOfBlocks: true</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span># 控制短函数、短 if 语句和循环的格式</span></span>
|
||||
<span class="line"><span>AllowShortFunctionsOnASingleLine: Empty</span></span>
|
||||
<span class="line"><span>AllowShortIfStatementsOnASingleLine: false</span></span>
|
||||
<span class="line"><span>AllowShortLoopsOnASingleLine: false</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span># 控制其他格式选项</span></span>
|
||||
<span class="line"><span>AlignConsecutiveAssignments: true</span></span>
|
||||
<span class="line"><span>AlignConsecutiveDeclarations: true</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span># 控制注释的格式化</span></span>
|
||||
<span class="line"><span>ReflowComments: true</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span># 控制包含指令的格式化</span></span>
|
||||
<span class="line"><span>IncludeBlocks: Regroup</span></span>
|
||||
<span class="line"><span>SortIncludes: CaseInsensitive</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span>SpaceBeforeParens: ControlStatements</span></span>
|
||||
<span class="line"><span>SpacesInParentheses: false</span></span>
|
||||
<span class="line"><span>SpacesInAngles: false</span></span>
|
||||
<span class="line"><span>SpacesInContainerLiterals: false</span></span>
|
||||
<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="`+Ya+'" alt=""></p><h2 id="_7-5-配置-gitignore-文件" tabindex="-1">7.5 配置 .gitignore 文件 <a class="header-anchor" href="#_7-5-配置-gitignore-文件" aria-label="Permalink to "7.5 配置 .gitignore 文件""></a></h2><ul><li>需要在项目中,配置 <code>.gitignore</code> 文件,以便在提交代码到 Git 仓库的时候,忽略某些文件或目录,如下所示:</li></ul><p><img src="'+za+`" alt=""></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="_7-6-演示" tabindex="-1">7.6 演示 <a class="header-anchor" href="#_7-6-演示" aria-label="Permalink to "7.6 演示""></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="`+Za+'" alt=""></p><h1 id="第八章-c-语言的编译过程-⭐" tabindex="-1">第八章:C 语言的编译过程(⭐) <a class="header-anchor" href="#第八章-c-语言的编译过程-⭐" aria-label="Permalink to "第八章:C 语言的编译过程(⭐)""></a></h1><h2 id="_8-1-概述" tabindex="-1">8.1 概述 <a class="header-anchor" href="#_8-1-概述" aria-label="Permalink to "8.1 概述""></a></h2><ul><li>C 程序的编译过程,如下所示:</li></ul><p><img src="'+si+'" alt=""></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><strong>头文件包含</strong>:将头文件的内容插入到源文件中。例如:<code>#include <stdio.h></code>会被替换为<code>stdio.h</code>文件的内容。</p></li><li><p><strong>宏展开</strong>:替换宏定义。例如:<code>#define PI 3.14</code>会将代码中的<code>PI</code>替换为<code>3.14</code>。</p></li><li><p><strong>条件编译</strong>:根据条件指令(如:<code>#ifdef</code>、<code>#ifndef</code>)有选择地编译代码。</p></li><li><p><strong>删除代码中的注释,但是不会进行语法检查</strong>。</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><stdio.h></code> 中的 <code>printf()</code> 函数,这些函数不是程序员自己写的,而是 C 程序库中提供的,因此需要链接。其实,在链接过程中,还会加入启动代码,这个启动代码(和系统相关,Linux 下主要有 crt0.c、crti.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="_8-2-gcc-编译器的介绍" tabindex="-1">8.2 GCC 编译器的介绍 <a class="header-anchor" href="#_8-2-gcc-编译器的介绍" aria-label="Permalink to "8.2 GCC 编译器的介绍""></a></h2><ul><li>编辑器,如:vim 、vscode 等,是指我们用它来编写源程序的(编辑代码),而我们写的代码语句,电脑是不懂的,我们需要把它转成电脑能懂的语句,编译器就是这样的转化工具。换言之,我们用编辑器编写程序,由编译器编译后才可以运行!</li><li>编译器是将易于编写、阅读和维护的高级计算机语言翻译为计算机能解读、运行的低级机器语言的程序。</li><li>gcc(GNU Compiler Collection,GNU 编译器套件),是由 GNU 开发的编程语言编译器。gcc 原本作为 GNU 操作系统的官方编译器,现已被大多数类 Unix 操作系统(如:Linux、BSD、Mac OS X 等)采纳为标准的编译器,gcc 同样适用于微软的 Windows 。</li><li>gcc 最初用于编译 C 语言,随着项目的发展, gcc 已经成为了能够编译 C、C++、Java、Ada、fortran、Object C、Object C++、Go 语言的编译器大家族。</li></ul><h2 id="_8-3-通过-gcc-直接生成可执行文件" tabindex="-1">8.3 通过 gcc 直接生成可执行文件 <a class="header-anchor" href="#_8-3-通过-gcc-直接生成可执行文件" aria-label="Permalink to "8.3 通过 gcc 直接生成可执行文件""></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="'+ai+'" alt=""></p><h2 id="_8-4-通过-gcc-分步编译" tabindex="-1">8.4 通过 gcc 分步编译 <a class="header-anchor" href="#_8-4-通过-gcc-分步编译" aria-label="Permalink to "8.4 通过 gcc 分步编译""></a></h2><h3 id="_8-3-1-概述" tabindex="-1">8.3.1 概述 <a class="header-anchor" href="#_8-3-1-概述" aria-label="Permalink to "8.3.1 概述""></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;">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 style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 通常以 .i 结尾表示这个文件是一个中间状态</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><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;"> -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 style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 在 Linux 中,通常以 .s 结尾;在 Windows 中,通常以 .asm 结尾</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><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;"> -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 style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 在 Linux 中,通常以 .o 结尾;在 Windows 中,通常以 .obj 结尾</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><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;"> 源文件.o</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 源文件.exe</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 在 Linux 中,通常以 .out 结尾;在 Windows 中,通常以 .exe 结尾</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><h3 id="_8-4-2-应用示例" tabindex="-1">8.4.2 应用示例 <a class="header-anchor" href="#_8-4-2-应用示例" aria-label="Permalink to "8.4.2 应用示例""></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;">gcc</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -E</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.i</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+ii+'" alt=""></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;"> -S</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> HelloWorld.i</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> HelloWorld.s</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+ni+'" alt=""></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;"> -c</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> HelloWorld.s</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> HelloWorld.o</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=""></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:#032F62;--shiki-dark:#9ECBFF;"> HelloWorld.o</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="'+ei+'" alt=""></p>',546),ri=[pi];function ci(oi,hi,di,ki,ui,gi){return i(),a("div",null,ri)}const Ei=s(ti,[["render",ci]]);export{mi as __pageData,Ei as default};
|
1
assets/notes_01_c-basic_01_xdx_index.md.D1hb9NAd.lean.js
Normal file
@ -0,0 +1 @@
|
||||
import{_ as s,c as a,o as i,a5 as n}from"./chunks/framework.D1oHBMsh.js";const l="/coa6/assets/1.D4a42fT1.jpg",e="/coa6/assets/2.D2wnxl5F.png",t="/coa6/assets/3.Dq625oo9.jpg",p="/coa6/assets/4.uqu1DEK4.png",r="/coa6/assets/5.C6Q0Q8kf.jpg",c="/coa6/assets/6.B4Srsb-0.png",o="/coa6/assets/7._D_c8Lrn.png",h="/coa6/assets/8.DlIyFGDg.png",d="/coa6/assets/9.7zkUmpQw.png",k="/coa6/assets/10.h1ugtjyX.png",u="/coa6/assets/11.D5PWTabw.png",g="/coa6/assets/12.Bvs6QYjl.jpg",b="/coa6/assets/9.7zkUmpQw.png",m="/coa6/assets/14.CsR5exrN.png",E="/coa6/assets/15.BRG9GQdT.png",y="/coa6/assets/16.C2sciGZn.png",C="/coa6/assets/17.DdyXXyxJ.png",F="/coa6/assets/18.DIeb_KXW.png",_="/coa6/assets/19.C-kvMz2p.png",v="/coa6/assets/20.CQqFxmDa.png",A="/coa6/assets/21.CjMWyIiX.png",f="/coa6/assets/22.DFQhcDgs.png",x="/coa6/assets/23.Cco1vsW8.png",B="/coa6/assets/24.D60Zf6_d.png",D="/coa6/assets/25.D2-G6nV2.png",q="/coa6/assets/26.DpzkVk5V.png",w="/coa6/assets/27.BXk95GIP.png",S="/coa6/assets/28.CbWTB08W.png",P="/coa6/assets/29.twO9TCIg.png",L="/coa6/assets/30.CKOjeIvS.png",W="/coa6/assets/31.DKmR0CxE.png",T="/coa6/assets/32.Cudf77_s.gif",I="/coa6/assets/33.BBUUlhRC.png",O="/coa6/assets/34.iLABkB7O.png",M="/coa6/assets/35.BQuYWOU9.png",N="/coa6/assets/36.CslpH6j0.png",U="/coa6/assets/37.BAyvZdKq.png",R="/coa6/assets/38.C3oC1iUd.png",G="/coa6/assets/39.Ds-jsEZn.png",H="/coa6/assets/40.Cd37gMYs.png",V="/coa6/assets/41.CAw2z3gc.png",X="/coa6/assets/42.DdPThnr-.png",K="/coa6/assets/43.q_rvlDnY.png",Q="/coa6/assets/44.JRHg9RZA.png",j="/coa6/assets/45.Baq-Hb06.png",J="/coa6/assets/46.c1ht53mu.png",$="/coa6/assets/47.CAZmH5Py.png",Y="/coa6/assets/48.DWeCYBe9.png",z="/coa6/assets/49.2XM8pYni.png",Z="/coa6/assets/50.CN0t-fuo.png",ss="/coa6/assets/51.AcDh3LXQ.png",as="/coa6/assets/52.CUkDFAc6.png",is="/coa6/assets/53.picNTNaJ.png",ns="/coa6/assets/54.DKX92RgJ.png",ls="/coa6/assets/55.Bxr7QKI3.png",es="/coa6/assets/56.DuFWsOgW.png",ts="/coa6/assets/57.Da9qUcfr.png",ps="/coa6/assets/58.7_gEABSX.gif",rs="/coa6/assets/59.C2KQYoVC.gif",cs="/coa6/assets/60.RTUP8Vtx.png",os="/coa6/assets/61.Dq21DxwL.png",hs="/coa6/assets/62.QmpUaNxU.png",ds="/coa6/assets/63.DP0C29gZ.png",ks="/coa6/assets/64.DwzHokd4.png",us="/coa6/assets/65.Bi6K26yA.png",gs="/coa6/assets/66.Bw8DcEQ_.png",bs="/coa6/assets/67.DPc8Z9rS.png",ms="/coa6/assets/68.S84xHMTl.png",Es="/coa6/assets/69.iw3JQUkn.png",ys="/coa6/assets/70.ILeJt-HK.png",Cs="/coa6/assets/71.CHgm7khh.png",Fs="/coa6/assets/72.N1nqJaEg.png",_s="/coa6/assets/73.DHsnibMi.png",vs="/coa6/assets/74.BQr6Q0uV.png",As="/coa6/assets/75.BVemi2Lh.png",fs="/coa6/assets/76.BHR69UXx.png",xs="/coa6/assets/77.CPSU5SJI.png",Bs="/coa6/assets/78.CaQLoDlw.png",Ds="/coa6/assets/79.aRGy4XbL.png",qs="/coa6/assets/80.kNO9fmPR.png",ws="/coa6/assets/81.D4EkoC4o.png",Ss="/coa6/assets/82.V23Lo9e_.png",Ps="/coa6/assets/83.Du9LVeMB.png",Ls="/coa6/assets/84.DdFg75U9.png",Ws="/coa6/assets/85.C6bz6KtT.png",Ts="/coa6/assets/86.CB6LAhB5.png",Is="/coa6/assets/87.Bip8bkua.png",Os="/coa6/assets/88.DRNHRduW.png",Ms="/coa6/assets/89.Cth4qqEn.png",Ns="/coa6/assets/90.DWGWZ64P.png",Us="/coa6/assets/91.3hDIDdvx.png",Rs="/coa6/assets/92.Bw_dQ4ap.png",Gs="/coa6/assets/93.Cn_ubTyA.png",Hs="/coa6/assets/94.C84EBqwB.png",Vs="/coa6/assets/95.dZfJY4eR.png",Xs="/coa6/assets/96.B0zm0Z79.png",Ks="/coa6/assets/97.CaTcEy1Q.png",Qs="/coa6/assets/98.iEc8mo9g.png",js="/coa6/assets/99.Co2KxM6t.png",Js="/coa6/assets/100.CaUm8Qhc.png",$s="/coa6/assets/101.kOkqIKG6.png",Ys="/coa6/assets/102.CyeASH-c.png",zs="/coa6/assets/103.CFdk60La.png",Zs="/coa6/assets/104.Bhl-0uK_.png",sa="/coa6/assets/105.Dni9KbXV.png",aa="/coa6/assets/106.BXx10MCV.png",ia="/coa6/assets/107.CXcIKX1T.png",na="/coa6/assets/108.CQ3_QCQT.png",la="/coa6/assets/109.CQoDRJM5.gif",ea="/coa6/assets/110.CPfwZvD9.gif",ta="/coa6/assets/111.bxEomEjU.gif",pa="/coa6/assets/112.C_onhf2k.png",ra="/coa6/assets/113.Budj3s38.gif",ca="/coa6/assets/114.CH8koQdu.gif",oa="/coa6/assets/115.kUJhxMtg.png",ha="/coa6/assets/116.BJeJJW4_.png",da="/coa6/assets/117.BCuK6eJL.gif",ka="/coa6/assets/118.rKC-z4z-.gif",ua="/coa6/assets/119.BJE3xxuT.gif",ga="/coa6/assets/120.DJOq__O0.gif",ba="/coa6/assets/121.BDt_0fRR.png",ma="/coa6/assets/122.Bo5OawW8.png",Ea="/coa6/assets/123.sUWUfl5e.png",ya="/coa6/assets/124.BK4jpnB8.png",Ca="/coa6/assets/125.EF8vdbSq.png",Fa="/coa6/assets/126.DjxdA_Co.png",_a="/coa6/assets/127.sp68q1hh.gif",va="/coa6/assets/128.DhMRyxNN.gif",Aa="/coa6/assets/129.CdcLZM0R.gif",fa="/coa6/assets/130.D-5AsTTr.png",xa="/coa6/assets/131.2RQKmAUa.png",Ba="/coa6/assets/132.CI4xX8SM.png",Da="/coa6/assets/133.C8QUZ9v3.gif",qa="/coa6/assets/134.g5tQfhWz.gif",wa="/coa6/assets/135.CX0_1NsE.gif",Sa="/coa6/assets/136.BrFJeoK6.png",Pa="/coa6/assets/137.58TjSSjH.gif",La="/coa6/assets/138.CgqNV2hL.png",Wa="/coa6/assets/139.BasYWvkM.png",Ta="/coa6/assets/140.CjFxJpBr.png",Ia="/coa6/assets/141.Dm5Jspvp.gif",Oa="/coa6/assets/142.1krCh8cy.gif",Ma="/coa6/assets/143.DOSyahv7.gif",Na="/coa6/assets/144.BHEvX_FI.gif",Ua="/coa6/assets/145.DFA0g1_d.gif",Ra="/coa6/assets/146.D50nO5eA.gif",Ga="/coa6/assets/147.cAvG1Qfq.png",Ha="/coa6/assets/148.DpakQFWz.gif",Va="/coa6/assets/149.Bg61j9QI.gif",Xa="/coa6/assets/150.DPvD9UCw.gif",Ka="/coa6/assets/151.Ceu65U_n.gif",Qa="/coa6/assets/152.BWPFRK_8.gif",ja="/coa6/assets/153.Ct4TfxPf.gif",Ja="/coa6/assets/154.zsKtx_jV.png",$a="/coa6/assets/155.3oqDAW0w.png",Ya="/coa6/assets/156.D9TSeAa9.gif",za="/coa6/assets/157.CCRgYIVq.png",Za="/coa6/assets/158.C1t2T6FV.gif",si="/coa6/assets/159.Rqa4uHq6.png",ai="/coa6/assets/160.6yQYnjOa.gif",ii="/coa6/assets/161.hYR9GiiD.gif",ni="/coa6/assets/162.D3b-QIrA.gif",li="/coa6/assets/163.DGbA6qsW.gif",ei="/coa6/assets/164.BToOkxf2.gif",mi=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":1720685105000}'),ti={name:"notes/01_c-basic/01_xdx/index.md"},pi=n("",546),ri=[pi];function ci(oi,hi,di,ki,ui,gi){return i(),a("div",null,ri)}const Ei=s(ti,[["render",ci]]);export{mi as __pageData,Ei as default};
|
207
assets/notes_01_c-basic_02_xdx_index.md.k6oVENcd.js
Normal file
@ -0,0 +1,207 @@
|
||||
import{_ as s,c as i,o as a,a5 as n}from"./chunks/framework.D1oHBMsh.js";const l="/coa6/assets/1.CXNJqOOc.png",e="/coa6/assets/2.E0LS08Y5.png",t="/coa6/assets/3.XcPl7d9s.png",p="/coa6/assets/4.DL02VQMp.png",h="/coa6/assets/5.Dr67r_Ws.png",d="/coa6/assets/6.C5XiXNVN.png",k="/coa6/assets/7.DO8XxSV6.jpg",r="/coa6/assets/8.CUXrdefp.jpeg",c="/coa6/assets/9.uqLiL_yu.png",o="/coa6/assets/10.CkykpHY2.png",E="/coa6/assets/11.DV1YbrOP.png",u="/coa6/assets/12.AHNJT9TV.png",b="/coa6/assets/13.Bs-MOwx2.png",g="/coa6/assets/14.StzjmBz-.png",F="/coa6/assets/15.C0wVWaxD.png",y="/coa6/assets/16.LXJMAihe.png",m="/coa6/assets/17._UTCq3PD.png",C="/coa6/assets/18.BjQ5kBL-.png",B="/coa6/assets/19.COIOzcmT.png",v="/coa6/assets/20.Cu__mjav.png",A="/coa6/assets/21.BX_KzkHt.png",_="/coa6/assets/22.COt_QxSP.png",S=JSON.parse('{"title":"第一章:变量(⭐)","description":"","frontmatter":{},"headers":[],"relativePath":"notes/01_c-basic/02_xdx/index.md","filePath":"notes/01_c-basic/02_xdx/index.md","lastUpdated":1720685105000}'),D={name:"notes/01_c-basic/02_xdx/index.md"},q=n('<h1 id="第一章-变量-⭐" tabindex="-1">第一章:变量(⭐) <a class="header-anchor" href="#第一章-变量-⭐" aria-label="Permalink to "第一章:变量(⭐)""></a></h1><h2 id="_1-1-程序中变化的数据" tabindex="-1">1.1 程序中变化的数据 <a class="header-anchor" href="#_1-1-程序中变化的数据" aria-label="Permalink to "1.1 程序中变化的数据""></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="'+l+'" alt=""></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 "1.2 变量""></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="'+e+`" alt=""></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 "1.3 变量的声明和使用""></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><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;"> <stdio.h></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;"> // 声明一个整型变量,取名为 a</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>
|
||||
<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;"> 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;">"a = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, a);</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;"> <stdio.h></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;"> // 声明一个整型变量,取名为 b ,并直接赋值(初始化,实际开发中最为常用)</span></span>
|
||||
<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;"> 200</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;"> // 修改变量 b 的值,将变量 a 的值赋值给变量 b</span></span>
|
||||
<span class="line"><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;"> 300</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;">"b= </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</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></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;"> <stdio.h></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;"> c1 </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;">, c2 </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;">, c3 </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;">"c1 = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, c1);</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"c2 = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, c2);</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"c3 = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, 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></div></div><h2 id="_1-4-输出变量" tabindex="-1">1.4 输出变量 <a class="header-anchor" href="#_1-4-输出变量" aria-label="Permalink to "1.4 输出变量""></a></h2><ul><li>在计算机中,所谓的<code>输入</code>和<code>输出</code>都是以计算机(CPU 和内存)为主体而言的,即:</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>输入:从输入设备(键盘、鼠标、扫描仪)向计算机输入数据。</p><p>输出:从计算机向外部输出设备(显示器、打印机)输出数据。</p></div><p><img src="`+t+`" alt=""></p><ul><li>在 C 语言中,提供了 <code>printf()</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;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">__format</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><ul><li><code>printf</code> 的标准含义是格式化输出文本,来源于 <code>print formatted(格式化打印)</code>的缩写,其语法规则,如下所示:</li></ul><p><img src="`+p+'" alt=""></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>格式化字符串:是使用双引号括起来的字符串,里面包含了普通的字符串和格式占位符。</li><li>格式占位符(格式声明符):由 <code>%</code> 和<code>格式字符</code>组成,作用是将输出的数据转换为指定的格式后输出,这里的 <code>%d</code> 表示整数。</li><li>输出列表:是程序要输出的一些数据,可以是常量、变量或表达式,需要和格式占位符一一对应。</li></ul></div><ul><li><p>在计算机中,二进制、八进制、十进制以及十六进制的英文名称和缩写,如下所示:</p><ul><li>二进制(binary),缩写是 bin。</li><li>八进制(octal),缩写是 oct。</li><li>十进制(decimal),缩写是 dec。</li><li>十六进制(Hexadecimal),缩写是 hex。</li></ul></li><li><p>其实,我们也可以在 Windows 系统中的计算器中来看到,即:</p></li></ul><p><img src="'+h+`" alt=""></p><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p>在生活中的 decimal 是小数的意思;但是,在 C 语言中,decimal 的完整含义是 decimal integer ,即十进制整数。</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;"> <stdio.h></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;"> 18</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;"> // 使用输出语句,将变量 num 的值输出,其中 %d 表示输出的是整数</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</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;">"</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></div></div><h2 id="_1-5-输入数据赋值给变量" tabindex="-1">1.5 输入数据赋值给变量 <a class="header-anchor" href="#_1-5-输入数据赋值给变量" aria-label="Permalink to "1.5 输入数据赋值给变量""></a></h2><ul><li>在 C 语言中,提供了 <code>scanf()</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;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">__format</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><ul><li>其语法规则,如下所示:</li></ul><p><img src="`+d+`" alt=""></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p><code>&age</code>、<code>&num</code> 中的 <code>&</code>是寻址操作符,<code>&age</code> 表示变量 <code>age</code> 在内存中的地址。</p></div><div class="caution custom-block github-alert"><p class="custom-block-title">CAUTION</p><p></p><ul><li><p>① scanf() 函数中的 <code>%d</code>,如果是连着写,即:<code>%d%d</code>,那么在输入数据的时候,数据之间不可以使用逗号<code>,</code>分隔,只能使用空白字符(空格、tab 键或回车键),即:<code>2空格3tab</code>或<code>2tab3回车</code>等。</p></li><li><p>② 如果是 <code>%d,%d</code>,则输入的时候需要加上逗号<code>,</code>,即:<code>2,3</code>。</p></li><li><p>③ 如果是 <code>%d %d</code>,则输入的时候需要加上空格,即:<code>2空格3</code>。</p></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;"> <stdio.h></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;"> float</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> radius;</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;">"请输入一个半径:"</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;">"</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%f</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</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;">radius);</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;"> area </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 3.1415926</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> radius </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> radius;</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;">"半径是</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%f</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">的圆的面积是</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%.2lf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, radius, area);</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;"> <stdio.h></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>
|
||||
<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;">"请输入一个整数:"</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;">"</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</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;">num);</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;"> absNum;</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;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
|
||||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> absNum </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;">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:#24292E;--shiki-dark:#E1E4E8;"> absNum </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;"> }</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;">"</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:#24292E;--shiki-dark:#E1E4E8;">, num, absNum);</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;"> <stdio.h></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;"> a, b, c;</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"请输入整数 a 、b 和 c 的值:"</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;">"</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> %d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> %d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</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:#D73A49;--shiki-dark:#F97583;">&</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">b, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&</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;"> 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:#24292E;--shiki-dark:#E1E4E8;"> a </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> b </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> c;</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;">"</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;"> = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, a, b, c, result);</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><h2 id="_1-6-标识符" tabindex="-1">1.6 标识符 <a class="header-anchor" href="#_1-6-标识符" aria-label="Permalink to "1.6 标识符""></a></h2><h3 id="_1-6-1-概述" tabindex="-1">1.6.1 概述 <a class="header-anchor" href="#_1-6-1-概述" aria-label="Permalink to "1.6.1 概述""></a></h3><ul><li>在 C 语言中,变量、函数、数组名、结构体等要素命名的时候使用的字符序列,称为标识符。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>在上世纪 60 - 70 年代的时候,因为国家贫穷,人民生活不富裕等原因,家长虽然会给孩子取名为:<code>张建国</code>、<code>李华强</code>等;但是,也会取小名为<code>二狗子</code>、<code>狗剩</code>等,目的是希望孩子能健康成长(养活),像 <code>张建国</code>、<code>李华强</code>、<code>二狗子</code>、<code>狗剩</code>都是名字(标识符),伴随人的一生。</p></div><h3 id="_1-6-2-标识符的命名规范" tabindex="-1">1.6.2 标识符的命名规范 <a class="header-anchor" href="#_1-6-2-标识符的命名规范" aria-label="Permalink to "1.6.2 标识符的命名规范""></a></h3><ul><li><p>强制规范:</p><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><p>建议规范:</p><ul><li>① 为了提高阅读性,使用有意义的单词,见名知意,如:sum,name,max,year 等。</li><li>② 使用下划线连接多个单词组成的标识符,如:max_classes_per_student 等。</li><li>③ 多个单词组成的标识符,除了使用下划线连接,也可以使用小驼峰命名法,除第一个单词外,后续单词的首字母大写,如: studentId、student_name 等。</li><li>④ 不要出现仅靠大小写区分不同的标识符,如:name、Name 容易混淆。</li><li>⑤ 系统内部使用了一些下划线开头的标识符,如:C99 标准添加的类型 <code>_Bool</code>,为防止冲突,建议开发者尽量避免使用下划线开头的标识符。</li></ul></li><li><p>示例:合法(不一定建议)的标识符</p></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>a、BOOK_sun、MAX_SIZE、Mouse、student23、Football、FOOTBALL、max、_add、num_1、sum_of_numbers</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><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>$zj、3sum、ab#cd、23student、Foot-baii、s.com、b&c、j**p、book-1、tax rate、don't</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><h3 id="_1-6-3-关键字" tabindex="-1">1.6.3 关键字 <a class="header-anchor" href="#_1-6-3-关键字" aria-label="Permalink to "1.6.3 关键字""></a></h3><ul><li>C 语言中的关键字是编译器<code>预定义</code>的<code>保留字</code>,它们有<code>特定</code>的<code>含义</code>和<code>用途</code>,用于控制程序的结构和执行。</li><li>C80 和 C90 (ANSI C)定义的关键字,如下所示:</li></ul><table tabindex="0"><thead><tr><th>类型(功能)</th><th>具体关键字</th></tr></thead><tbody><tr><td>数据类型关键字</td><td><code>char</code>、<code>double</code>、<code>float</code>、<code>int</code>、<code>long</code>、<code>short</code>、<code>signed</code>、<code>unsigned</code>、<code>void</code></td></tr><tr><td>存储类说明符关键字</td><td><code>auto</code>、<code>extern</code>、<code>register</code>、<code>static</code>、<code>typedef</code>、<code>volatile</code>、<code>const</code></td></tr><tr><td>控制语句关键字</td><td><code>break</code>、<code>case</code>、<code>continue</code>、<code>default</code>、<code>do</code>、<code>else</code>、<code>for</code>、<code>goto</code>、<code>if</code>、<code>return</code>、<code>switch</code>、<code>while</code></td></tr><tr><td>结构体、联合体和枚举关键字</td><td><code>enum</code>、<code>struct</code>、<code>union</code></td></tr><tr><td>其他关键字</td><td><code>sizeof</code></td></tr></tbody></table><ul><li>C99 新增的关键字,如下所示:</li></ul><table tabindex="0"><thead><tr><th>类型(功能)</th><th>具体关键字</th></tr></thead><tbody><tr><td>数据类型关键字</td><td><code>_Bool</code>、<code>_Complex</code>、<code>_Imaginary</code></td></tr><tr><td>存储类说明符关键字</td><td><code>inline</code>、<code>restrict</code></td></tr><tr><td>其他关键字</td><td><code>_Complex</code>、 <code>_Imaginary</code></td></tr></tbody></table><ul><li>C11 新增的关键字,如下所示:</li></ul><table tabindex="0"><thead><tr><th>类型(功能)</th><th>具体关键字</th></tr></thead><tbody><tr><td>存储类说明符关键字</td><td><code>_Atomic</code></td></tr><tr><td>其他关键字</td><td><code>_Alignas</code>、 <code>_Alignof</code>、 <code>_Generic</code>、 <code>_Noreturn</code>、 <code>_Static_assert</code>、 <code>_Thread_local</code></td></tr></tbody></table><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li>① 关键字不能用作标识符(如:变量名、函数名等)。</li><li>② 不要死记硬背这些关键字,在实际开发中,并不一定全部使用到;而且,在学到后面的时候,会自动记住这些关键字以及对应的含义。</li></ul></div><h1 id="第二章-常量-⭐" tabindex="-1">第二章:常量(⭐) <a class="header-anchor" href="#第二章-常量-⭐" aria-label="Permalink to "第二章:常量(⭐)""></a></h1><h2 id="_2-1-概述" tabindex="-1">2.1 概述 <a class="header-anchor" href="#_2-1-概述" aria-label="Permalink to "2.1 概述""></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>,就是一个常量,其值为 3.1415926 。</li><li>② 在生活中,人类的性别只有<code>男</code>和<code>女</code>;其中,<code>男</code>和<code>女</code>也是常量。</li><li>③ ...</li></ul></div><h2 id="_2-2-常量的分类" tabindex="-1">2.2 常量的分类 <a class="header-anchor" href="#_2-2-常量的分类" aria-label="Permalink to "2.2 常量的分类""></a></h2><ul><li>在 C 语言中的变量的分类,如下所示: <ul><li>① 字面量常量。</li><li>② 标识符常量: <ul><li><code>#define</code> 宏定义的标识符常量。</li><li><code>const</code> 关键字修饰的标识符常量。</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>所谓的<code>字面量常量</code>,就是可以直接使用的常量,不需要声明或定义,包括:整数常量、浮点数常量以及字符常量。</li><li>所谓的<code>标识符常量</code>,就是使用标识符来作为常量名,包括: <code>#define</code> 宏定义的标识符常量、<code>const</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;"> <stdio.h></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:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
|
||||
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 'A'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
|
||||
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 12.3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
|
||||
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "你好"</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></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;"> <stdio.h></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:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</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;">"</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;">"字符常量 =》</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%c\\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'A'</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;">"浮点数常量 =》</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%f\\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">12.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;">"字符串常量 =》</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%s\\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"你好"</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></div></div><h2 id="_2-3-使用-define-定义常量" tabindex="-1">2.3 使用 #define 定义常量 <a class="header-anchor" href="#_2-3-使用-define-定义常量" aria-label="Permalink to "2.3 使用 #define 定义常量""></a></h2><ul><li><code>#define</code> 来定义常量,也叫作宏定义,就是用一个标识符来表示一个常量值,如果在后面的代码中出现了该标识符,那么编译时就全部替换成指定的常量值,即用宏体替换所有宏名,简称<code>宏替换</code>。</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:#24292E;--shiki-dark:#E1E4E8;">#define 常量名 常量值</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="caution custom-block github-alert"><p class="custom-block-title">CAUTION</p><p></p><ul><li>① 其实<code>宏定义</code>的常量的<code>执行时机</code>是在<code>预处理</code>阶段,将所有<code>宏常量</code>替换完毕,才会继续编译代码。</li><li>② 不要以 <code>;</code> 结尾,如果有 <code>;</code> ,分号也会成为常量值的一部分。</li><li>③ <code># define</code> 必须写在 <code>main</code> 函数的外面!!!</li><li>④ <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;"> <stdio.h></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;"> PI</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 3.1415926</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;"> double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> radius </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2.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;"> double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> area </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> PI </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> radius </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> radius;</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;">"半径为</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%lf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">的圆的面积是</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%.2lf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, radius, area);</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><h2 id="_2-4-const-关键字" tabindex="-1">2.4 const 关键字 <a class="header-anchor" href="#_2-4-const-关键字" aria-label="Permalink to "2.4 const 关键字""></a></h2><ul><li>C99 标准新增,这种方式跟定义一个变量是类似的;只不过,需要在变量的数据类型前加上 <code>const</code> 关键字。</li><li>和使用 <code>#define定义宏常量</code>相比,const 定义的常量有详细的数据类型,而且会在编译阶段进行安全检查,在运行时才完成替换,所以会更加安全和方便。</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;">const</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></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</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;"> <stdio.h></span></span>
|
||||
<span class="line"></span>
|
||||
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> PI </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 3.1415926</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:#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;"> double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> radius </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2.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;"> double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> area </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> PI </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> radius </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> radius;</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;">"半径为</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%lf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">的圆的面积是</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%.2lf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, radius, area);</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><h2 id="_2-5-枚举常量" tabindex="-1">2.5 枚举常量 <a class="header-anchor" href="#_2-5-枚举常量" aria-label="Permalink to "2.5 枚举常量""></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;">enum</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 枚举常量 {</span></span>
|
||||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> xxx </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;"> yyy;</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>① 默认情况下,枚举常量是从 0 开始递增的。</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;"> <stdio.h></span></span>
|
||||
<span class="line"></span>
|
||||
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">enum</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> sex {</span></span>
|
||||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> MALE </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;"> FEMALE </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;">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;">"</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, MALE);</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</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;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, FEMALE);</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;"> <stdio.h></span></span>
|
||||
<span class="line"></span>
|
||||
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">enum</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Sex {</span></span>
|
||||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> MALE </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;"> FEMALE </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;">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;"> enum</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Sex sex;</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;">"请输入性别(1 表示男性, 2 表示女性):"</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;">"</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</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;">sex);</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</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;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, sex);</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-6-defind-定义常量-vs-const-定义常量" tabindex="-1">2.6 #defind 定义常量 VS const 定义常量 <a class="header-anchor" href="#_2-6-defind-定义常量-vs-const-定义常量" aria-label="Permalink to "2.6 #defind 定义常量 VS const 定义常量""></a></h2><ul><li>① 执行时机:<code>#define</code> 是预处理指令,在编译<code>之前</code>执行;<code>const</code> 是关键字,在编译<code>过程</code>中执行。</li><li>② 类型检查:<code>#define</code> 定义常量<code>不用指定类型</code>,<code>不进行类型检查</code>,只是简单地文本替换;<code>const</code> 定义常量<code>需要指定数据类型</code>,<code>会进行类型检查</code>,类型安全性更强。</li></ul><h1 id="第三章-二进制" tabindex="-1">第三章:二进制 <a class="header-anchor" href="#第三章-二进制" aria-label="Permalink to "第三章:二进制""></a></h1><h2 id="_3-1-概述" tabindex="-1">3.1 概述 <a class="header-anchor" href="#_3-1-概述" aria-label="Permalink to "3.1 概述""></a></h2><ul><li>计算机的底层只有<code>二进制</code>,即计算机中<code>运算</code>和<code>存储</code>的<code>所有数据</code>都需要转换为<code>二进制</code>,包括:数字、字符、图片、视频等。</li></ul><p><img src="`+k+'" alt=""></p><ul><li>之前,我们也提到现代的计算机(量子计算机除外)几乎都遵循<code>冯·诺依曼</code>体系结构,其理论要点如下: <ul><li>① <strong>存储程序</strong>:<code>程序指令</code>和<code>数据</code>都存储在计算机的内存中,这使得程序可以在运行时修改。</li><li>② <strong>二进制逻辑</strong>:所有数据和指令都以<code>二进制</code>形式表示。</li><li>③ <strong>顺序执行</strong>:指令按照它们在内存中的顺序执行,但可以有条件地改变执行顺序。</li><li>④ <strong>五大部件</strong>:计算机由<code>运算器</code>、<code>控制器</code>、<code>存储器</code>、<code>输入设备</code>和<code>输出设备</code>组成。</li><li>⑤ <strong>指令结构</strong>:指令由操作码和地址码组成,操作码指示要执行的操作,地址码指示操作数的位置。</li><li>⑥ <strong>中心化控制</strong>:计算机的控制单元(CPU)负责解释和执行指令,控制数据流。</li></ul></li><li>所以,再次论证了为什么计算机只能识别二进制。</li></ul><h2 id="_3-2-进制" tabindex="-1">3.2 进制 <a class="header-anchor" href="#_3-2-进制" aria-label="Permalink to "3.2 进制""></a></h2><h3 id="_3-2-1-常见的进制" tabindex="-1">3.2.1 常见的进制 <a class="header-anchor" href="#_3-2-1-常见的进制" aria-label="Permalink to "3.2.1 常见的进制""></a></h3><ul><li>在生活中,我们最为常用的进制就是<code>十进制</code>,其规则是<code>满 10 进 1</code> ,即:</li></ul><p><img src="'+r+`" alt=""></p><ul><li>在计算机中,常见的进制有<code>二进制</code>、<code>八进制</code>和<code>十六进制</code>,即: <ul><li>二进制:只能 0 和 1 ,满 2 进 1 。</li><li>八进制:0 ~ 7 ,满 8 进 1 。</li><li>十六进制:0 ~ 9 以及 A ~ F ,满 16 进 1 。</li></ul></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>在十六进制中,除了 0 到 9 这十个数字之外,还引入了字母,以便表示超过 9 的值。字母 A 对应十进制的 10 ,字母 B 对应十进制的 11 ,以此类推,字母 F 对应十进制的 15。</p></div><ul><li>进制的换算举例,如下所示:</li></ul><table tabindex="0"><thead><tr><th>十进制</th><th>二进制</th><th>八进制</th><th>十六进制</th></tr></thead><tbody><tr><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>2</td><td>10</td><td>2</td><td>2</td></tr><tr><td>3</td><td>11</td><td>3</td><td>3</td></tr><tr><td>4</td><td>100</td><td>4</td><td>4</td></tr><tr><td>5</td><td>101</td><td>5</td><td>5</td></tr><tr><td>6</td><td>110</td><td>6</td><td>6</td></tr><tr><td>7</td><td>111</td><td>7</td><td>7</td></tr><tr><td>8</td><td>1000</td><td>10</td><td>8</td></tr><tr><td>9</td><td>1001</td><td>11</td><td>9</td></tr><tr><td>10</td><td>1010</td><td>12</td><td>a 或 A</td></tr><tr><td>11</td><td>1011</td><td>13</td><td>b 或 B</td></tr><tr><td>12</td><td>1100</td><td>14</td><td>c 或 C</td></tr><tr><td>13</td><td>1101</td><td>15</td><td>d 或 D</td></tr><tr><td>14</td><td>1110</td><td>16</td><td>e 或 E</td></tr><tr><td>15</td><td>1111</td><td>17</td><td>f 或 F</td></tr><tr><td>16</td><td>10000</td><td>20</td><td>10</td></tr><tr><td>...</td><td>...</td><td>...</td><td>...</td></tr></tbody></table><ul><li>二进制和十六进制的关系:十六进制是以 16 为基数的进制系统,16 在二进制中表示为 ( 2^4 ),即:一个十六进制可以表示 4 位二进制。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>十六进制的范围是:0 ~ F (0 ~ 15)对应的二进制数的范围是:0000 ~ 1111 (0 ~ 15)。</p></div><ul><li>每个十六进制数都可以映射到一个唯一的 4 位二进制数,即:</li></ul><table tabindex="0"><thead><tr><th>十六进制</th><th>二进制</th></tr></thead><tbody><tr><td>0</td><td>0000</td></tr><tr><td>1</td><td>0001</td></tr><tr><td>2</td><td>0010</td></tr><tr><td>3</td><td>0011</td></tr><tr><td>4</td><td>0100</td></tr><tr><td>5</td><td>0101</td></tr><tr><td>6</td><td>0110</td></tr><tr><td>7</td><td>0111</td></tr><tr><td>8</td><td>1000</td></tr><tr><td>9</td><td>1001</td></tr><tr><td>A</td><td>1010</td></tr><tr><td>B</td><td>1011</td></tr><tr><td>C</td><td>1100</td></tr><tr><td>D</td><td>1101</td></tr><tr><td>E</td><td>1110</td></tr><tr><td>F</td><td>1111</td></tr></tbody></table><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>由此可见,每个十六进制数字确实由 4 位二进制数表示。</p></div><ul><li>二进制和八进制的关系:八进制是以 8 为基数的进制系统,8 在二进制中表示为 ( 2^3 );即:一个八进制位可以表示 3 个二进制位。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>八进制的范围是:0 ~ 7 对应的二进制数的范围是:000 ~ 111。</p></div><ul><li>每个八进制数位都可以映射到一个唯一的 3 位二进制数,即:</li></ul><table tabindex="0"><thead><tr><th>八进制</th><th>二进制</th></tr></thead><tbody><tr><td>0</td><td>000</td></tr><tr><td>1</td><td>001</td></tr><tr><td>2</td><td>010</td></tr><tr><td>3</td><td>011</td></tr><tr><td>4</td><td>100</td></tr><tr><td>5</td><td>101</td></tr><tr><td>6</td><td>110</td></tr><tr><td>7</td><td>111</td></tr></tbody></table><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>由此可见,每个八进制数字确实由 3 位二进制数表示。</p></div><h3 id="_3-2-2-c-语言中如何表示不同进制的整数" tabindex="-1">3.2.2 C 语言中如何表示不同进制的整数? <a class="header-anchor" href="#_3-2-2-c-语言中如何表示不同进制的整数" aria-label="Permalink to "3.2.2 C 语言中如何表示不同进制的整数?""></a></h3><ul><li><p>规则如下:</p><ul><li>在 C 语言中,如果是<code>二进制</code>(字面常量),则需要在二进制整数前加上 <code>0b</code> 或 <code>0B</code> 。</li><li>在 C 语言中,如果是<code>八进制</code>(字面常量),则需要在八进制整数前加上 <code>0</code> 。</li><li>在 C 语言中,如果是<code>十进制</code>(字面常量),正常数字表示即可。</li><li>在 C 语言中,如果是<code>十六进制</code>(字面常量),则需要在十六进制整数前加上 <code>0x</code>或<code>0X</code> 。</li></ul></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;"> <stdio.h></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;"> num1 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> 0b</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10100110</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;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num2 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> 0</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">717563</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;"> int</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;"> 1000</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;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num4 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> 0x</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">af72</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;">"num1 = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num1);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // num1 = 166</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"num2 = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num2);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // num2 = 237427</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"num3 = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num3);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // num3 = 1000</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"num4 = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num4);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // num4 = 44914</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 "3.2.3 输出格式""></a></h3><ul><li>在 C 语言中,可以使用不同的<code>格式占位符</code>来<code>输出</code>不同<code>进制</code>的整数,如下所示: <ul><li><code>%d</code>:十进制整数。</li><li><code>%o</code> :八进制整数。</li><li><code>%x</code>:十六进制整数。</li><li><code>%#o</code> :显示前缀 <code>0</code> 的八进制整数。</li><li><code>%#x</code> :显示前缀 <code>0x</code> 的十六进制整数。</li><li><code>%#X</code> :显示前缀 <code>0X</code> 的十六进制整数。</li></ul></li></ul><div class="caution custom-block github-alert"><p class="custom-block-title">CAUTION</p><p></p><p>C 语言中没有输出二进制数的格式占位符!!!</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;"> <stdio.h></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;"> 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;">"</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;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num, num);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 100 的十进制整数: 100</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</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;">%o\\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num, num);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 100 的八进制整数: 144</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</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;">%x\\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num, num);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 100 的十六进制整数: 64</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</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;">%#o\\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num, num);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 100 的八进制(前缀)整数: 0144</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</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;">%#x\\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num, num);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 100 的十六进制(前缀)整数: 0x64</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</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;">%#X\\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num, num);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 100 的十六进制(前缀)整数: 0X64</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="_3-3-进制的转换" tabindex="-1">3.3 进制的转换 <a class="header-anchor" href="#_3-3-进制的转换" aria-label="Permalink to "3.3 进制的转换""></a></h2><h3 id="_3-3-1-概述" tabindex="-1">3.3.1 概述 <a class="header-anchor" href="#_3-3-1-概述" aria-label="Permalink to "3.3.1 概述""></a></h3><ul><li>不同进制的转换,如下所示:</li></ul><p><img src="`+c+'" alt=""></p><ul><li>在计算机中,数据是从右往左的方式排列的;其中,最右边的是低位,最左边的是高位,即:</li></ul><p><img src="'+o+'" alt=""></p><h3 id="_3-3-2-二进制和十进制的转换" tabindex="-1">3.3.2 二进制和十进制的转换 <a class="header-anchor" href="#_3-3-2-二进制和十进制的转换" aria-label="Permalink to "3.3.2 二进制和十进制的转换""></a></h3><h4 id="_3-3-2-1-二进制转换为十进制" tabindex="-1">3.3.2.1 二进制转换为十进制 <a class="header-anchor" href="#_3-3-2-1-二进制转换为十进制" aria-label="Permalink to "3.3.2.1 二进制转换为十进制""></a></h4><ul><li>规则:从最低位开始,将每个位上的数提取出来,乘以 2 的 (位数 - 1 )次方,然后求和。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 在学术界,将这种计算规则,称为<code>位权相加法</code>。</li><li>② <code>八进制转换为十进制</code>、<code>十六进制转换为十进制</code>和<code>二进制转换为十进制</code>的算法相同!!!</li></ul></div><ul><li>示例:十进制转十进制</li></ul><p><img src="'+E+'" alt=""></p><ul><li>示例:二进制转十进制</li></ul><p><img src="'+u+'" alt=""></p><h4 id="_3-3-2-2-十进制转换二进制" tabindex="-1">3.3.2.2 十进制转换二进制 <a class="header-anchor" href="#_3-3-2-2-十进制转换二进制" aria-label="Permalink to "3.3.2.2 十进制转换二进制""></a></h4><ul><li>规则:将该数不断除以 2 ,直到商为 0 为止,然后将每步得到的余数倒过来,就是对应的二进制。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 在学术界,将这种计算规则,称为<code>短除法</code>或<code>连续除2取余法</code>。</li><li>② 很好理解,只有不断地除以 2 ,就能保证最大的数字不超过 2 ,这不就是二进制(只能有 0 或 1)吗?</li><li>③ <code>八进制转换为二进制</code>、<code>十六进制转换为二进制</code>和<code>十进制转换为二进制</code>的算法相同!!!</li></ul></div><ul><li>示例:十进制转十进制</li></ul><p><img src="'+b+'" alt=""></p><ul><li>示例:十进制转二进制</li></ul><p><img src="'+g+'" alt=""></p><h3 id="_3-3-3-二进制转八进制" tabindex="-1">3.3.3 二进制转八进制 <a class="header-anchor" href="#_3-3-3-二进制转八进制" aria-label="Permalink to "3.3.3 二进制转八进制""></a></h3><ul><li><p>规则:每 3 位二进制就是一个八进制。</p></li><li><p>示例:011 101 001 -> 351</p></li></ul><p><img src="'+F+'" alt=""></p><h3 id="_3-3-4-二进制转十六进制" tabindex="-1">3.3.4 二进制转十六进制 <a class="header-anchor" href="#_3-3-4-二进制转十六进制" aria-label="Permalink to "3.3.4 二进制转十六进制""></a></h3><ul><li><p>规则:每 4 位二进制就是一个八进制。</p></li><li><p>示例:1110 1001 -> 0xE9</p></li></ul><p><img src="'+y+'" alt=""></p><h2 id="_3-4-原码、反码和补码" tabindex="-1">3.4 原码、反码和补码 <a class="header-anchor" href="#_3-4-原码、反码和补码" aria-label="Permalink to "3.4 原码、反码和补码""></a></h2><h3 id="_3-4-1-概述" tabindex="-1">3.4.1 概述 <a class="header-anchor" href="#_3-4-1-概述" aria-label="Permalink to "3.4.1 概述""></a></h3><ul><li>机器数:一个数在计算机的存储形式是二进制,我们称这些二进制数为机器数。机器数可以是有符号的,用机器数的最高位来存放符号位,0 表示正数,1 表示负数。</li></ul><p><img src="'+m+'" alt=""></p><ul><li>真值:因为机器数带有符号位,所以机器数的形式值不等于其真实表示的值(真值),以机器数 1000 0001 为例,其真正表示的值(首位是符号位)为 -1,而形式值却是 129 ,因此将带有符号位的机器数的真正表示的值称为机器数的真值。</li></ul><p><img src="'+C+'" alt=""></p><h3 id="_3-4-2-原码" tabindex="-1">3.4.2 原码 <a class="header-anchor" href="#_3-4-2-原码" aria-label="Permalink to "3.4.2 原码""></a></h3><ul><li>原码的表示与机器数真值表示的一样,即用第一位表示符号,其余位表示数值。</li><li>规则: <ul><li>正数的<code>原码</code>是它本身对应的二进制数,符号位是 0 。</li><li>负数的<code>原码</code>是它本身绝对值对应的二进制数,但是符号位是 1 。</li></ul></li><li>+1 的原码,使用 8 位二进数来表示,就是:</li></ul><table tabindex="0"><thead><tr><th>十进制数</th><th>原码(8位二进制数)</th></tr></thead><tbody><tr><td>+1</td><td><code>0</code>000 0001</td></tr></tbody></table><ul><li>-1 的原码,使用 8 位二进数来表示,就是:</li></ul><table tabindex="0"><thead><tr><th>十进制数</th><th>原码(8位二进制数)</th></tr></thead><tbody><tr><td>-1</td><td><code>1</code>000 0001</td></tr></tbody></table><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p>按照原码的规则,会出现 <code>+0</code> 和 <code>-0</code> 的情况,即:<code>0</code>000 0000(+0)、<code>1</code>000 0000(-0),显然不符合实际情况;所以,计算机底层虽然存储和计算的都是二进数,但显然不是原码。</p></div><h3 id="_3-4-3-反码" tabindex="-1">3.4.3 反码 <a class="header-anchor" href="#_3-4-3-反码" aria-label="Permalink to "3.4.3 反码""></a></h3><ul><li><p>规则:</p><ul><li>正数的反码和它的原码相同。</li><li>负数的反码是在其原码的基础上,符号位不变,其余各位取反。</li></ul></li><li><p>+1 的反码,使用 8 位二进数来表示,就是:</p></li></ul><table tabindex="0"><thead><tr><th>十进制数</th><th>原码(8位二进制数)</th><th>反码(8位二进制数)</th></tr></thead><tbody><tr><td>+1</td><td><code>0</code>000 0001</td><td><code>0</code>000 0001</td></tr></tbody></table><ul><li>-1 的反码,使用 8 位二进数来表示,就是:</li></ul><table tabindex="0"><thead><tr><th>十进制数</th><th>原码(8位二进制数)</th><th>反码(8位二进制数)</th></tr></thead><tbody><tr><td>-1</td><td><code>1</code>000 0001</td><td><code>1</code>111 1110</td></tr></tbody></table><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p>按照反码的规则,如果是 <code>+0</code>,对应的原码是 <code>0</code>000 0000;那么,其反码还是 <code>0</code>000 0000 ;如果是 <code>-0</code>,对应的原码是 <code>1</code>000 0000,其反码是 <code>1</code>111 1111,显然不符合实际情况;所以,计算机底层虽然存储和计算的都是二进数,但显然不是反码。</p></div><h3 id="_3-4-4-补码" tabindex="-1">3.4.4 补码 <a class="header-anchor" href="#_3-4-4-补码" aria-label="Permalink to "3.4.4 补码""></a></h3><ul><li><p>规则:</p><ul><li>正数的补码和它的原码相同。</li><li>负数的补码是在其反码的基础上 + 1 。</li></ul></li><li><p>+1 的补码,使用 8 位二进数来表示,就是:</p></li></ul><table tabindex="0"><thead><tr><th>十进制数</th><th>原码(8位二进制数)</th><th>反码(8位二进制数)</th><th>补码(8位二进制数)</th></tr></thead><tbody><tr><td>+1</td><td><code>0</code>000 0001</td><td><code>0</code>000 0001</td><td><code>0</code>000 0001</td></tr></tbody></table><ul><li>-1 的补码,使用 8 位二进数来表示,就是:</li></ul><table tabindex="0"><thead><tr><th>十进制数</th><th>原码(8位二进制数)</th><th>反码(8位二进制数)</th><th>补码(8位二进制数)</th></tr></thead><tbody><tr><td>-1</td><td><code>1</code>000 0001</td><td><code>1</code>111 1110</td><td><code>1</code>111 1111</td></tr></tbody></table><ul><li>如果 0 ,按照 <code>+0</code> 的情况进行处理,即:</li></ul><p><img src="'+B+'" alt=""></p><ul><li>如果 0 ,按照 <code>-0</code> 的情况进行处理,即:</li></ul><p><img src="'+v+'" alt=""></p><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li>① 补码表示法解决了<code>原码</code>和<code>反码</code>存在的<code>两种</code>零(<code>+0</code> 和 <code>-0</code>)的问题,即:在补码表示法中,只有<code>一个</code>零,即 0000 0000。</li><li>② 补码使得<code>加法运算</code>和<code>减法运算</code>可以统一处理,通过将减法运算<code>转换</code>为加法运算,可以简化硬件设计,提高了运算效率。</li><li>③ 计算机底层<code>存储</code>和<code>计算</code>的都是<code>二进数的补码</code>。</li></ul></div><h3 id="_3-4-5-总结" tabindex="-1">3.4.5 总结 <a class="header-anchor" href="#_3-4-5-总结" aria-label="Permalink to "3.4.5 总结""></a></h3><ul><li>① 正数的原码、反码和补码都是一样的,三码合一。</li><li>② 负数的反码是在其原码的基础上,按位取反(0 变 1 ,1 变 0 ),符号位不变;负数的补码是其反码 + 1 。</li><li>③ 0 的补码是 0 。</li></ul><h2 id="_3-5-计算机底层为什么使用补码" tabindex="-1">3.5 计算机底层为什么使用补码? <a class="header-anchor" href="#_3-5-计算机底层为什么使用补码" aria-label="Permalink to "3.5 计算机底层为什么使用补码?""></a></h2><ul><li>如果计算是 <code>2 - 2</code> ,那么可以转换为 <code>2 + (-2)</code>,这样计算机内部在处理<code>减法计算</code>的时候,就会将其转换为<code>加法计算</code>的形式,以简化硬件设计和提高计算效率。</li><li><code>最高位</code>表示<code>符号位</code>,由于符号位的存在,如果使用<code>原码</code>来计算,就会导致<code>计算结果不正确</code>,即:</li></ul><p><img src="'+A+'" alt=""></p><ul><li><code>补码</code>的设计可以巧妙的让<code>符号位</code>也参与计算,并且可以得到<code>正确的计算结果</code>,即:</li></ul><p><img src="'+_+'" alt=""></p>',190),f=[q];function x(P,T,N,O,w,I){return a(),i("div",null,f)}const L=s(D,[["render",x]]);export{S as __pageData,L as default};
|
1
assets/notes_01_c-basic_02_xdx_index.md.k6oVENcd.lean.js
Normal file
@ -0,0 +1 @@
|
||||
import{_ as s,c as i,o as a,a5 as n}from"./chunks/framework.D1oHBMsh.js";const l="/coa6/assets/1.CXNJqOOc.png",e="/coa6/assets/2.E0LS08Y5.png",t="/coa6/assets/3.XcPl7d9s.png",p="/coa6/assets/4.DL02VQMp.png",h="/coa6/assets/5.Dr67r_Ws.png",d="/coa6/assets/6.C5XiXNVN.png",k="/coa6/assets/7.DO8XxSV6.jpg",r="/coa6/assets/8.CUXrdefp.jpeg",c="/coa6/assets/9.uqLiL_yu.png",o="/coa6/assets/10.CkykpHY2.png",E="/coa6/assets/11.DV1YbrOP.png",u="/coa6/assets/12.AHNJT9TV.png",b="/coa6/assets/13.Bs-MOwx2.png",g="/coa6/assets/14.StzjmBz-.png",F="/coa6/assets/15.C0wVWaxD.png",y="/coa6/assets/16.LXJMAihe.png",m="/coa6/assets/17._UTCq3PD.png",C="/coa6/assets/18.BjQ5kBL-.png",B="/coa6/assets/19.COIOzcmT.png",v="/coa6/assets/20.Cu__mjav.png",A="/coa6/assets/21.BX_KzkHt.png",_="/coa6/assets/22.COt_QxSP.png",S=JSON.parse('{"title":"第一章:变量(⭐)","description":"","frontmatter":{},"headers":[],"relativePath":"notes/01_c-basic/02_xdx/index.md","filePath":"notes/01_c-basic/02_xdx/index.md","lastUpdated":1720685105000}'),D={name:"notes/01_c-basic/02_xdx/index.md"},q=n("",190),f=[q];function x(P,T,N,O,w,I){return a(),i("div",null,f)}const L=s(D,[["render",x]]);export{S as __pageData,L as default};
|
1
assets/notes_index.md.86O_Lb7b.js
Normal file
@ -0,0 +1 @@
|
||||
import{_ as t,c as a,o as s,j as e,a as o}from"./chunks/framework.D1oHBMsh.js";const B=JSON.parse('{"title":"计算机基础知识","description":"","frontmatter":{},"headers":[],"relativePath":"notes/index.md","filePath":"notes/index.md","lastUpdated":1720685105000}'),n={name:"notes/index.md"},r=e("h1",{id:"计算机基础知识",tabindex:"-1"},[o("计算机基础知识 "),e("a",{class:"header-anchor",href:"#计算机基础知识","aria-label":'Permalink to "计算机基础知识"'},"")],-1),d=e("hr",null,null,-1),c=e("iframe",{src:"https://roadmap.sh/r/embed?id=668c68522c7edd3e44893630",width:"115%",height:"500px",frameBorder:"0"},null,-1),i=[r,d,c];function l(_,h,p,m,f,x){return s(),a("div",null,i)}const $=t(n,[["render",l]]);export{B as __pageData,$ as default};
|
1
assets/notes_index.md.86O_Lb7b.lean.js
Normal file
@ -0,0 +1 @@
|
||||
import{_ as t,c as a,o as s,j as e,a as o}from"./chunks/framework.D1oHBMsh.js";const B=JSON.parse('{"title":"计算机基础知识","description":"","frontmatter":{},"headers":[],"relativePath":"notes/index.md","filePath":"notes/index.md","lastUpdated":1720685105000}'),n={name:"notes/index.md"},r=e("h1",{id:"计算机基础知识",tabindex:"-1"},[o("计算机基础知识 "),e("a",{class:"header-anchor",href:"#计算机基础知识","aria-label":'Permalink to "计算机基础知识"'},"")],-1),d=e("hr",null,null,-1),c=e("iframe",{src:"https://roadmap.sh/r/embed?id=668c68522c7edd3e44893630",width:"115%",height:"500px",frameBorder:"0"},null,-1),i=[r,d,c];function l(_,h,p,m,f,x){return s(),a("div",null,i)}const $=t(n,[["render",l]]);export{B as __pageData,$ as default};
|
1
assets/style.93t0OQ_p.css
Normal file
BIN
favicon.ico
Normal file
After Width: | Height: | Size: 4.2 KiB |
1
hashmap.json
Normal file
@ -0,0 +1 @@
|
||||
{"notes_index.md":"86O_Lb7b","index.md":"LKQAh9T8","notes_01_c-basic_02_xdx_index.md":"k6oVENcd","notes_01_c-basic_01_xdx_index.md":"D1hb9NAd"}
|
27
index.html
Normal file
@ -0,0 +1,27 @@
|
||||
<!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.2.3">
|
||||
<link rel="preload stylesheet" href="/coa6/assets/style.93t0OQ_p.css" as="style">
|
||||
|
||||
<script type="module" src="/coa6/assets/app.BmFonQgT.js"></script>
|
||||
<link rel="preload" href="/coa6/assets/inter-roman-latin.Di8DUHzh.woff2" as="font" type="font/woff2" crossorigin="">
|
||||
<link rel="modulepreload" href="/coa6/assets/chunks/framework.D1oHBMsh.js">
|
||||
<link rel="modulepreload" href="/coa6/assets/chunks/theme.DstJSxiY.js">
|
||||
<link rel="modulepreload" href="/coa6/assets/index.md.LKQAh9T8.lean.js">
|
||||
<link rel="shortcut icon" href="/coa6//favicon.ico">
|
||||
<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">
|
||||
<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>
|
||||
<meta name="keywords" content="许大仙,许大仙的博客">
|
||||
</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-ccf7ddec><div class="wrapper" data-v-ccf7ddec><div class="container" data-v-ccf7ddec><div class="title" data-v-ccf7ddec><div class="VPNavBarTitle" data-v-ccf7ddec data-v-ab179fa1><a class="title" href="/coa6/" data-v-ab179fa1><!--[--><!--]--><!--[--><img class="VPImage logo" src="/coa6/logo.svg" alt data-v-8426fc1a><!--]--><span data-v-ab179fa1>许大仙</span><!--[--><!--]--></a></div></div><div class="content" data-v-ccf7ddec><div class="content-body" data-v-ccf7ddec><!--[--><!--]--><div class="VPNavBarSearch search" data-v-ccf7ddec><!--[--><!----><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-ccf7ddec data-v-7f418b0f><span id="main-nav-aria-label" class="visually-hidden" data-v-7f418b0f>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-7f418b0f 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-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>计组6件套</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/coa6/notes/" tabindex="0" data-v-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>c/c++</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/web-design/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>前端</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/java/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>Java</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/big-data/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>大数据</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/linux/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-7f418b0f 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-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>开源软件</span><!--]--></a><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-ccf7ddec data-v-e6aabb21><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-e6aabb21 data-v-d1f28634 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-d1f28634></span><span class="vpi-moon moon" data-v-d1f28634></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-ccf7ddec 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-ccf7ddec data-v-d0bd9dde 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-e7ea1737><!----><!--[--><!--[--><!----><div class="group" data-v-d0bd9dde><div class="item appearance" data-v-d0bd9dde><p class="label" data-v-d0bd9dde>Appearance</p><div class="appearance-action" data-v-d0bd9dde><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-d0bd9dde data-v-d1f28634 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-d1f28634></span><span class="vpi-moon moon" data-v-d1f28634></span><!--]--></span></span></button></div></div></div><div class="group" data-v-d0bd9dde><div class="item social-links" data-v-d0bd9dde><div class="VPSocialLinks social-links-list" data-v-d0bd9dde 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-ccf7ddec 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-ccf7ddec><div class="divider-line" data-v-ccf7ddec></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 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="/coa6/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/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="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><!--[--><!--]--></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><!----><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><!----><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><!----><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("{\"notes_index.md\":\"86O_Lb7b\",\"index.md\":\"LKQAh9T8\",\"notes_01_c-basic_02_xdx_index.md\":\"k6oVENcd\",\"notes_01_c-basic_01_xdx_index.md\":\"D1hb9NAd\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"zh-CN\",\"dir\":\"ltr\",\"title\":\"许大仙\",\"titleTemplate\":\"Hi,终于等到你\",\"description\":\"许大仙前端、Java、大数据、云原生\",\"base\":\"/coa6/\",\"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\":\"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\":\"开源软件\",\"link\":\"https://aexiar.github.io/open-software/notes/\"}],\"sidebar\":{\"/notes/\":[{\"text\":\"C语言基础\",\"collapsed\":true,\"items\":[{\"text\":\"C 语言入门\",\"link\":\"/notes/01_c-basic/01_xdx/\"},{\"text\":\"变量和进制\",\"link\":\"/notes/01_c-basic/02_xdx/\"}]},{\"text\":\"C 语言高级\",\"collapsed\":true,\"items\":[{\"text\":\"初识 C 语言\",\"link\":\"/notes/02_dsa/01_xdx/\"}]},{\"text\":\"C++ 核心编程\",\"collapsed\":true,\"items\":[{\"text\":\"计算机组成原理前言\",\"link\":\"/notes/03_coa/03_xdx/\"}]},{\"text\":\"QT 桌面开发\",\"collapsed\":true,\"items\":[{\"text\":\"操作系统前言\",\"link\":\"/notes/04_os/01_xdx/\"}]},{\"text\":\"Linux 高并发服务器开发\",\"collapsed\":true,\"items\":[{\"text\":\"操作系统前言\",\"link\":\"/notes/04_os/01_xdx/\"}]}]},\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/Aurorxa\"}],\"docFooter\":{\"prev\":\"上一篇\",\"next\":\"下一篇\"},\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2024 许大仙\"},\"outline\":{\"level\":[1,6],\"label\":\"目录\"},\"outlineTitle\":\"当前页大纲\"},\"locales\":{},\"scrollOffset\":134,\"cleanUrls\":false}");</script>
|
||||
|
||||
</body>
|
||||
</html>
|
1
logo.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 261.76 226.69"><path d="M161.096.001l-30.225 52.351L100.647.001H-.005l130.877 226.688L261.749.001z" fill="#41b883"/><path d="M161.096.001l-30.225 52.351L100.647.001H52.346l78.526 136.01L209.398.001z" fill="#34495e"/></svg>
|
After Width: | Height: | Size: 276 B |
252
notes/01_c-basic/01_xdx/index.html
Normal file
@ -0,0 +1,252 @@
|
||||
<!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.2.3">
|
||||
<link rel="preload stylesheet" href="/coa6/assets/style.93t0OQ_p.css" as="style">
|
||||
|
||||
<script type="module" src="/coa6/assets/app.BmFonQgT.js"></script>
|
||||
<link rel="preload" href="/coa6/assets/inter-roman-latin.Di8DUHzh.woff2" as="font" type="font/woff2" crossorigin="">
|
||||
<link rel="modulepreload" href="/coa6/assets/chunks/framework.D1oHBMsh.js">
|
||||
<link rel="modulepreload" href="/coa6/assets/chunks/theme.DstJSxiY.js">
|
||||
<link rel="modulepreload" href="/coa6/assets/notes_01_c-basic_01_xdx_index.md.D1hb9NAd.lean.js">
|
||||
<link rel="shortcut icon" href="/coa6//favicon.ico">
|
||||
<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-ccf7ddec><div class="wrapper" data-v-ccf7ddec><div class="container" data-v-ccf7ddec><div class="title" data-v-ccf7ddec><div class="VPNavBarTitle has-sidebar" data-v-ccf7ddec data-v-ab179fa1><a class="title" href="/coa6/" data-v-ab179fa1><!--[--><!--]--><!--[--><img class="VPImage logo" src="/coa6/logo.svg" alt data-v-8426fc1a><!--]--><span data-v-ab179fa1>许大仙</span><!--[--><!--]--></a></div></div><div class="content" data-v-ccf7ddec><div class="content-body" data-v-ccf7ddec><!--[--><!--]--><div class="VPNavBarSearch search" data-v-ccf7ddec><!--[--><!----><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-ccf7ddec data-v-7f418b0f><span id="main-nav-aria-label" class="visually-hidden" data-v-7f418b0f>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-7f418b0f 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-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>计组6件套</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/coa6/notes/" tabindex="0" data-v-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>c/c++</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/web-design/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>前端</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/java/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>Java</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/big-data/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>大数据</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/linux/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-7f418b0f 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-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>开源软件</span><!--]--></a><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-ccf7ddec data-v-e6aabb21><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-e6aabb21 data-v-d1f28634 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-d1f28634></span><span class="vpi-moon moon" data-v-d1f28634></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-ccf7ddec 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-ccf7ddec data-v-d0bd9dde 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-e7ea1737><!----><!--[--><!--[--><!----><div class="group" data-v-d0bd9dde><div class="item appearance" data-v-d0bd9dde><p class="label" data-v-d0bd9dde>Appearance</p><div class="appearance-action" data-v-d0bd9dde><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-d0bd9dde data-v-d1f28634 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-d1f28634></span><span class="vpi-moon moon" data-v-d1f28634></span><!--]--></span></span></button></div></div></div><div class="group" data-v-d0bd9dde><div class="item social-links" data-v-d0bd9dde><div class="VPSocialLinks social-links-list" data-v-d0bd9dde 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-ccf7ddec 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-ccf7ddec><div class="divider-line" data-v-ccf7ddec></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-575e6a36><div class="curtain" data-v-575e6a36></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-575e6a36><span class="visually-hidden" id="sidebar-aria-label" data-v-575e6a36> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="group" data-v-575e6a36><section class="VPSidebarItem level-0 collapsible has-active" data-v-575e6a36 data-v-b8d55f3b><div class="item" role="button" tabindex="0" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><h2 class="text" data-v-b8d55f3b>C语言基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b8d55f3b><span class="vpi-chevron-right caret-icon" data-v-b8d55f3b></span></div></div><div class="items" data-v-b8d55f3b><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/coa6/notes/01_c-basic/01_xdx/" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>C 语言入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/coa6/notes/01_c-basic/02_xdx/" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>变量和进制</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-575e6a36><section class="VPSidebarItem level-0 collapsible collapsed" data-v-575e6a36 data-v-b8d55f3b><div class="item" role="button" tabindex="0" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><h2 class="text" data-v-b8d55f3b>C 语言高级</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b8d55f3b><span class="vpi-chevron-right caret-icon" data-v-b8d55f3b></span></div></div><div class="items" data-v-b8d55f3b><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/coa6/notes/02_dsa/01_xdx/" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>初识 C 语言</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-575e6a36><section class="VPSidebarItem level-0 collapsible collapsed" data-v-575e6a36 data-v-b8d55f3b><div class="item" role="button" tabindex="0" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><h2 class="text" data-v-b8d55f3b>C++ 核心编程</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b8d55f3b><span class="vpi-chevron-right caret-icon" data-v-b8d55f3b></span></div></div><div class="items" data-v-b8d55f3b><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/coa6/notes/03_coa/03_xdx/" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>计算机组成原理前言</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-575e6a36><section class="VPSidebarItem level-0 collapsible collapsed" data-v-575e6a36 data-v-b8d55f3b><div class="item" role="button" tabindex="0" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><h2 class="text" data-v-b8d55f3b>QT 桌面开发</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b8d55f3b><span class="vpi-chevron-right caret-icon" data-v-b8d55f3b></span></div></div><div class="items" data-v-b8d55f3b><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/coa6/notes/04_os/01_xdx/" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>操作系统前言</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-575e6a36><section class="VPSidebarItem level-0 collapsible collapsed" data-v-575e6a36 data-v-b8d55f3b><div class="item" role="button" tabindex="0" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><h2 class="text" data-v-b8d55f3b>Linux 高并发服务器开发</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b8d55f3b><span class="vpi-chevron-right caret-icon" data-v-b8d55f3b></span></div></div><div class="items" data-v-b8d55f3b><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/coa6/notes/04_os/01_xdx/" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>操作系统前言</p><!--]--></a><!----></div><!----></div><!--]--></div></section></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 _coa6_notes_01_c-basic_01_xdx_" data-v-39a288b8><div><h1 id="第一章-计算机组成原理" tabindex="-1">第一章:计算机组成原理 <a class="header-anchor" href="#第一章-计算机组成原理" aria-label="Permalink to "第一章:计算机组成原理""></a></h1><h2 id="_1-1-计算机系统" tabindex="-1">1.1 计算机系统 <a class="header-anchor" href="#_1-1-计算机系统" aria-label="Permalink to "1.1 计算机系统""></a></h2><ul><li>计算机(Computer),俗称<code>"电脑"</code>,是一种能够接收和存储信息,并按照存储在其内部的程序对海量的数据进行自动、高速的处理,然后将处理结果输出的现代化智能电子设备。</li><li>计算机有很多形式,如:台式电脑、笔记本电脑、智能手机、平板电脑等,还有生产环境中提供重要业务支撑的各种服务器。</li></ul><p><img src="/coa6/assets/1.D4a42fT1.jpg" alt=""></p><ul><li>一个完整的<code>计算机系统</code>由<code>硬件(Hardware)系统</code>和<code>软件(Software)系统</code>两大部分组成,即:</li></ul><p><img src="/coa6/assets/2.D2wnxl5F.png" alt=""></p><h2 id="_1-2-冯·诺依曼体系结构" tabindex="-1">1.2 冯·诺依曼体系结构 <a class="header-anchor" href="#_1-2-冯·诺依曼体系结构" aria-label="Permalink to "1.2 冯·诺依曼体系结构""></a></h2><ul><li><code>冯·诺依曼</code>是一位多才多艺的科学家,他在数学、物理学、计算机科学、经济学等领域都有杰出的贡献。</li></ul><p><img src="/coa6/assets/3.Dq625oo9.jpg" alt=""></p><ul><li><code>冯·诺依曼</code>的主要成就: <ul><li>在计算机科学领域的最著名贡献是提出了<code>冯·诺依曼</code>体系结构(1946 年),这是<code>现代计算机设计的基础</code>。</li><li>促进了计算机的可编程性和通用性,使得计算机能够执行各种复杂的任务。</li><li>对核武器设计、自动化控制系统、人工智能等领域的发展产生了重要影响。</li><li>……</li></ul></li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p><code>冯·诺依曼体系结构</code>是现代计算机(量子计算机除外)设计的<code>基础</code>。</p></div><ul><li><p><code>冯·诺依曼</code>体系结构的理论要点如下:</p><ul><li><p>① <strong>存储程序</strong>:<code>程序指令</code>和<code>数据</code>都存储在计算机的内存中,这使得程序可以在运行时修改。</p></li><li><p>② <strong>二进制逻辑</strong>:所有<code>数据</code>和<code>指令</code>都以<code>二进制</code>形式表示。</p></li><li><p>③ <strong>顺序执行</strong>:指令按照它们在内存中的顺序执行,但可以有条件地改变执行顺序。</p></li><li><p>④ <strong>五大部件</strong>:计算机由<code>运算器</code>、<code>控制器</code>、<code>存储器</code>、<code>输入设备</code>和<code>输出设备</code>组成。</p></li><li><p>⑤ <strong>指令结构</strong>:指令由操作码和地址码组成,操作码指示要执行的操作,地址码指示操作数的位置。</p></li><li><p>⑥ <strong>中心化控制</strong>:计算机的控制单元(CPU)负责解释和执行指令,控制数据流。</p></li></ul></li></ul><p><img src="/coa6/assets/4.uqu1DEK4.png" alt=""></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>上述的组件协同工作,构成了一个完整的计算机系统:</p><ul><li><strong>运算器</strong>和<strong>控制器</strong>通常被集成在一起,组成中央处理器(CPU),负责数据处理和指令执行。</li><li><strong>存储器</strong>保存数据和程序,是计算机运作的基础。</li><li><strong>输入设备</strong>和<strong>输出设备</strong>负责与外界的交互,确保用户能够输入信息并接收计算机的处理结果。</li></ul></div><h2 id="_1-3-各种硬件处理速度和性能优化" tabindex="-1">1.3 各种硬件处理速度和性能优化 <a class="header-anchor" href="#_1-3-各种硬件处理速度和性能优化" aria-label="Permalink to "1.3 各种硬件处理速度和性能优化""></a></h2><ul><li>计算机的性能短板:如果 CPU 有每秒处理 1000 个服务请求的能力,各种总线的负载能力能达到 500 个, 但网卡只能接受 200个请求,而硬盘只能负担 150 个的话,那这台服务器得处理能力只能是 150 个请求/ 秒,有 85% 的处理器计算能力浪费了,在计算机系统当中,<code>硬盘</code>的读写速率已经成为影响系统性能进一 步提高的瓶颈。</li></ul><p><img src="/coa6/assets/5.C6Q0Q8kf.jpg" alt="img"></p><ul><li>计算机的各个设备部件的延迟从高到低的排列,依次是机械硬盘(HDD)、固态硬盘(SSD)、内存、CPU 。</li></ul><p><img src="/coa6/assets/6.B4Srsb-0.png" alt="img"></p><ul><li>从上图中,我们可以知道,CPU 是最快的,一个时钟周期是 0.3 ns ,内存访问需要 120 ns ,固态硬盘访问需要 50-150 us,传统的硬盘访问需要 1-10 ms,而网络访问是最慢,需要 40 ms 以上。</li><li>时间的单位换算如下:</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>1 秒 = 1000 毫秒,即 1 s = 1000 ms。</span></span>
|
||||
<span class="line"><span>1 毫秒 = 1000 微妙,即 1 ms = 1000 us 。</span></span>
|
||||
<span class="line"><span>1 微妙 = 1000 纳秒,即 1 us = 1000 ns。</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-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>如果 CPU 的时钟周期按照 1 秒计算,</span></span>
|
||||
<span class="line"><span>那么,内存访问就需要 6 分钟;</span></span>
|
||||
<span class="line"><span>那么,固态硬盘就需要 2-6 天;</span></span>
|
||||
<span class="line"><span>那么,传统硬盘就需要 1-12 个月;</span></span>
|
||||
<span class="line"><span>那么,网络访问就需要 4 年以上。</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>所以,对于 CPU 来说,这个世界真的是太慢了!!!</li><li>其实,中国古代中的文人,通常以<code>蜉蝣</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>鹤寿千岁,以极其游,蜉蝣朝生而暮死,尽其乐,盖其旦暮为期,远不过三日尔。</span></span>
|
||||
<span class="line"><span> --- 出自 西汉淮南王刘安《淮南子》</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><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>寄蜉蝣于天地,渺沧海之一粟。 哀吾生之须臾,羡长江之无穷。 </span></span>
|
||||
<span class="line"><span>挟飞仙以遨游,抱明月而长终。 知不可乎骤得,托遗响于悲风。</span></span>
|
||||
<span class="line"><span> --- 出自 苏轼《赤壁赋》</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><p>对于<code>蜉蝣</code>来说,从早到晚就是一生;而对于我们<code>人类</code>而言,却仅仅只是一天。</p></div><ul><li>存储器的层次结构(CPU 中也有存储器,即:寄存器、高速缓存 L1、L2 和 L3),如下所示:</li></ul><p><img src="/coa6/assets/7._D_c8Lrn.png" alt="img"></p><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><h2 id="_1-4-计算机软件" tabindex="-1">1.4 计算机软件 <a class="header-anchor" href="#_1-4-计算机软件" aria-label="Permalink to "1.4 计算机软件""></a></h2><h3 id="_1-4-1-操作系统的来源" tabindex="-1">1.4.1 操作系统的来源 <a class="header-anchor" href="#_1-4-1-操作系统的来源" aria-label="Permalink to "1.4.1 操作系统的来源""></a></h3><ul><li>在上古时期,硬件资源不够丰富,计算机设计的也非常简陋。那个时候,很多应用程序都是直接跑在硬件上的,即:一个计算机只能跑一个应用程序。</li></ul><p><img src="/coa6/assets/8.DlIyFGDg.png" alt=""></p><ul><li>随着技术的发展,硬件越来越丰富,功能也越来越强大,性能也越来越好。这种情况下,如果一台计算机只能跑一个程序,实在是太浪费了。而且,底层硬件不断丰富,应用程序需要对接的硬件也将越来越多,如果每个应用程序都这么干,不显示工作很重复吗?于是,操作系统应运而生了。</li></ul><p><img src="/coa6/assets/9.7zkUmpQw.png" alt=""></p><ul><li>操作系统的功能: <ul><li>硬件驱动。</li><li>进程管理。</li><li>内存管理。</li><li>网络管理。</li><li>安全管理。</li><li>文件管理。</li></ul></li></ul><ul><li>那么,操作系统的作用,就是这样的,即: <ul><li>对下,管理计算机的硬件资源。</li><li>对上,提供使用计算机资源的操作方式,有: <ul><li><code>系统调用</code>:是一套已经写好的代码接口,应用程序通过调用这些接口来请求操作系统执行特定的硬件操作。它们直接与硬件交互,提供底层功能支持,如:文件操作、进程管理、内存管理等。<code>开发者</code>通过系统调用可以实现对底层资源的直接控制,确保程序能够高效、安全地运行。</li><li><code>终端命令</code>:是一种文本命令接口,通过命令行输入各种指令来控制操作系统和软件的行为。终端命令可以执行文件操作、系统配置、网络管理等各种任务。主要针对<code>开发人员</code>和<code>高级用户</code>,他们通过命令行可以快速、精确地完成各种操作,提高工作效率。</li><li><code>图形用户界面</code>(GUI)是通过图形元素(如:窗口、图标、按钮等)与用户进行交互的界面。供直观、易用的操作方式,使用户能够通过鼠标点击、拖拽等简单操作完成复杂任务。主要面向<code>普通用户</code>,降低了计算机操作的门槛,提高了用户体验和工作效率。</li></ul></li></ul></li></ul><p><img src="/coa6/assets/10.h1ugtjyX.png" alt=""></p><h3 id="_1-4-2-用户态和内核态" tabindex="-1">1.4.2 用户态和内核态 <a class="header-anchor" href="#_1-4-2-用户态和内核态" aria-label="Permalink to "1.4.2 用户态和内核态""></a></h3><ul><li>在现代操作系统中,<code>用户态(User Mode)</code>和<code>内核态(Kernel Mode)</code>是两种不同的执行模式,它们对系统资源的访问权限有着本质的区别。这种区分是为了提供一个稳定和安全的运行环境,防止用户程序直接操作硬件设备和关键的系统资源,从而可能引起系统的不稳定或安全问题。</li></ul><p><img src="/coa6/assets/11.D5PWTabw.png" alt=""></p><ul><li>核态(Kernel Mode) VS 用户态(User Mode):</li></ul><table tabindex="0"><thead><tr><th style="text-align:left;">类型</th><th style="text-align:left;">内核态(Kernel Mode)</th><th style="text-align:left;">用户态(User Mode)</th></tr></thead><tbody><tr><td style="text-align:left;">权限</td><td style="text-align:left;">内核态是操作系统代码运行的模式,拥有访问系统全部资源和执行硬件操作的<code>最高权限</code>。在这种模式下,操作系统的核心部分可以直接访问内存、硬件设备控制、管理文件系统和网络通信等。</td><td style="text-align:left;">用户态是普通应用程序运行的模式,具有<code>较低</code>的系统资源访问权限。在用户态,程序不能直接执行硬件操作,必须通过操作系统提供的接口(即系统调用)来请求服务。</td></tr><tr><td style="text-align:left;">安全性</td><td style="text-align:left;">由于内核态具有如此高的权限,因此只有可信的、经过严格审查的操作系统核心组件才被允许在此模式下运行。这样可以保护系统不被恶意软件破坏。</td><td style="text-align:left;">用户态为系统提供了一层保护,确保用户程序不能直接访问关键的系统资源,防止系统崩溃和数据泄露。</td></tr><tr><td style="text-align:left;">功能</td><td style="text-align:left;">内核态提供了<code>系统调用</code>的接口,允许用户态程序安全地请求使用操作系统提供的服务,比如:文件操作、网络通信、内存管理等。</td><td style="text-align:left;">用户态保证了操作系统的稳定性和安全性,同时也使得多个程序可以在相互隔离的环境中同时运行,避免相互干扰。</td></tr></tbody></table><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 操作系统通过用户态和内核态的分离,实现了对系统资源的保护和控制。</li><li>② 当用户程序需要进行文件读写、网络通信或其他需要操作系统介入的操作时,会发生从用户态到内核态的切换。这通过系统调用(System Call)实现,系统调用是用户程序与操作系统内核通信的桥梁。</li><li>③ 执行完毕后,系统从内核态返回用户态,继续执行用户程序。</li><li>④ 用户态和内核态的这种分离设计是现代操作系统中实现安全、稳定运行的关键机制之一。</li></ul></div><ul><li>示例:</li></ul><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;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> java.io.IOException;</span></span>
|
||||
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> java.nio.file.Files;</span></span>
|
||||
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> java.nio.file.Path;</span></span>
|
||||
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> java.nio.file.Paths;</span></span>
|
||||
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> java.util.List;</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;"> Demo</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;"> writeFile</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(String </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">filePath</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, String </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">content</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
|
||||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Path path </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Paths.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">get</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(filePath);</span></span>
|
||||
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> try</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
|
||||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Files.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">write</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(path, content.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">getBytes</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;">catch</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (IOException </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">e</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
|
||||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> e.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">printStackTrace</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;"> 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:#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 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;"> b </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 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;"> c </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> a </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> b; </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 用户态</span></span>
|
||||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> string filePath </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "c:/demo.txt"</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;"> string txt </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> a </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> b </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> c; </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;"> writeFile</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(filePath, a); </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;"> System.out.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">println</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(a); </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 从内核态切换回用户态</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;">(b); </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 用户态</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;">(c); </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></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><h3 id="_1-4-3-isa、abi-和-api" tabindex="-1">1.4.3 ISA、ABI 和 API <a class="header-anchor" href="#_1-4-3-isa、abi-和-api" aria-label="Permalink to "1.4.3 ISA、ABI 和 API""></a></h3><ul><li>ISA 、ABI 和 API 的参考模型如下:</li></ul><p><img src="/coa6/assets/12.Bvs6QYjl.jpg" alt=""></p><ul><li>在底层,硬件模型以指令集架构 (ISA) 表示,该架构定义了处理器、寄存器、存储器和中断管理的指令集。ISA 是硬件和软件之间的接口,对于操作系统 (OS) 开发人员 (System ISA) 和直接管理底层硬件的应用程序 (User ISA) 的开发人员来说非常重要。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① ISA 是计算机体系结构中定义的一组指令,它规定了处理器能够执行的操作。ISA 包括指令的编码、寄存器的使用、内存访问模式等。不同的处理器可能有不同的 ISA,例如:x86、ARM、MIPS 等。</li><li>② 在设计一个新的操作系统时,开发者需要确保操作系统能够支持特定的 ISA ,以便在特定的硬件上运行。例如:如果操作系统旨在运行在 ARM 架构的处理器上,那么它必须能够理解和执行 ARM ISA 定义的指令集。</li></ul></div><ul><li>应用程序二进制接口 (ABI) 将<code>操作系统层</code>与由操作系统管理的<code>应用程序</code>和<code>库</code>分开。ABI 涵盖了低级数据类型、对齐方式和调用约定等详细信息,并定义了可执行程序的格式。系统调用在此级别定义。此接口允许应用程序和库在实现相同 ABI 的操作系统之间移植。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① ABI 是指在二进制级别上,应用程序与操作系统、库或应用程序的不同部分之间的接口。它定义了数据类型的大小、布局、对齐方式,以及函数调用的约定(如参数如何传递、返回值如何处理等)。ABI 确保了编译后的二进制文件能够在特定的操作系统和硬件平台上正确地运行。</li><li>② 在 windows 上的应用程序的运行格式是:<code>PE</code>(portable executable)格式、<code>.dll</code> (dynamic link library)格式和 <code>.lib</code> 格式;而在 Linux 上的应用程序的运行格式是:<code>ELF</code>(executable and linking format)格式、<code>.so</code> (shared object)格式和 <code>.a</code> 格式。</li><li>③ 在 Linux 中可以通过 <code>file /bin/ls</code> 命令查看指定可执行应用程序的 ABI 格式;从而也可以论证,在 Windows 上可以运行的程序,在 Linux 上运行不了。</li><li>④ 当开发者在 Linux 系统上编写 C 语言程序,并使用特定的编译器(如:GCC)编译时,编译器会遵循 Linux 平台的 ABI 规范来生成二进制文件。这样,生成的可执行文件就可以在任何遵循相同 ABI 规范的 Linux 系统上运行。</li><li>⑤ 如果一个应用程序需要跨平台(操作系统)运行,就需要使用<code>一套代码,多平台编译</code>的方式(针对 C 或 C++ 等),即:相同的源代码,在不同平台(操作系统)上使用特定平台的编译器(如:GCC)来分别编译成符合自己平台的 ABI 规范的二进制文件。</li></ul></div><ul><li>最高级别的抽象由应用程序编程接口 (API) 表示,它将<code>应用程序</code>连接到<code>库</code>或<code>底层操作系统</code>。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① API 是一组预定义的函数、协议和工具,用于构建软件和应用程序。API 允许不同的软件系统相互交互,它定义了软件组件之间如何相互通信。API 可以是库、框架、协议或服务。</li><li>② 在 Web 开发中,开发者可能会使用 JavaScript 的 Fetch API 来与服务器进行通信,获取数据或提交表单。这个 API 提供了一种标准化的方式来发送 HTTP 请求和处理响应,而不需要开发者关心底层的网络协议细节。</li></ul></div><h3 id="_1-4-4-系统调用-system-call-和函数库-library-call" tabindex="-1">1.4.4 系统调用(System Call)和函数库(Library Call) <a class="header-anchor" href="#_1-4-4-系统调用-system-call-和函数库-library-call" aria-label="Permalink to "1.4.4 系统调用(System Call)和函数库(Library Call)""></a></h3><ul><li>在现代操作系统中,应用程序都不能直接作用于硬件,而是运行在操作系统之上。</li></ul><p><img src="/coa6/assets/9.7zkUmpQw.png" alt=""></p><ul><li>并且,在上文的图示中,我们也会看到<code>系统调用(System Call)</code>和<code>函数库(Library Call)</code>的身影,如下:</li></ul><p><img src="/coa6/assets/14.CsR5exrN.png" alt=""></p><p><img src="/coa6/assets/15.BRG9GQdT.png" alt=""></p><ul><li>其实,<code>系统调用(System Call)</code>和<code>函数库(Library Call)</code>的区别如下:</li></ul><table tabindex="0"><thead><tr><th style="text-align:left;">类型</th><th style="text-align:left;">系统调用(System Call)</th><th style="text-align:left;">函数库(Library Call)</th></tr></thead><tbody><tr><td style="text-align:left;">定义</td><td style="text-align:left;">系统调用是操作系统提供给程序员的一组接口,这些接口允许用户空间的程序请求操作系统内核提供的服务,比如文件操作、进程控制、通信和内存管理等。</td><td style="text-align:left;">函数库调用是指使用高级语言编写的一组预先编译好的函数,这些函数实现了一些常用的功能,比如:字符串处理、数学计算等。程序员可以在自己的程序中直接调用这些函数,而无需重新实现它们。</td></tr><tr><td style="text-align:left;">权限</td><td style="text-align:left;">执行系统调用时,会从用户态切换到内核态。这是因为系统调用涉及到访问受保护的系统资源,这些操作必须由操作系统控制以确保系统的稳定性和安全性。</td><td style="text-align:left;">函数库调用通常在用户态执行,不涉及到用户态与内核态之间的切换。它们直接使用操作系统通过系统调用提供的服务,或者完全在用户空间内完成计算,不需要操作系统介入。</td></tr><tr><td style="text-align:left;">性能开销</td><td style="text-align:left;">由于涉及到用户态与内核态之间的切换,系统调用的执行成本相对较高。因此,频繁的系统调用可能会影响程序的性能。</td><td style="text-align:left;">相对于系统调用,函数库调用的性能开销较小。因为它们通常不涉及到模式切换,且执行的操作多在用户空间完成。</td></tr><tr><td style="text-align:left;">示例</td><td style="text-align:left;">open(),read(),write(),fork(),exec() 等 UNIX/Linux 系统调用。</td><td style="text-align:left;">C 标准库中的 printf() 等函数;数学库中的 sin(),cos() 等函数。</td></tr></tbody></table><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① <strong>执行层级</strong>:系统调用直接与操作系统内核交互,执行更底层的操作;而函数库调用运行在用户空间,通常使用系统调用来实现其功能。</li><li>② <strong>性能开销</strong>:系统调用由于涉及到用户态与内核态的切换,性能开销相对较大;函数库调用则因为主要在用户态执行,性能开销较小。</li><li>③ <strong>使用目的</strong>:系统调用提供了访问操作系统资源和服务的能力;函数库调用则提供了方便、高效执行常见任务的手段。</li></ul></div><h1 id="第二章-初识计算机语言" tabindex="-1">第二章:初识计算机语言 <a class="header-anchor" href="#第二章-初识计算机语言" aria-label="Permalink to "第二章:初识计算机语言""></a></h1><h2 id="_2-1-计算机语言是什么" tabindex="-1">2.1 计算机语言是什么? <a class="header-anchor" href="#_2-1-计算机语言是什么" aria-label="Permalink to "2.1 计算机语言是什么?""></a></h2><ul><li><code>人类语言</code>是人和人之间用于沟通的一种方式,例如:中国人和中国人之间使用普通话沟通,而中国人和美国人交流,则可以使用英语。</li><li><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、C++、Java、Go、JavaScript、Python、Scala 等。</p></div><h2 id="_2-2-为什么要学习计算机语言" tabindex="-1">2.2 为什么要学习计算机语言? <a class="header-anchor" href="#_2-2-为什么要学习计算机语言" aria-label="Permalink to "2.2 为什么要学习计算机语言?""></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;"> <stdio.h></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;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</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;">"你好,世界!!!"</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 style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 函数执行完毕时返回函数值0</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></div></div><ul><li>编程语言就是用于控制计算机,让其完成我们需要的功能。而我们学习编程语言,其实就是学习这些文字和符号编写的规则。</li><li>因为 CPU 只能识别二进制的指令,而我们<code>编写</code>的程序叫做<code>源代码</code>,是人类能看懂;但是,计算机却不能识别。那么,我们就需要让计算机能识别我们编写的源程序,就需要将我们编写的源代码交给编译器程序,其会帮助我们将所编写的源代码转换为计算机能够识别的二进制指令。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>编译器就是运行在操作系统之上的程序,其作用就是用来将程序员编写的源代码转换为计算机能够识别的二进制指令。</p></div><ul><li>如果我们用 Java 语言编写了程序(源代码),那么编写的程序也是不能直接运行的,需要通过 Java 语言的编译器将 Java 程序编译为计算机能够识别的二进制指令。</li><li>如果我们用 Python 语言编写了程序(源代码),那么编写的程序也是不能直接运行的,需要通过 Python 语言的编译器将 Python 程序编译为计算机能够识别的二进制指令。</li><li>……</li><li>总而言之,无论我们学习任何一门编程语言,想要将程序运行起来,都必须做如下的两件事情: <ul><li>① 学习该语言的文字和符号编写的规则,即:<code>语法规则</code>。</li><li>② 需要在操作系统上安装对应编程语言的<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 "2.3 计算机语言简史""></a></h2><h3 id="_2-3-1-机器语言-相当于人类的石器时代" tabindex="-1">2.3.1 机器语言(相当于人类的石器时代) <a class="header-anchor" href="#_2-3-1-机器语言-相当于人类的石器时代" aria-label="Permalink to "2.3.1 机器语言(相当于人类的石器时代)""></a></h3><ul><li>1946 年 2 月 14 日,世界上第一台计算机 <code>ENIAC</code> 诞生,使用的是最原始的<code>穿透卡片</code>。</li></ul><p><img src="/coa6/assets/16.C2sciGZn.png" alt=""></p><ul><li>这种卡片使用的是用<code>二进制代码</code>表示的语言,和人类语言差别极大,这种语言就称为<code>机器语言</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>0000,0000,000000010000 代表 LOAD A, 16</span></span>
|
||||
<span class="line"><span>0000,0001,000000000001 代表 LOAD B, 1</span></span>
|
||||
<span class="line"><span>0001,0001,000000010000 代表 STORE B, 16</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>这种语言本质上是计算机能识别的<code>唯一语言</code>,人类很难理解;换言之,当时的程序员 99.9% 都是异类!!!</li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p>不同类型(CPU 架构,如:x86_64、arm 等)的处理器有不同的机器语言指令集,指令集架构(ISA)决定了机器语言的具体形式;换言之,机器语言与特定硬件架构紧密相关,机器语言程序几乎没有可移植性。</p></div><h3 id="_2-3-2-汇编语言-相当于人类的青铜-铁器时代" tabindex="-1">2.3.2 汇编语言(相当于人类的青铜&铁器时代) <a class="header-anchor" href="#_2-3-2-汇编语言-相当于人类的青铜-铁器时代" aria-label="Permalink to "2.3.2 汇编语言(相当于人类的青铜&铁器时代)""></a></h3><ul><li><code>汇编语言</code>使用<code>助记符</code>(如:MOV、ADD、SUB)代替二进制操作码,使程序更易于人类编写和理解;因此,<code>汇编语言</code>也被称为<code>符号语言</code>。</li></ul><p><img src="/coa6/assets/17.DdyXXyxJ.png" alt=""></p><ul><li>汇编语言的<code>优点</code>是能编写<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>汇编语言,目前仍然应用于工业电子编程领域、软件的加密解密、计算机病毒分析等。</p></div><h3 id="_2-3-3-高级语言-相当于人类的信息时代" tabindex="-1">2.3.3 高级语言(相当于人类的信息时代) <a class="header-anchor" href="#_2-3-3-高级语言-相当于人类的信息时代" aria-label="Permalink to "2.3.3 高级语言(相当于人类的信息时代)""></a></h3><ul><li><code>高级语言</code>是一种<code>接近于人们使用习惯</code>的程序设计语言。<code>它允许程序员使用接近日常英语的指令来编写程序</code>,程序中的符号和算式也和<code>日常使用的数学公式</code>差不多,接近于自然语言和数学语言,容易被人们掌握。</li></ul><p><img src="/coa6/assets/18.DIeb_KXW.png" alt=""></p><ul><li>高级语言<code>独立于计算机硬件</code>,有一定的通用性;计算机不能直接识别和执行用高级语言编写的程序,需要使用<code>编译器</code>或<code>解释器</code>转换为机器语言,才能被计算机识别和执行。</li></ul><p><img src="/coa6/assets/19.C-kvMz2p.png" alt=""></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>普遍使用的高级编程语言,有:C、C++、Java、Python、C#、JavaScript、Go、SQL 等。</p></div><h3 id="_2-3-4-总结" tabindex="-1">2.3.4 总结 <a class="header-anchor" href="#_2-3-4-总结" aria-label="Permalink to "2.3.4 总结""></a></h3><ul><li>编写语言的对比,如下所示:</li></ul><table tabindex="0"><thead><tr><th style="text-align:left;">类别</th><th style="text-align:left;">特征</th><th style="text-align:left;">优点</th><th style="text-align:left;">缺点</th><th style="text-align:left;">示例</th></tr></thead><tbody><tr><td style="text-align:left;"><strong>机器语言</strong></td><td style="text-align:left;">直接由计算机执行的二进制代码</td><td style="text-align:left;">执行速度快</td><td style="text-align:left;">编写困难,可读性差,与具体硬件强绑定</td><td style="text-align:left;">二进制代码</td></tr><tr><td style="text-align:left;"><strong>汇编语言</strong></td><td style="text-align:left;">用助记符代替二进制代码的低级语言</td><td style="text-align:left;">相对机器语言更易编写和理解,允许直接控制硬件资源</td><td style="text-align:left;">依然需要了解硬件,不够抽象,与具体硬件或平台相关</td><td style="text-align:left;">MOV,ADD 等助记符</td></tr><tr><td style="text-align:left;"><strong>高级语言</strong></td><td style="text-align:left;">接近人类语言,提供了更高层次的抽象</td><td style="text-align:left;">易于编写和维护,可移植性好,支持多种编程范式</td><td style="text-align:left;">需要通过编译器或解释器转换为机器语言,可能存在一定的性能损失</td><td style="text-align:left;">C,Java, Python 等</td></tr></tbody></table><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 这三种编程语言类型从低级到高级提供了不同层次的抽象,以满足不同的编程需求和场景。</li><li>② 随着计算机科学的发展,高级语言因其强大的表达能力、良好的可移植性和易用性,成为了日常软件开发的主流选择。</li></ul></div><h1 id="第三章-初识-c-语言" tabindex="-1">第三章:初识 C 语言 <a class="header-anchor" href="#第三章-初识-c-语言" aria-label="Permalink to "第三章:初识 C 语言""></a></h1><h2 id="_3-1-c-语言的由来" tabindex="-1">3.1 C 语言的由来 <a class="header-anchor" href="#_3-1-c-语言的由来" aria-label="Permalink to "3.1 C 语言的由来""></a></h2><ul><li>1969 年,美国贝尔实验室的<code>肯·汤姆森</code>(Ken Thompson)和<code>丹尼斯·里奇</code>(Dennis Ritchie)一起开发了 Unix 操作系统。Unix 最初是使用<code>汇编语言</code>编写的,依赖于计算机硬件。为了程序的<code>可读性</code>和<code>可移植性</code>,它们决定使用高级语言重写。但是。当时的高级语言无法满足他们的要求,<code>肯·汤姆森</code>就在 BCPL 语言的基础上发明了 <code>B</code> 语言。</li><li>1972 年,<code>丹尼斯·里奇</code>(Dennis Ritchie)在 <code>B</code> 语言的基础上重新设计了一种新的语言,这种新语言取代了 <code>B</code> 语言,即 <code>C</code> 语言。</li></ul><p><img src="/coa6/assets/20.CQqFxmDa.png" alt=""></p><ul><li>1973 年,<code>整个 Unix 系统都使用 C 语言重写</code>。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>C 语言最初是作为 Unix 系统的开发工具而发明的。</p></div><ul><li>此后,这种语言快速流传,广泛用于各种操作系统和系统软件的开发,如:Unix、MS-DOS、Microsoft Windows 以及 Linux 等。</li></ul><p><img src="/coa6/assets/21.CjMWyIiX.png" alt=""></p><ul><li>1988 年,美国国家标准协会(ANSI)正式将 <code>C 语言标准化</code>,标志着 C 语言开始稳定和规范化。</li></ul><h2 id="_3-2-为什么要学习-c-语言" tabindex="-1">3.2 为什么要学习 C 语言? <a class="header-anchor" href="#_3-2-为什么要学习-c-语言" aria-label="Permalink to "3.2 为什么要学习 C 语言?""></a></h2><ul><li>① <code>C 语言具有可移植好、跨平台的特点</code>:用 C 语言编写的代码可以在不同的操作系统和硬件平台上编译和运行。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>C 语言的最原始的设计目的,就是为了将 Unix 操作系统移植到其他的计算机架构上,这使得它从一开始就非常注重可移植性。</p></div><ul><li>② <code>C 语言在许多领域应用广泛</code>。 <ul><li><code>操作系统</code>:C 广泛用于开发操作系统,如:Unix、Linux 和 Windows。</li><li><code>嵌入式系统</code>:C 是一种用于开发嵌入式系统(如:微控制器、微处理器和其它电子设备)的流程语言。</li><li><code>系统软件</code>:C 用于开发设备驱动程序、编译器和汇编器等系统软件。</li><li><code>网络</code>:C 语言广泛用于开发网络应用程序,例如:Web 服务器、网络协议和网络驱动程序。</li><li><code>数据库系统</code>:C 用于开发数据库系统,例如:Oracle、MySQL 和 PostgreSQL 。</li><li><code>游戏</code>:由于 C 能够处理低级硬件交互,因此经常用于开发计算机游戏。</li><li><code>人工智能</code>:C 用于开发人工智能和机器学习的应用程序,例如:神经网络和深度学习算法。</li><li><code>科学应用</code>:C 用于开发科学应用程序,例如:仿真软件和数值分析工具。</li><li><code>金融应用</code>:C 用于开发股票市场分析和交易系统等金融应用。</li></ul></li><li>③ C 语言能够直接对硬件进行操作、管理内存以及和操作系统对话,这使得它是一种非常接近底层的语言,非常适合<code>写需要和硬件交互、有极高性能要求</code>的程序。</li><li>④ <code>学习 C 语言有助于快速上手其他编程语言</code>,如:C++(原先是 C 语言的一个扩展,在 C 语言的基础上嫁接了面向对象编程思想)、C#、Java 等,这些语言都继承或深受 C 语言的影响和启发。</li><li>⑤ C 语言长盛不衰。<code>C 语言至今,依然是最广泛使用、最流行的编程语言之一</code>,包括很多大学将 C 语言作为计算机教学的入门语言,拥有庞大而活跃的用户社区,这意味着有许多资源和库可供开发人员使用。</li></ul><h2 id="_3-3-计算机语言排行榜" tabindex="-1">3.3 计算机语言排行榜 <a class="header-anchor" href="#_3-3-计算机语言排行榜" aria-label="Permalink to "3.3 计算机语言排行榜""></a></h2><ul><li><a href="https://www.tiobe.com/tiobe-index/" target="_blank" rel="noreferrer">TIOBE</a> 是一个流行编程语言排行,每月更新。排名权重基于世界范围内工程师数量,Google、Bing、Yahoo! 、Wikipedia、Amazon、Youtube 和百度这些主流的搜索引擎,也将作为排名权重的参考指标。</li></ul><p><img src="/coa6/assets/22.DFQhcDgs.png" alt=""></p><ul><li>计算机语言走势图:</li></ul><p><img src="/coa6/assets/23.Cco1vsW8.png" alt=""></p><h2 id="_3-4-c-语言的版本选择" tabindex="-1">3.4 C 语言的版本选择 <a class="header-anchor" href="#_3-4-c-语言的版本选择" aria-label="Permalink to "3.4 C 语言的版本选择""></a></h2><ul><li><p>随着微型计算机的日益普及,出现了许多 C 语言版本(标准)。</p><ul><li>版本 1(K&R C):K&R C 指的是 C 语言的原始版本。1978年,C 语言的发明者布莱恩·柯林(Brian <code>K</code>ernighan)和丹尼斯·里奇(Dennis <code>R</code>itchie)合写了一本著名的教材《C 编程语言》(The C programming language)。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>由于 C 语言还没有成文的语法标准,这本书就成了公认标准,以两位作者的姓氏首字母作为版本简称 “K&R C”。</p></div><ul><li><p>版本 2(ANSI C,又称 C89 或 C90):C 语言的原始版本非常简单,对很多情况的描述非常模糊,加上 C 语法依然在快速发展,要求将 C 语言标准化的呼声越来越高。1989 年,美国国家标准协会(ANSI)制定了一套 C 语言标准,并于次年被国际标准化组织(ISO)通过。它被称为 “ANSI C”,也可以按照发布年份,称为 “C89 或 C90”。</p></li><li><p>版本 3(C99):C 语言标准的第一次<code>大型修订</code>,发生在 1999 年,增加了许多语言特性,比如:双斜杠( // )的注释语法,可变长度数组、灵活的数组成员、复数、内联函数和指定的初始值设定项,这个版本称为 C99,<code>是目前最流行的 C 版本</code>。</p></li><li><p>版本 4(C11):2011 年,标准化组织再一次对 C 语言进行修订,增加了_Generic、static_assert 和原子类型限定符。这个版本称为 C11。</p></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>需要强调的是,修订标准的原因并不是因为原标准不能用,而是需要跟进新的技术。</p></div><ul><li>版本 5(C17):C11 标准在 2017 年进行了修补,但发布是在 2018 年。新版本只是解决了 C11 的一些缺陷,没有引入任何新功能。这个版本称为 C17。</li><li>版本 6(C23):2023 年发布,计划进一步增强安全性,消除实现定义的行为,引入模块化语言概念等新特性,使 C 语言在安全和可靠性方面有重大提高。</li><li>……</li></ul></li><li><p>需要注意的是,C 语言的标准并没有强制性的约束,只是个说明文档而已。不同的编译器产商,对 C 语言的标准有不同的实现,甚至会出现某些 C 语言的标准在这个编译器下实现了;但是,在另外的编辑器下却没有实现,导致编译程序错误的现象。常见的 C/C++ 编译器如下:</p><ul><li>Borland C++ 宝蓝公司。</li><li>Intel C++ 英特尔编译器。</li><li>MSVC 微软公司。</li><li>g++ 编译器(GCC,编译套件), Linux 操作系统。</li></ul></li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p>GCC 编译套件对标准的支持是最好的;所以,在实际项目开发中,我们首先会选用 GCC 编译套件来进行开发。</p></div><h2 id="_3-5-c-语言的优缺点" tabindex="-1">3.5 C 语言的优缺点 <a class="header-anchor" href="#_3-5-c-语言的优缺点" aria-label="Permalink to "3.5 C 语言的优缺点""></a></h2><ul><li><p>C 语言的优点:</p><ul><li>① 高效:C 语言生成的代码非常高效,执行速度快,这使得其非常适合用于操作系统、嵌入式系统等需要高性能的场景。</li><li>② 灵活性和低级控制:C 语言允许直接操作内存和硬件,可以进行位操作、指针运算等底层编程,非常适合开发需要直接硬件控制的应用。</li><li>③ 广泛的硬件和平台支持:C 语言几乎可以在所有的计算机平台上运行,从微处理器到超级计算机,几乎所有的硬件平台都支持 C 语言。</li><li>④ 标准库丰富:C 语言有一个标准库(C Standard Library),提供了大量常用的函数,涵盖了文件操作、字符串处理、内存管理等多种功能。</li><li>⑤ 语言简洁:语法规则相对简单,没有过多的复杂特性,使得语言本身比较容易学习和掌握。</li></ul></li><li><p>C 语言的缺点:</p><ul><li>① 缺乏高级特性:和现代编程语言相对,C 语言缺乏一些高级特性,如:面向对象编程、垃圾回收机制等,这使得某些类型的应用程序开发可能会更加复杂。</li><li>② 安全性问题:C 语言允许直接操作内存,可能会导致缓冲区溢出、空指针引用等安全漏洞。如果不小心处理,容易产生难以调试的错误和安全隐患。</li><li>③ 手动管理内存:C 语言需要程序员手动管理内存,即:分配内存和释放内存,这增加了内存泄露和悬空指针等问题的风险。</li><li>④ 错误调试困难:由于 C 语言的底层操作特点,调试和排查错误可能比较困难,尤其是在处理复杂指针和内存操作的时候。</li><li>⑤ 标准库有限:虽然 C 语言的标准库涵盖了很多基本功能,但相比现代编程语言的标准库,功能相对有限,尤其是在网络编程、多线程编程等方面。</li></ul></li><li><p>总而言之,C 语言的高效性和灵活性使其在系统级编程和嵌入式系统中占据重要地位,但其缺乏高级特性和内存管理上的挑战也使得开发过程可能更加复杂和容易出错。对于需要高性能和底层控制的应用,C 语言依然是不可替代的选择。</p></li></ul><h1 id="第四章-c-语言入门-hello-world-⭐" tabindex="-1">第四章:C 语言入门(Hello World,⭐) <a class="header-anchor" href="#第四章-c-语言入门-hello-world-⭐" aria-label="Permalink to "第四章:C 语言入门(Hello World,⭐)""></a></h1><h2 id="_4-1-环境的安装和配置" tabindex="-1">4.1 环境的安装和配置 <a class="header-anchor" href="#_4-1-环境的安装和配置" aria-label="Permalink to "4.1 环境的安装和配置""></a></h2><h3 id="_4-1-1-概述" tabindex="-1">4.1.1 概述 <a class="header-anchor" href="#_4-1-1-概述" aria-label="Permalink to "4.1.1 概述""></a></h3><ul><li><p>要开发 C/C++ 程序,需要安装 C/C++ 编译器,目前有两种主流实现,即:</p><ul><li>GCC(GNU Compiler Collection):全平台实现,即支持 Windows、MacOS、Linux 等。</li><li>MSVC(Microsoft Visual C++):只支持 Windows 系统。</li></ul></li><li><p>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>。它们之间的区别,如下所示:</p></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></ul></div><h3 id="_4-1-2-mingw-w64-的安装和配置" tabindex="-1">4.1.2 MinGW-w64 的安装和配置 <a class="header-anchor" href="#_4-1-2-mingw-w64-的安装和配置" aria-label="Permalink to "4.1.2 MinGW-w64 的安装和配置""></a></h3><h4 id="_4-1-2-1-安装" tabindex="-1">4.1.2.1 安装 <a class="header-anchor" href="#_4-1-2-1-安装" aria-label="Permalink to "4.1.2.1 安装""></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="/coa6/assets/24.D60Zf6_d.png" alt=""></p><ul><li>解压到指定的目录,即:</li></ul><p><img src="/coa6/assets/25.D2-G6nV2.png" alt=""></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="_4-1-2-2-配置-path-环境变量" tabindex="-1">4.1.2.2 配置 path 环境变量 <a class="header-anchor" href="#_4-1-2-2-配置-path-环境变量" aria-label="Permalink to "4.1.2.2 配置 path 环境变量""></a></h4><ul><li>配置环境变量,以便任意目录都可以执行 gcc 命令,即:</li></ul><p><img src="/coa6/assets/26.DpzkVk5V.png" alt=""></p><p><img src="/coa6/assets/27.BXk95GIP.png" alt=""></p><p><img src="/coa6/assets/28.CbWTB08W.png" alt=""></p><p><img src="/coa6/assets/29.twO9TCIg.png" alt=""></p><p><img src="/coa6/assets/30.CKOjeIvS.png" alt=""></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="/coa6/assets/31.DKmR0CxE.png" alt=""></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="/coa6/assets/32.Cudf77_s.gif" alt=""></p><h3 id="_4-1-3-cygwin-的安装和配置" tabindex="-1">4.1.3 Cygwin 的安装和配置 <a class="header-anchor" href="#_4-1-3-cygwin-的安装和配置" aria-label="Permalink to "4.1.3 Cygwin 的安装和配置""></a></h3><h4 id="_4-1-3-1-安装" tabindex="-1">4.1.3.1 安装 <a class="header-anchor" href="#_4-1-3-1-安装" aria-label="Permalink to "4.1.3.1 安装""></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="/coa6/assets/33.BBUUlhRC.png" alt=""></p><ul><li>点击安装:</li></ul><p><img src="/coa6/assets/34.iLABkB7O.png" alt=""></p><p><img src="/coa6/assets/35.BQuYWOU9.png" alt=""></p><p><img src="/coa6/assets/36.CslpH6j0.png" alt=""></p><p><img src="/coa6/assets/37.BAyvZdKq.png" alt=""></p><p><img src="/coa6/assets/38.C3oC1iUd.png" alt=""></p><p><img src="/coa6/assets/39.Ds-jsEZn.png" alt=""></p><p><img src="/coa6/assets/40.Cd37gMYs.png" alt=""></p><p><img src="/coa6/assets/41.CAw2z3gc.png" alt=""></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="/coa6/assets/42.DdPThnr-.png" alt=""></p><p><img src="/coa6/assets/43.q_rvlDnY.png" alt=""></p><p><img src="/coa6/assets/44.JRHg9RZA.png" alt=""></p><p><img src="/coa6/assets/45.Baq-Hb06.png" alt=""></p><p><img src="/coa6/assets/46.c1ht53mu.png" alt=""></p><p><img src="/coa6/assets/47.CAZmH5Py.png" alt=""></p><p><img src="/coa6/assets/48.DWeCYBe9.png" alt=""></p><p><img src="/coa6/assets/49.2XM8pYni.png" alt=""></p><p><img src="/coa6/assets/50.CN0t-fuo.png" alt=""></p><h4 id="_4-1-3-2-配置-path-环境变量" tabindex="-1">4.1.3.2 配置 path 环境变量 <a class="header-anchor" href="#_4-1-3-2-配置-path-环境变量" aria-label="Permalink to "4.1.3.2 配置 path 环境变量""></a></h4><ul><li>和 <code>3.1.2.2 配置 path 环境变量</code> 步骤相同:略。</li></ul><h3 id="_4-1-4-msys2-推荐" tabindex="-1">4.1.4 MSYS2(推荐) <a class="header-anchor" href="#_4-1-4-msys2-推荐" aria-label="Permalink to "4.1.4 MSYS2(推荐)""></a></h3><h4 id="_4-1-4-1-安装" tabindex="-1">4.1.4.1 安装 <a class="header-anchor" href="#_4-1-4-1-安装" aria-label="Permalink to "4.1.4.1 安装""></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="/coa6/assets/51.AcDh3LXQ.png" alt=""></p><ul><li>点击安装:</li></ul><p><img src="/coa6/assets/52.CUkDFAc6.png" alt=""></p><p><img src="/coa6/assets/53.picNTNaJ.png" alt=""></p><p><img src="/coa6/assets/54.DKX92RgJ.png" alt=""></p><p><img src="/coa6/assets/55.Bxr7QKI3.png" alt=""></p><p><img src="/coa6/assets/56.DuFWsOgW.png" alt=""></p><ul><li>出现命令终端:</li></ul><p><img src="/coa6/assets/57.Da9qUcfr.png" alt=""></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;">sed</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -i</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "s#https\?://mirror.msys2.org/#https://mirrors.tuna.tsinghua.edu.cn/msys2/#g"</span><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></div></div><p><img src="/coa6/assets/58.7_gEABSX.gif" alt=""></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-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><p><img src="/coa6/assets/59.C2KQYoVC.gif" alt=""></p><h4 id="_4-1-4-2-配置-path-环境变量" tabindex="-1">4.1.4.2 配置 path 环境变量 <a class="header-anchor" href="#_4-1-4-2-配置-path-环境变量" aria-label="Permalink to "4.1.4.2 配置 path 环境变量""></a></h4><ul><li>和 <code>3.1.2.2 配置 path 环境变量</code> 步骤相同:略。</li></ul><h2 id="_4-2-ide-的安装和配置" tabindex="-1">4.2 IDE 的安装和配置 <a class="header-anchor" href="#_4-2-ide-的安装和配置" aria-label="Permalink to "4.2 IDE 的安装和配置""></a></h2><h3 id="_4-2-1-clion" tabindex="-1">4.2.1 CLion <a class="header-anchor" href="#_4-2-1-clion" aria-label="Permalink to "4.2.1 CLion""></a></h3><h4 id="_4-2-1-1-概述" tabindex="-1">4.2.1.1 概述 <a class="header-anchor" href="#_4-2-1-1-概述" aria-label="Permalink to "4.2.1.1 概述""></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><h4 id="_4-2-1-2-安装" tabindex="-1">4.2.1.2 安装 <a class="header-anchor" href="#_4-2-1-2-安装" aria-label="Permalink to "4.2.1.2 安装""></a></h4><ul><li>鼠标双击,进入安装:</li></ul><p><img src="/coa6/assets/60.RTUP8Vtx.png" alt=""></p><ul><li>下一步:</li></ul><p><img src="/coa6/assets/61.Dq21DxwL.png" alt=""></p><ul><li>下一步:</li></ul><p><img src="/coa6/assets/62.QmpUaNxU.png" alt=""></p><ul><li>下一步:</li></ul><p><img src="/coa6/assets/63.DP0C29gZ.png" alt=""></p><ul><li>安装:</li></ul><p><img src="/coa6/assets/64.DwzHokd4.png" alt=""></p><ul><li>安装完成:</li></ul><p><img src="/coa6/assets/65.Bi6K26yA.png" alt=""></p><h4 id="_4-2-1-3-配置" tabindex="-1">4.2.1.3 配置 <a class="header-anchor" href="#_4-2-1-3-配置" aria-label="Permalink to "4.2.1.3 配置""></a></h4><ul><li>打开 CLion :</li></ul><p><img src="/coa6/assets/66.Bw8DcEQ_.png" alt=""></p><ul><li>安装中文插件(可选):</li></ul><p><img src="/coa6/assets/67.DPc8Z9rS.png" alt=""></p><p><img src="/coa6/assets/68.S84xHMTl.png" alt=""></p><ul><li>配置新 UI :</li></ul><p><img src="/coa6/assets/69.iw3JQUkn.png" alt=""></p><p><img src="/coa6/assets/70.ILeJt-HK.png" alt=""></p><ul><li>新 UI 配置自定义字体(可选):</li></ul><p><img src="/coa6/assets/71.CHgm7khh.png" alt=""></p><ul><li>配置<code>自动保存</code>功能:</li></ul><p><img src="/coa6/assets/72.N1nqJaEg.png" alt=""></p><ul><li>配置<code>文件编码</code> 为 UTF-8:</li></ul><p><img src="/coa6/assets/73.DHsnibMi.png" alt=""></p><ul><li>配置<code>控制台编码</code>为 UTF-8:</li></ul><p><img src="/coa6/assets/74.BQr6Q0uV.png" alt=""></p><ul><li>配置<code>显示方法分隔符</code>功能:</li></ul><p><img src="/coa6/assets/75.BVemi2Lh.png" alt=""></p><ul><li>配置<code>编辑器</code>的字体(可选):</li></ul><p><img src="/coa6/assets/76.BHR69UXx.png" alt=""></p><ul><li>检测 GCC 工具链是否安装成功:</li></ul><p><img src="/coa6/assets/77.CPSU5SJI.png" alt=""></p><h3 id="_4-2-2-vs-code" tabindex="-1">4.2.2 VS Code <a class="header-anchor" href="#_4-2-2-vs-code" aria-label="Permalink to "4.2.2 VS Code""></a></h3><h4 id="_4-2-2-1-概述" tabindex="-1">4.2.2.1 概述 <a class="header-anchor" href="#_4-2-2-1-概述" aria-label="Permalink to "4.2.2.1 概述""></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><p>Visual Studio Code 需要安装对应的插件,才能运行 C/C++ 代码。</p></div><h4 id="_4-2-2-2-安装" tabindex="-1">4.2.2.2 安装 <a class="header-anchor" href="#_4-2-2-2-安装" aria-label="Permalink to "4.2.2.2 安装""></a></h4><ul><li>鼠标双击,进入安装:</li></ul><p><img src="/coa6/assets/78.CaQLoDlw.png" alt=""></p><ul><li>同意协议:</li></ul><p><img src="/coa6/assets/79.aRGy4XbL.png" alt=""></p><ul><li>下一步:</li></ul><p><img src="/coa6/assets/80.kNO9fmPR.png" alt=""></p><ul><li>下一步:</li></ul><p><img src="/coa6/assets/81.D4EkoC4o.png" alt=""></p><ul><li>下一步:</li></ul><p><img src="/coa6/assets/82.V23Lo9e_.png" alt=""></p><ul><li>安装:</li></ul><p><img src="/coa6/assets/83.Du9LVeMB.png" alt=""></p><ul><li>安装过程:</li></ul><p><img src="/coa6/assets/84.DdFg75U9.png" alt=""></p><ul><li>安装完成:</li></ul><p><img src="/coa6/assets/85.C6bz6KtT.png" alt=""></p><h4 id="_4-2-2-3-配置" tabindex="-1">4.2.2.3 配置 <a class="header-anchor" href="#_4-2-2-3-配置" aria-label="Permalink to "4.2.2.3 配置""></a></h4><ul><li>安装<code>中文</code>插件:</li></ul><p><img src="/coa6/assets/86.CB6LAhB5.png" alt=""></p><p><img src="/coa6/assets/87.Bip8bkua.png" alt=""></p><ul><li>安装 <code>C/C++</code> 插件:</li></ul><p><img src="/coa6/assets/88.DRNHRduW.png" alt=""></p><p><img src="/coa6/assets/89.Cth4qqEn.png" alt=""></p><h3 id="_4-2-3-microsoft-visual-studio" tabindex="-1">4.2.3 Microsoft Visual Studio <a class="header-anchor" href="#_4-2-3-microsoft-visual-studio" aria-label="Permalink to "4.2.3 Microsoft Visual Studio""></a></h3><h4 id="_4-2-3-1-概述" tabindex="-1">4.2.3.1 概述 <a class="header-anchor" href="#_4-2-3-1-概述" aria-label="Permalink to "4.2.3.1 概述""></a></h4><ul><li><p><a href="https://visualstudio.microsoft.com/" target="_blank" rel="noreferrer">Visual Studio</a>(简称 VS)是由微软公司发布的集成开发环境。它包括了整个软件生命周期中所需要的大部分工具,如:UML工具、代码管控工具、集成开发环境(IDE)等。</p></li><li><p>Visual Studio 支持 C/C++、C#、F#、VB 等多种程序语言的开发和测试,可以用于生成Web应用程序,也可以生成桌面应用程序,功能十分强大,但下载和安装很可能耗时数小时,还可能会塞满磁盘。</p></li><li><p>Visual Studio 2022 有三种版本:社区版(免费,不支持企业使用),专业版(第一年 1199 美元/ 799 美元续订)和企业版(第一年 5999 美元/ 2569 美元续订)。企业版拥有面向架构师的功能、高级调试和测试,这些功能是另两种 SKU 所没有的。</p></li><li><p>Visual Studio 旨在成为世界上最好的 IDE(集成开发环境),目前最新版本为 Visual Studio 2022。</p></li></ul><h4 id="_4-2-3-2-安装" tabindex="-1">4.2.3.2 安装 <a class="header-anchor" href="#_4-2-3-2-安装" aria-label="Permalink to "4.2.3.2 安装""></a></h4><ul><li>鼠标双击,进入安装:</li></ul><p><img src="/coa6/assets/90.DWGWZ64P.png" alt=""></p><ul><li>继续:</li></ul><p><img src="/coa6/assets/91.3hDIDdvx.png" alt=""></p><ul><li>等待:</li></ul><p><img src="/coa6/assets/92.Bw_dQ4ap.png" alt=""></p><ul><li>工作负荷(使用 C++ 的桌面开发):</li></ul><p><img src="/coa6/assets/93.Cn_ubTyA.png" alt=""></p><ul><li>单个组件:</li></ul><p><img src="/coa6/assets/94.C84EBqwB.png" alt=""></p><ul><li>语言包:</li></ul><p><img src="/coa6/assets/95.dZfJY4eR.png" alt=""></p><ul><li>安装位置(修改默认的安装位置):</li></ul><p><img src="/coa6/assets/96.B0zm0Z79.png" alt=""></p><ul><li>如果不是第一次安装,可能会出现<code>共享组件、工具和 SDK</code>不可以修改,即:</li></ul><p><img src="/coa6/assets/97.CaTcEy1Q.png" alt=""></p><ul><li>此时,就需要打开<code>注册表编辑器</code>,将如下图中的除了第一个选项,全部删除,然后关闭再重新安装,即:</li></ul><p><img src="/coa6/assets/98.iEc8mo9g.png" alt=""></p><ul><li>开始安装:</li></ul><p><img src="/coa6/assets/99.Co2KxM6t.png" alt=""></p><ul><li>安装中:</li></ul><p><img src="/coa6/assets/100.CaUm8Qhc.png" alt=""></p><ul><li>安装完成,然后关闭:</li></ul><p><img src="/coa6/assets/101.kOkqIKG6.png" alt=""></p><h4 id="_4-2-3-3-配置" tabindex="-1">4.2.3.3 配置 <a class="header-anchor" href="#_4-2-3-3-配置" aria-label="Permalink to "4.2.3.3 配置""></a></h4><ul><li>在开始菜单处,启动 VS :</li></ul><p><img src="/coa6/assets/102.CyeASH-c.png" alt=""></p><ul><li>登录或跳过该选项(有微软账号就注册,没有就暂时跳过):</li></ul><p><img src="/coa6/assets/103.CFdk60La.png" alt=""></p><ul><li>继续:</li></ul><p><img src="/coa6/assets/104.Bhl-0uK_.png" alt=""></p><ul><li>注册 VS :</li></ul><p><img src="/coa6/assets/105.Dni9KbXV.png" alt=""></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="/coa6/assets/106.BXx10MCV.png" alt=""></p><p><img src="/coa6/assets/107.CXcIKX1T.png" alt=""></p><h2 id="_4-3-helloworld" tabindex="-1">4.3 HelloWorld <a class="header-anchor" href="#_4-3-helloworld" aria-label="Permalink to "4.3 HelloWorld""></a></h2><h3 id="_4-3-1-手动版" tabindex="-1">4.3.1 手动版 <a class="header-anchor" href="#_4-3-1-手动版" aria-label="Permalink to "4.3.1 手动版""></a></h3><ul><li>① 新建一个 <code>HelloWorld.c</code> 的文件:</li></ul><p><img src="/coa6/assets/108.CQ3_QCQT.png" alt=""></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;"> <stdio.h></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;">"Hello World"</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></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></div></div><p><img src="/coa6/assets/109.CQoDRJM5.gif" alt=""></p><ul><li>③ 通过 <code>gcc</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;">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="/coa6/assets/110.CPfwZvD9.gif" alt=""></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;">./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="/coa6/assets/111.bxEomEjU.gif" alt=""></p><h3 id="_4-3-2-vs-code-版" tabindex="-1">4.3.2 VS Code 版 <a class="header-anchor" href="#_4-3-2-vs-code-版" aria-label="Permalink to "4.3.2 VS Code 版""></a></h3><ul><li>① 新建一个<code>空</code>文件夹(目录),用于存放代码:</li></ul><p><img src="/coa6/assets/112.C_onhf2k.png" alt=""></p><ul><li>② 通过 <code>vscode</code> 打开该目录:</li></ul><p><img src="/coa6/assets/113.Budj3s38.gif" alt=""></p><ul><li>③ 在 <code>vscode</code> 中新建 <code>HelloWorld.c</code> 文件:</li></ul><p><img src="/coa6/assets/114.CH8koQdu.gif" alt=""></p><ul><li>④ 设置 VSCode 中 C/C++ 的代码格式为行尾风格(可选):</li></ul><p><img src="/coa6/assets/115.kUJhxMtg.png" alt=""></p><p><img src="/coa6/assets/116.BJeJJW4_.png" alt=""></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;"> <stdio.h></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;">"Hello World"</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></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></div></div><p><img src="/coa6/assets/117.BCuK6eJL.gif" alt=""></p><ul><li>⑥ 通过 <code>gcc</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;">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="/coa6/assets/118.rKC-z4z-.gif" alt=""></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;">./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="/coa6/assets/119.BJE3xxuT.gif" alt=""></p><ul><li>⑧ 安装 Code Runner 插件(步骤略),实现右键直接编译执行(可选):</li></ul><p><img src="/coa6/assets/120.DJOq__O0.gif" alt=""></p><h3 id="_4-3-3-vs-版" tabindex="-1">4.3.3 VS 版 <a class="header-anchor" href="#_4-3-3-vs-版" aria-label="Permalink to "4.3.3 VS 版""></a></h3><ul><li>① 新建空项目:</li></ul><p><img src="/coa6/assets/121.BDt_0fRR.png" alt=""></p><p><img src="/coa6/assets/122.Bo5OawW8.png" alt=""></p><p><img src="/coa6/assets/123.sUWUfl5e.png" alt=""></p><p><img src="/coa6/assets/124.BK4jpnB8.png" alt=""></p><ul><li>② 打开<code>解决方案资源管理器</code>:</li></ul><p><img src="/coa6/assets/125.EF8vdbSq.png" alt=""></p><p><img src="/coa6/assets/126.DjxdA_Co.png" alt=""></p><ul><li>③ 新建 <code>HelloWorld.c</code> 文件:</li></ul><p><img src="/coa6/assets/127.sp68q1hh.gif" alt=""></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;"> <stdio.h></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;">"Hello World"</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></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></div></div><p><img src="/coa6/assets/128.DhMRyxNN.gif" alt=""></p><ul><li>⑤ 编译和执行:</li></ul><p><img src="/coa6/assets/129.CdcLZM0R.gif" alt=""></p><h3 id="_4-3-4-clion" tabindex="-1">4.3.4 CLion <a class="header-anchor" href="#_4-3-4-clion" aria-label="Permalink to "4.3.4 CLion""></a></h3><ul><li>① 新建空项目:</li></ul><p><img src="/coa6/assets/130.D-5AsTTr.png" alt=""></p><p><img src="/coa6/assets/131.2RQKmAUa.png" alt=""></p><p><img src="/coa6/assets/132.CI4xX8SM.png" alt=""></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;"> <stdio.h></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;">"Hello World"</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></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></div></div><p><img src="/coa6/assets/133.C8QUZ9v3.gif" alt=""></p><ul><li>③ 编译和运行:</li></ul><p><img src="/coa6/assets/134.g5tQfhWz.gif" alt=""></p><ul><li>④ 默认情况下,一个项目只能有一个 c 源文件包含 main 函数,但是 CLion 可以有多个,如下:</li></ul><p><img src="/coa6/assets/135.CX0_1NsE.gif" alt=""></p><ul><li>⑤ 如果之后,有中文乱码问题,那么请做如下步骤:</li></ul><p><img src="/coa6/assets/136.BrFJeoK6.png" alt=""></p><p><img src="/coa6/assets/137.58TjSSjH.gif" alt=""></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>内容如下所示:</p><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>-Dfile.encoding=UTF-8</span></span>
|
||||
<span class="line"><span>-Dconsole.encoding=UTF-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></div></div></div><h1 id="第五章-注释" tabindex="-1">第五章:注释 <a class="header-anchor" href="#第五章-注释" aria-label="Permalink to "第五章:注释""></a></h1><h2 id="_5-1-概述" tabindex="-1">5.1 概述 <a class="header-anchor" href="#_5-1-概述" aria-label="Permalink to "5.1 概述""></a></h2><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>② 在实际开发中,程序员可以将自己的思路通过<code>注释</code>整理出来,然后再用<code>代码</code>去实现。</li></ul></div><h2 id="_5-2-单行注释" tabindex="-1">5.2 单行注释 <a class="header-anchor" href="#_5-2-单行注释" aria-label="Permalink to "5.2 单行注释""></a></h2><ul><li>C 语言中的单行注释的格式,如下所示:</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;">// 单行注释</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>在 CLion 中的快捷键是 <code>Ctrl + /</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;"> <stdio.h></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;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</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;">"你好,世界!!!"</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 style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 函数执行完毕时返回函数值0</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></div></div><h2 id="_5-3-多行注释" tabindex="-1">5.3 多行注释 <a class="header-anchor" href="#_5-3-多行注释" aria-label="Permalink to "5.3 多行注释""></a></h2><ul><li>C 语言中的多行注释的格式,如下所示:</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;">/*</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;"> 这是第二行注释</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;">*/</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>① 多行注释不能嵌套使用!!!</li><li>② 在 CLion 中的快捷键是 <code>Ctrl + Alt + /</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;"> <stdio.h></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:#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:#6A737D;--shiki-dark:#6A737D;"> printf(1);</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> printf(2);</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;">"你好,世界!!!"</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></div></div><h1 id="第六章-helloworld-的规范-⭐" tabindex="-1">第六章:HelloWorld 的规范(⭐) <a class="header-anchor" href="#第六章-helloworld-的规范-⭐" aria-label="Permalink to "第六章:HelloWorld 的规范(⭐)""></a></h1><h2 id="_6-1-规范的代码风格" tabindex="-1">6.1 规范的代码风格 <a class="header-anchor" href="#_6-1-规范的代码风格" aria-label="Permalink to "6.1 规范的代码风格""></a></h2><h3 id="_6-1-1-正确的缩进和空白" tabindex="-1">6.1.1 正确的缩进和空白 <a class="header-anchor" href="#_6-1-1-正确的缩进和空白" aria-label="Permalink to "6.1.1 正确的缩进和空白""></a></h3><ul><li>① 使用一次 <code>tab</code> 操作,实现缩进,默认整体向右边移动;如果使用 <code>shift + tab</code> 则整体向左移动。</li><li>② 运算符两边习惯各加一个空格,如:<code>2 + 4 = 6</code>。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>各种 IDE 都有格式化的快捷键,如:CLion 的格式化快捷键是 <code>Ctrl + Alt + L</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;"> <stdio.h></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;"> a </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;"> b </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:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> c </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> a </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> b;</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;">"c = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</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></div></div><h3 id="_6-1-2-代码风格" tabindex="-1">6.1.2 代码风格 <a class="header-anchor" href="#_6-1-2-代码风格" aria-label="Permalink to "6.1.2 代码风格""></a></h3><ul><li>在 C 语言中,有两种代码风格:<code>行尾风格</code>和<code>次行风格</code>。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>看个人爱好,任选一种即可,本人喜欢<code>行尾分格</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;">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;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(a </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">></span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> b) {</span></span>
|
||||
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> a;</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;"> return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> b;</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></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;"> 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;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(a </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">></span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> b) </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:#24292E;--shiki-dark:#E1E4E8;"> a;</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;"> else</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:#24292E;--shiki-dark:#E1E4E8;"> b;</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></div></div><h2 id="_6-2-代码细节剖析" tabindex="-1">6.2 代码细节剖析 <a class="header-anchor" href="#_6-2-代码细节剖析" aria-label="Permalink to "6.2 代码细节剖析""></a></h2><h3 id="_6-2-1-main-函数" tabindex="-1">6.2.1 main() 函数 <a class="header-anchor" href="#_6-2-1-main-函数" aria-label="Permalink to "6.2.1 main() 函数""></a></h3><ul><li>在 C 语言中,一个程序或工程可以定义很多函数,但是有且只有一个 main() 函数,作为程序执行的入口,并且在 main() 函数结尾结束整个程序的运行,即:</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;"> main</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></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>如果 main() 函数是空括号,即表示 main() 函数不接收任何参数。</li><li>在 main() 函数之前的 <code>int</code> 称为关键字,代表数据类型是<code>整型</code>,它是 main() 函数的返回值的类型,即在执行 main() 函数之后一定会得到一个整数类型的值,即函数值。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 在 C 语言中,人们约定,如果 <code>return 0</code>,就表示 main() 函数终止运行,且运行成功;如果返回其它非零整数,则表示运行失败。</li><li>② 默认情况下,如果 main() 函数中省略 <code>return 0</code> ,则编译器会自动加上;但是,为了保持统一的代码风格,不建议省略。</li></ul></div><h3 id="_6-2-2-函数体" tabindex="-1">6.2.2 函数体 <a class="header-anchor" href="#_6-2-2-函数体" aria-label="Permalink to "6.2.2 函数体""></a></h3><ul><li>① 一对花括号 <code>{}</code> 定义了函数的主体,所有函数都必须以大括号开头和结尾,成对出现。</li><li>② C 程序中的函数体指的是作为该函数一部分的语句。它可以是任何操作,比如:搜索、排序、打印等。</li><li>③ 每一个执行语句后面都会有一个英文分号<code>;</code>作为语句结束的标志。</li><li>④ 一行内可写几条语句,一条语句也可写在几行上。</li></ul><h3 id="_6-2-3-printf-函数" tabindex="-1">6.2.3 printf() 函数 <a class="header-anchor" href="#_6-2-3-printf-函数" aria-label="Permalink to "6.2.3 printf() 函数""></a></h3><ul><li>printf() 函数的格式,如下所示:</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;">printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">__format</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>printf() 函数是产生格式化输出的函数,作用是将参数文本输出到屏幕,f 表示 format(格式化),表示可以指定输出文本的格式,即:</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;">printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"Hello World"</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><ul><li>如果想让光标移动到下一行的开头,可以在输出文本的结尾,可以添加一个换行符 <code>\n</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:#6F42C1;--shiki-dark:#B392F0;">printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"Hello World</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</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><h3 id="_6-2-4-标准库和头文件" tabindex="-1">6.2.4 标准库和头文件 <a class="header-anchor" href="#_6-2-4-标准库和头文件" aria-label="Permalink to "6.2.4 标准库和头文件""></a></h3><h4 id="_6-2-4-1-概述" tabindex="-1">6.2.4.1 概述 <a class="header-anchor" href="#_6-2-4-1-概述" aria-label="Permalink to "6.2.4.1 概述""></a></h4><ul><li>printf() 函数是在标准库的头文件 <code>stdio.h</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;"> <stdio.h></span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><h4 id="_6-2-4-2-标准库-standard-library" tabindex="-1">6.2.4.2 标准库(Standard Library) <a class="header-anchor" href="#_6-2-4-2-标准库-standard-library" aria-label="Permalink to "6.2.4.2 标准库(Standard Library)""></a></h4><ul><li>C 语言的<code>标准库</code>是由一组函数组成,这些函数提供了许多常用的操作和功能,如:输入输出、字符串处理、内存管理、数学计算等。标准库中的函数由编译器提供,遵循 ANSI C 标准(如:C89/C90、C99、C11等)。</li><li>换言之,C 语言的<code>标准库</code>就是包含函数的实际代码,这些代码在编译的时候被链接到我们的程序中,无需手动包含。C 语言的<code>标准库</code>提供了可重用的函数实现,使得程序员不必编写常用的功能。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>实际的 printf() 函数的实现代码通常位于标准库的实现文件中,如:在 Linux 中的标准库<code>libc.so.6</code> 就包含了 printf() 函数的实现。</p></div><h4 id="_6-2-4-3-头文件-header-files" tabindex="-1">6.2.4.3 头文件(Header Files) <a class="header-anchor" href="#_6-2-4-3-头文件-header-files" aria-label="Permalink to "6.2.4.3 头文件(Header Files)""></a></h4><ul><li><p><code>头文件</code>是包含函数声明、宏定义、数据类型定义等内容的文件。头文件的作用是为源代码提供必要的声明和定义,以便编译器能够正确解析和链接函数调用。头文件通常以<code>.h</code>作为文件扩展名。</p></li><li><p>换言之,头文件包含函数声明、宏定义和数据类型定义,但不包含函数的实现。头文件告知编译器如何使用标准库中的函数和定义,确保编译时的正确性。头文件需要在源代码文件中使用<code>#include</code>指令显式包含,如:<code>#include <stdio.h></code>。</p></li><li><p>常见的 C 语言头文件及其功能和常用函数、宏等,如下所示:</p></li></ul><table tabindex="0"><thead><tr><th>头文件</th><th>功能说明</th><th>常用函数和宏</th></tr></thead><tbody><tr><td><strong>stdio.h</strong></td><td>标准输入输出库</td><td><code>printf</code>, <code>scanf</code>, <code>fprintf</code>,<code>fscanf</code>,<code>fopen</code>, <code>fclose</code>,<code>fgets</code>, <code>fputs</code></td></tr><tr><td><strong>stdlib.h</strong></td><td>标准库,提供内存分配、程序控制、类型转换、随机数生成等功能</td><td><code>malloc</code>, <code>free</code>, <code>exit</code>, <code>atoi</code>, <code>atof</code>,<code>rand</code>,<code>srand</code></td></tr><tr><td><strong>string.h</strong></td><td>字符串处理库</td><td><code>strlen</code>, <code>strcpy</code>, <code>strncpy</code>, <code>strcat</code>, <code>strcmp</code>,<code>strstr</code>, <code>memset</code>, <code>memcpy</code></td></tr><tr><td><strong>math.h</strong></td><td>数学库</td><td><code>sin</code>, <code>cos</code>, <code>tan</code>, <code>exp</code>, <code>log</code>, <code>sqrt</code>, <code>pow</code></td></tr><tr><td><strong>time.h</strong></td><td>时间和日期库</td><td><code>time</code>, <code>clock</code>, <code>difftime</code>, <code>mktime</code>, <code>strftime</code>, <code>localtime</code>,<code>gmtime</code></td></tr><tr><td><strong>ctype.h</strong></td><td>字符处理库</td><td><code>isalnum</code>, <code>isalpha</code>, <code>isdigit</code>, <code>islower</code>, <code>isupper</code>, <code>tolower</code>, <code>toupper</code></td></tr><tr><td><strong>stdbool.h</strong></td><td>布尔类型库</td><td><code>bool</code>, <code>true</code>, <code>false</code></td></tr><tr><td><strong>assert.h</strong></td><td>断言库</td><td><code>assert</code></td></tr></tbody></table><h4 id="_6-2-4-4-预处理命令" tabindex="-1">6.2.4.4 预处理命令 <a class="header-anchor" href="#_6-2-4-4-预处理命令" aria-label="Permalink to "6.2.4.4 预处理命令""></a></h4><ul><li><code>#include</code> 命令的作用是将指定文件的内容插入到包含该命令的源文件中。这通常用于包含头文件,以便使用头文件中声明的函数、宏和数据类型。</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:#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:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> <filename></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:#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:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "filename"</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><h1 id="第七章-clion-高级配置-⭐" tabindex="-1">第七章:CLion 高级配置(⭐) <a class="header-anchor" href="#第七章-clion-高级配置-⭐" aria-label="Permalink to "第七章:CLion 高级配置(⭐)""></a></h1><h2 id="_7-1-安装和配置-wsl2" tabindex="-1">7.1 安装和配置 WSL2 <a class="header-anchor" href="#_7-1-安装和配置-wsl2" aria-label="Permalink to "7.1 安装和配置 WSL2""></a></h2><h3 id="_7-1-1-概述" tabindex="-1">7.1.1 概述 <a class="header-anchor" href="#_7-1-1-概述" aria-label="Permalink to "7.1.1 概述""></a></h3><ul><li>WSL 2,全称为 Windows Subsystem for Linux 2,是微软提供的一种技术,允许用户在 Windows 操作系统上运行 Linux 内核。WSL 2 是 WSL 的升级版,它引入了一个真正的 Linux 内核来代替 WSL 1 中使用的兼容层,从而提供更高的性能和更广泛的系统调用支持。</li><li>其架构图,如下所示:</li></ul><p><img src="/coa6/assets/138.CgqNV2hL.png" alt=""></p><ul><li><p>WSL2 的功能,如下所示:</p><ul><li>① <strong>真实的Linux内核</strong>:WSL 2 使用了微软开发的轻量级虚拟机,它包含了一个完整的 Linux 内核。这意味着 WSL 2 能够运行更多的 Linux 应用程序,并且支持更多的系统调用。</li><li>② <strong>文件系统性能提升</strong>:WSL 2 的文件系统性能比 WSL 1 有显著提升。对于 I/O 密集型的操作,如:编译代码或数据库操作,WSL 2 能够提供更快的速度。</li><li>③ <strong>兼容性增强</strong>:由于使用了真实的 Linux 内核,WSL 2 对 Linux 应用程序的兼容性大幅提高。许多在 WSL 1上不能运行或需要调整的应用程序,可以在 WSL 2上直接运行。</li><li>④ <strong>网络功能改进</strong>:WSL 2 提供了更好的网络集成,能够更容易地与 Windows 上的其他网络资源进行交互。</li><li>⑤ <strong>资源使用优化</strong>:WSL 2 使用轻量级虚拟机,比传统的虚拟机占用更少的资源,同时提供了类似的隔离和安全性。</li></ul></li><li><p>WSL 的用途,如下所示:</p><ul><li>① <strong>开发环境</strong>:WSL 2 为开发者提供了一个原生的Linux开发环境,而无需离开 Windows 。这对于需要在 Linux 上开发、测试或运行应用程序的开发者非常有帮助。</li><li>② <strong>学习和实验</strong>:用户可以使用 WSL 2 在Windows上学习和实验 Linux 命令行工具和应用程序,而无需设置双重引导系统或安装虚拟机。</li><li>③ <strong>多平台开发</strong>:对于跨平台开发者来说,WSL 2 允许他们在一个操作系统上同时进行 Windows 和 Linux 平台的开发和测试,提高工作效率。</li><li>④ <strong>运行 Linux 工具和应用程序</strong>:WSL 2 支持在 Windows 上直接运行各种 Linux 工具和应用程序,如:Docker、数据库、编程语言环境等。</li></ul></li></ul><h3 id="_7-1-2-wsl2-的安装" tabindex="-1">7.1.2 WSL2 的安装 <a class="header-anchor" href="#_7-1-2-wsl2-的安装" aria-label="Permalink to "7.1.2 WSL2 的安装""></a></h3><ul><li>① BIOS 或 UEFI 中,开启虚拟化:步骤略。</li></ul><p><img src="/coa6/assets/139.BasYWvkM.png" alt=""></p><ul><li>② 查看是否开启了虚拟化:</li></ul><p><img src="/coa6/assets/140.CjFxJpBr.png" alt=""></p><ul><li>③ 启用适用于 Linux 的 Windows 子系统:</li></ul><div class="language-powershell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">powershell</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;">dism.exe</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> /</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">online </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">enable-feature</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> /</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">featurename:Microsoft</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">Windows</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">Subsystem</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">Linux </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">all </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">norestart</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>以管理员身份打开 PowerShell 并运行,执行完上述命令之后,如果提示需要重启计算机,那就重启计算机。</p></div><p><img src="/coa6/assets/141.Dm5Jspvp.gif" alt=""></p><ul><li>④ 启用虚拟机功能:</li></ul><div class="language-powershell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">powershell</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;">dism.exe</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> /</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">online </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">enable-feature</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> /</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">featurename:VirtualMachinePlatform </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">all </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">norestart</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>以管理员身份打开 PowerShell 并运行,执行完上述命令之后,如果提示需要重启计算机,那就重启计算机。</p></div><p><img src="/coa6/assets/142.1krCh8cy.gif" alt=""></p><ul><li>⑤ 更新 Linux 内核包:</li></ul><div class="language-powershell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">powershell</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;">wsl </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">--</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">update</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>wsl2 的最新 Linux 内核包托管在 GitHub 上,某些国家可能会污染 Github 相关的域名,那么就需要手动下载,然后安装即可,下载地址在<a href="https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi" target="_blank" rel="noreferrer">这里</a>。</p></div><p><img src="/coa6/assets/143.DOSyahv7.gif" alt=""></p><ul><li>⑥ 将 wsl2 设置为默认版本:</li></ul><div class="language-powershell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">powershell</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;">wsl </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">--</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">set-default</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">version </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/coa6/assets/144.BHEvX_FI.gif" alt=""></p><ul><li>⑦ 查看官方在线支持的 Linux 版本:</li></ul><div class="language-powershell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">powershell</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;">wsl </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">--</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">list </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">--</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">online</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/coa6/assets/145.DFA0g1_d.gif" alt=""></p><ul><li>⑧ 安装指定版本的 Linux :</li></ul><div class="language-powershell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">powershell</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;">wsl </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">--</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">install Ubuntu</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">24.04</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>官方支持的 Linux 版本,托管在 Github 上,某些国家可能会污染 Github 的域名;此时,要么走科学上网,要么在 <code>Microsoft Store</code> 中搜索并安装。</p></div><p><img src="/coa6/assets/146.D50nO5eA.gif" alt=""></p><ul><li>⑨ 在 Microsoft Store 中搜索并安装(可选):</li></ul><p><img src="/coa6/assets/147.cAvG1Qfq.png" alt=""></p><ul><li>⑩ 查询本地安装的 Linux 版本:</li></ul><div class="language-powershell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">powershell</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;">wsl </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">--</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">list</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/coa6/assets/148.DpakQFWz.gif" alt=""></p><h3 id="_7-1-3-配置-wsl2" tabindex="-1">7.1.3 配置 WSL2 <a class="header-anchor" href="#_7-1-3-配置-wsl2" aria-label="Permalink to "7.1.3 配置 WSL2""></a></h3><ul><li>本人的安装的是 AlmaLinux9 ,所以需要执行如下命令,以便安装 cmake 相关工具链:</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;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dnf</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:#6A737D;--shiki-dark:#6A737D;"> # 更新包管理器 </span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dnf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> groupinstall</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "Development Tools"</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 安装开发工具包</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dnf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> gcc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> gcc-c++</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 安装GCC相关工具链</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dnf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> cmake</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 安装 cmake</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dnf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> make</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 安装 make</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dnf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> gdb</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 安装 gdb</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></div></div><p><img src="/coa6/assets/149.Bg61j9QI.gif" alt=""></p><ul><li>可以通过 CLion 测试是否安装成功:</li></ul><p><img src="/coa6/assets/150.DPvD9UCw.gif" alt=""></p><h3 id="_7-1-4-配置-wsl2" tabindex="-1">7.1.4 配置 WSL2 <a class="header-anchor" href="#_7-1-4-配置-wsl2" aria-label="Permalink to "7.1.4 配置 WSL2""></a></h3><ul><li>本人的安装的是 Ubuntu 24.04,所以需要执行如下命令,以便安装 cmake 相关工具链:</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;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> apt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> update</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> && </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> apt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> upgrade</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 更新包管理器</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> apt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> build-essential</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 安装开发工具包</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> apt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> gcc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> g++</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 安装 GCC 相关工具链</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> apt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> cmake</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 安装 cmake</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> apt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> gdb</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 安装 gdb</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><p><img src="/coa6/assets/151.Ceu65U_n.gif" alt=""></p><ul><li>可以通过 CLion 测试是否安装成功:</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>默认仓库中的 GDB 的版本会很高,CLion 会不支持,那么就需要手动下载源码,自行编译,本次不再演示!!!</p></div><p><img src="/coa6/assets/152.BWPFRK_8.gif" alt=""></p><h2 id="_7-2-切换-clion-中的-cmake-的工具链" tabindex="-1">7.2 切换 CLion 中的 cmake 的工具链 <a class="header-anchor" href="#_7-2-切换-clion-中的-cmake-的工具链" aria-label="Permalink to "7.2 切换 CLion 中的 cmake 的工具链""></a></h2><ul><li>可以在 CLoin 中切换 cmake 的工具链,以便支持不同平台的 cmake ,即:</li></ul><p><img src="/coa6/assets/153.Ct4TfxPf.gif" alt=""></p><h2 id="_7-3-修改-cmakelists-txt-文件" tabindex="-1">7.3 修改 CMakeLists.txt 文件 <a class="header-anchor" href="#_7-3-修改-cmakelists-txt-文件" aria-label="Permalink to "7.3 修改 CMakeLists.txt 文件""></a></h2><ul><li>前文也提到了,在一个 C 语言项目中,只能有一个 main() 函数;但是,我们可以修改 <code>CMakeLists.txt</code> 文件的内容,以便其支持在一个 C 语言项目中,可以有多个包含 main() 函数的文件,如下所示:</li></ul><p><img src="/coa6/assets/154.zsKtx_jV.png" alt=""></p><ul><li><code>CMakeLists.txt</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>cmake_minimum_required(VERSION 3.10)</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span># 项目名称和版本号</span></span>
|
||||
<span class="line"><span>project(c-study VERSION 1.0 LANGUAGES C)</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span># 设置 C 标准</span></span>
|
||||
<span class="line"><span>set(CMAKE_C_STANDARD 11)</span></span>
|
||||
<span class="line"><span>set(CMAKE_C_STANDARD_REQUIRED True)</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span># 辅助函数,用于递归查找所有源文件</span></span>
|
||||
<span class="line"><span>function(collect_sources result dir)</span></span>
|
||||
<span class="line"><span> file(GLOB_RECURSE new_sources "${dir}/*.c")</span></span>
|
||||
<span class="line"><span> set(${result} ${${result}} ${new_sources} PARENT_SCOPE)</span></span>
|
||||
<span class="line"><span>endfunction()</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span># 查找顶层 include 目录(如果存在)</span></span>
|
||||
<span class="line"><span>if (EXISTS "${CMAKE_SOURCE_DIR}/include")</span></span>
|
||||
<span class="line"><span> include_directories(${CMAKE_SOURCE_DIR}/include)</span></span>
|
||||
<span class="line"><span>endif ()</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span># 查找所有源文件</span></span>
|
||||
<span class="line"><span>set(SOURCES)</span></span>
|
||||
<span class="line"><span>collect_sources(SOURCES ${CMAKE_SOURCE_DIR})</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span># 用于存储已经处理过的可执行文件名,防止重复</span></span>
|
||||
<span class="line"><span>set(EXECUTABLE_NAMES)</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span># 创建可执行文件</span></span>
|
||||
<span class="line"><span>foreach (SOURCE ${SOURCES})</span></span>
|
||||
<span class="line"><span> # 获取文件的相对路径</span></span>
|
||||
<span class="line"><span> file(RELATIVE_PATH REL_PATH ${CMAKE_SOURCE_DIR} ${SOURCE})</span></span>
|
||||
<span class="line"><span> # 将路径中的斜杠替换为下划线,生成唯一的可执行文件名</span></span>
|
||||
<span class="line"><span> string(REPLACE "/" "_" EXECUTABLE_NAME ${REL_PATH})</span></span>
|
||||
<span class="line"><span> string(REPLACE "\\" "_" EXECUTABLE_NAME ${EXECUTABLE_NAME})</span></span>
|
||||
<span class="line"><span> string(REPLACE "." "_" EXECUTABLE_NAME ${EXECUTABLE_NAME})</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span> # 处理与 CMakeLists.txt 文件同名的问题</span></span>
|
||||
<span class="line"><span> if (${EXECUTABLE_NAME} STREQUAL "CMakeLists_txt")</span></span>
|
||||
<span class="line"><span> set(EXECUTABLE_NAME "${EXECUTABLE_NAME}_exec")</span></span>
|
||||
<span class="line"><span> endif ()</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span> # 检查是否已经创建过同名的可执行文件</span></span>
|
||||
<span class="line"><span> if (NOT EXECUTABLE_NAME IN_LIST EXECUTABLE_NAMES)</span></span>
|
||||
<span class="line"><span> list(APPEND EXECUTABLE_NAMES ${EXECUTABLE_NAME})</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span> # 创建可执行文件</span></span>
|
||||
<span class="line"><span> add_executable(${EXECUTABLE_NAME} ${SOURCE})</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span> # 查找源文件所在的目录,并添加为包含目录(头文件可能在同一目录下)</span></span>
|
||||
<span class="line"><span> get_filename_component(DIR ${SOURCE} DIRECTORY)</span></span>
|
||||
<span class="line"><span> target_include_directories(${EXECUTABLE_NAME} PRIVATE ${DIR})</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span> # 检查并添加子目录中的 include 目录(如果存在)</span></span>
|
||||
<span class="line"><span> if (EXISTS "${DIR}/include")</span></span>
|
||||
<span class="line"><span> target_include_directories(${EXECUTABLE_NAME} PRIVATE ${DIR}/include)</span></span>
|
||||
<span class="line"><span> endif ()</span></span>
|
||||
<span class="line"><span> endif ()</span></span>
|
||||
<span class="line"><span>endforeach ()</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="_7-4-配置-clang-format-文件" tabindex="-1">7.4 配置 .clang-format 文件 <a class="header-anchor" href="#_7-4-配置-clang-format-文件" aria-label="Permalink to "7.4 配置 .clang-format 文件""></a></h2><ul><li>配置 <code>.clang-format</code> 格式化文件,以便写代码的时候,可以自动保存并格式化 C 程序代码,如下所示:</li></ul><p><img src="/coa6/assets/155.3oqDAW0w.png" alt=""></p><ul><li><code>.clang-format</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>BasedOnStyle: Google</span></span>
|
||||
<span class="line"><span>IndentWidth: 4</span></span>
|
||||
<span class="line"><span>UseTab: Never</span></span>
|
||||
<span class="line"><span>ColumnLimit: 0</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span># 控制大括号的位置</span></span>
|
||||
<span class="line"><span>BreakBeforeBraces: Attach</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span># 控制空行的使用</span></span>
|
||||
<span class="line"><span>EmptyLineBeforeAccessModifier: Never</span></span>
|
||||
<span class="line"><span>KeepEmptyLinesAtTheStartOfBlocks: true</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span># 控制短函数、短 if 语句和循环的格式</span></span>
|
||||
<span class="line"><span>AllowShortFunctionsOnASingleLine: Empty</span></span>
|
||||
<span class="line"><span>AllowShortIfStatementsOnASingleLine: false</span></span>
|
||||
<span class="line"><span>AllowShortLoopsOnASingleLine: false</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span># 控制其他格式选项</span></span>
|
||||
<span class="line"><span>AlignConsecutiveAssignments: true</span></span>
|
||||
<span class="line"><span>AlignConsecutiveDeclarations: true</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span># 控制注释的格式化</span></span>
|
||||
<span class="line"><span>ReflowComments: true</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span># 控制包含指令的格式化</span></span>
|
||||
<span class="line"><span>IncludeBlocks: Regroup</span></span>
|
||||
<span class="line"><span>SortIncludes: CaseInsensitive</span></span>
|
||||
<span class="line"><span></span></span>
|
||||
<span class="line"><span>SpaceBeforeParens: ControlStatements</span></span>
|
||||
<span class="line"><span>SpacesInParentheses: false</span></span>
|
||||
<span class="line"><span>SpacesInAngles: false</span></span>
|
||||
<span class="line"><span>SpacesInContainerLiterals: false</span></span>
|
||||
<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="/coa6/assets/156.D9TSeAa9.gif" alt=""></p><h2 id="_7-5-配置-gitignore-文件" tabindex="-1">7.5 配置 .gitignore 文件 <a class="header-anchor" href="#_7-5-配置-gitignore-文件" aria-label="Permalink to "7.5 配置 .gitignore 文件""></a></h2><ul><li>需要在项目中,配置 <code>.gitignore</code> 文件,以便在提交代码到 Git 仓库的时候,忽略某些文件或目录,如下所示:</li></ul><p><img src="/coa6/assets/157.CCRgYIVq.png" alt=""></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="_7-6-演示" tabindex="-1">7.6 演示 <a class="header-anchor" href="#_7-6-演示" aria-label="Permalink to "7.6 演示""></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="/coa6/assets/158.C1t2T6FV.gif" alt=""></p><h1 id="第八章-c-语言的编译过程-⭐" tabindex="-1">第八章:C 语言的编译过程(⭐) <a class="header-anchor" href="#第八章-c-语言的编译过程-⭐" aria-label="Permalink to "第八章:C 语言的编译过程(⭐)""></a></h1><h2 id="_8-1-概述" tabindex="-1">8.1 概述 <a class="header-anchor" href="#_8-1-概述" aria-label="Permalink to "8.1 概述""></a></h2><ul><li>C 程序的编译过程,如下所示:</li></ul><p><img src="/coa6/assets/159.Rqa4uHq6.png" alt=""></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><strong>头文件包含</strong>:将头文件的内容插入到源文件中。例如:<code>#include <stdio.h></code>会被替换为<code>stdio.h</code>文件的内容。</p></li><li><p><strong>宏展开</strong>:替换宏定义。例如:<code>#define PI 3.14</code>会将代码中的<code>PI</code>替换为<code>3.14</code>。</p></li><li><p><strong>条件编译</strong>:根据条件指令(如:<code>#ifdef</code>、<code>#ifndef</code>)有选择地编译代码。</p></li><li><p><strong>删除代码中的注释,但是不会进行语法检查</strong>。</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><stdio.h></code> 中的 <code>printf()</code> 函数,这些函数不是程序员自己写的,而是 C 程序库中提供的,因此需要链接。其实,在链接过程中,还会加入启动代码,这个启动代码(和系统相关,Linux 下主要有 crt0.c、crti.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="_8-2-gcc-编译器的介绍" tabindex="-1">8.2 GCC 编译器的介绍 <a class="header-anchor" href="#_8-2-gcc-编译器的介绍" aria-label="Permalink to "8.2 GCC 编译器的介绍""></a></h2><ul><li>编辑器,如:vim 、vscode 等,是指我们用它来编写源程序的(编辑代码),而我们写的代码语句,电脑是不懂的,我们需要把它转成电脑能懂的语句,编译器就是这样的转化工具。换言之,我们用编辑器编写程序,由编译器编译后才可以运行!</li><li>编译器是将易于编写、阅读和维护的高级计算机语言翻译为计算机能解读、运行的低级机器语言的程序。</li><li>gcc(GNU Compiler Collection,GNU 编译器套件),是由 GNU 开发的编程语言编译器。gcc 原本作为 GNU 操作系统的官方编译器,现已被大多数类 Unix 操作系统(如:Linux、BSD、Mac OS X 等)采纳为标准的编译器,gcc 同样适用于微软的 Windows 。</li><li>gcc 最初用于编译 C 语言,随着项目的发展, gcc 已经成为了能够编译 C、C++、Java、Ada、fortran、Object C、Object C++、Go 语言的编译器大家族。</li></ul><h2 id="_8-3-通过-gcc-直接生成可执行文件" tabindex="-1">8.3 通过 gcc 直接生成可执行文件 <a class="header-anchor" href="#_8-3-通过-gcc-直接生成可执行文件" aria-label="Permalink to "8.3 通过 gcc 直接生成可执行文件""></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="/coa6/assets/160.6yQYnjOa.gif" alt=""></p><h2 id="_8-4-通过-gcc-分步编译" tabindex="-1">8.4 通过 gcc 分步编译 <a class="header-anchor" href="#_8-4-通过-gcc-分步编译" aria-label="Permalink to "8.4 通过 gcc 分步编译""></a></h2><h3 id="_8-3-1-概述" tabindex="-1">8.3.1 概述 <a class="header-anchor" href="#_8-3-1-概述" aria-label="Permalink to "8.3.1 概述""></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;">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 style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 通常以 .i 结尾表示这个文件是一个中间状态</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><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;"> -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 style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 在 Linux 中,通常以 .s 结尾;在 Windows 中,通常以 .asm 结尾</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><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;"> -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 style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 在 Linux 中,通常以 .o 结尾;在 Windows 中,通常以 .obj 结尾</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><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;"> 源文件.o</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 源文件.exe</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 在 Linux 中,通常以 .out 结尾;在 Windows 中,通常以 .exe 结尾</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><h3 id="_8-4-2-应用示例" tabindex="-1">8.4.2 应用示例 <a class="header-anchor" href="#_8-4-2-应用示例" aria-label="Permalink to "8.4.2 应用示例""></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;">gcc</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -E</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.i</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/coa6/assets/161.hYR9GiiD.gif" alt=""></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;"> -S</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> HelloWorld.i</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> HelloWorld.s</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/coa6/assets/162.D3b-QIrA.gif" alt=""></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;"> -c</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> HelloWorld.s</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> HelloWorld.o</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="/coa6/assets/163.DGbA6qsW.gif" alt=""></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:#032F62;--shiki-dark:#9ECBFF;"> HelloWorld.o</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="/coa6/assets/164.BToOkxf2.gif" alt=""></p></div></div></main><footer class="VPDocFooter" data-v-39a288b8 data-v-d4a0bba5><!--[--><!--]--><div class="edit-info" data-v-d4a0bba5><!----><div class="last-updated" data-v-d4a0bba5><p class="VPLastUpdated" data-v-d4a0bba5 data-v-7e05ebdb>上次更新: <time datetime="2024-07-11T08:05:05.000Z" data-v-7e05ebdb></time></p></div></div><nav class="prev-next" aria-labelledby="doc-footer-aria-label" data-v-d4a0bba5><span class="visually-hidden" id="doc-footer-aria-label" data-v-d4a0bba5>Pager</span><div class="pager" data-v-d4a0bba5><!----></div><div class="pager" data-v-d4a0bba5><a class="VPLink link pager-link next" href="/coa6/notes/01_c-basic/02_xdx/" data-v-d4a0bba5><!--[--><span class="desc" data-v-d4a0bba5>下一篇</span><span class="title" data-v-d4a0bba5>变量和进制</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("{\"notes_index.md\":\"86O_Lb7b\",\"index.md\":\"LKQAh9T8\",\"notes_01_c-basic_02_xdx_index.md\":\"k6oVENcd\",\"notes_01_c-basic_01_xdx_index.md\":\"D1hb9NAd\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"zh-CN\",\"dir\":\"ltr\",\"title\":\"许大仙\",\"titleTemplate\":\"Hi,终于等到你\",\"description\":\"许大仙前端、Java、大数据、云原生\",\"base\":\"/coa6/\",\"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\":\"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\":\"开源软件\",\"link\":\"https://aexiar.github.io/open-software/notes/\"}],\"sidebar\":{\"/notes/\":[{\"text\":\"C语言基础\",\"collapsed\":true,\"items\":[{\"text\":\"C 语言入门\",\"link\":\"/notes/01_c-basic/01_xdx/\"},{\"text\":\"变量和进制\",\"link\":\"/notes/01_c-basic/02_xdx/\"}]},{\"text\":\"C 语言高级\",\"collapsed\":true,\"items\":[{\"text\":\"初识 C 语言\",\"link\":\"/notes/02_dsa/01_xdx/\"}]},{\"text\":\"C++ 核心编程\",\"collapsed\":true,\"items\":[{\"text\":\"计算机组成原理前言\",\"link\":\"/notes/03_coa/03_xdx/\"}]},{\"text\":\"QT 桌面开发\",\"collapsed\":true,\"items\":[{\"text\":\"操作系统前言\",\"link\":\"/notes/04_os/01_xdx/\"}]},{\"text\":\"Linux 高并发服务器开发\",\"collapsed\":true,\"items\":[{\"text\":\"操作系统前言\",\"link\":\"/notes/04_os/01_xdx/\"}]}]},\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/Aurorxa\"}],\"docFooter\":{\"prev\":\"上一篇\",\"next\":\"下一篇\"},\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2024 许大仙\"},\"outline\":{\"level\":[1,6],\"label\":\"目录\"},\"outlineTitle\":\"当前页大纲\"},\"locales\":{},\"scrollOffset\":134,\"cleanUrls\":false}");</script>
|
||||
|
||||
</body>
|
||||
</html>
|
233
notes/01_c-basic/02_xdx/index.html
Normal file
@ -0,0 +1,233 @@
|
||||
<!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.2.3">
|
||||
<link rel="preload stylesheet" href="/coa6/assets/style.93t0OQ_p.css" as="style">
|
||||
|
||||
<script type="module" src="/coa6/assets/app.BmFonQgT.js"></script>
|
||||
<link rel="preload" href="/coa6/assets/inter-roman-latin.Di8DUHzh.woff2" as="font" type="font/woff2" crossorigin="">
|
||||
<link rel="modulepreload" href="/coa6/assets/chunks/framework.D1oHBMsh.js">
|
||||
<link rel="modulepreload" href="/coa6/assets/chunks/theme.DstJSxiY.js">
|
||||
<link rel="modulepreload" href="/coa6/assets/notes_01_c-basic_02_xdx_index.md.k6oVENcd.lean.js">
|
||||
<link rel="shortcut icon" href="/coa6//favicon.ico">
|
||||
<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-ccf7ddec><div class="wrapper" data-v-ccf7ddec><div class="container" data-v-ccf7ddec><div class="title" data-v-ccf7ddec><div class="VPNavBarTitle has-sidebar" data-v-ccf7ddec data-v-ab179fa1><a class="title" href="/coa6/" data-v-ab179fa1><!--[--><!--]--><!--[--><img class="VPImage logo" src="/coa6/logo.svg" alt data-v-8426fc1a><!--]--><span data-v-ab179fa1>许大仙</span><!--[--><!--]--></a></div></div><div class="content" data-v-ccf7ddec><div class="content-body" data-v-ccf7ddec><!--[--><!--]--><div class="VPNavBarSearch search" data-v-ccf7ddec><!--[--><!----><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-ccf7ddec data-v-7f418b0f><span id="main-nav-aria-label" class="visually-hidden" data-v-7f418b0f>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-7f418b0f 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-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>计组6件套</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/coa6/notes/" tabindex="0" data-v-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>c/c++</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/web-design/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>前端</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/java/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>Java</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/big-data/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>大数据</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/linux/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-7f418b0f 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-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>开源软件</span><!--]--></a><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-ccf7ddec data-v-e6aabb21><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-e6aabb21 data-v-d1f28634 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-d1f28634></span><span class="vpi-moon moon" data-v-d1f28634></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-ccf7ddec 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-ccf7ddec data-v-d0bd9dde 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-e7ea1737><!----><!--[--><!--[--><!----><div class="group" data-v-d0bd9dde><div class="item appearance" data-v-d0bd9dde><p class="label" data-v-d0bd9dde>Appearance</p><div class="appearance-action" data-v-d0bd9dde><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-d0bd9dde data-v-d1f28634 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-d1f28634></span><span class="vpi-moon moon" data-v-d1f28634></span><!--]--></span></span></button></div></div></div><div class="group" data-v-d0bd9dde><div class="item social-links" data-v-d0bd9dde><div class="VPSocialLinks social-links-list" data-v-d0bd9dde 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-ccf7ddec 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-ccf7ddec><div class="divider-line" data-v-ccf7ddec></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-575e6a36><div class="curtain" data-v-575e6a36></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-575e6a36><span class="visually-hidden" id="sidebar-aria-label" data-v-575e6a36> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="group" data-v-575e6a36><section class="VPSidebarItem level-0 collapsible has-active" data-v-575e6a36 data-v-b8d55f3b><div class="item" role="button" tabindex="0" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><h2 class="text" data-v-b8d55f3b>C语言基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b8d55f3b><span class="vpi-chevron-right caret-icon" data-v-b8d55f3b></span></div></div><div class="items" data-v-b8d55f3b><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/coa6/notes/01_c-basic/01_xdx/" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>C 语言入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/coa6/notes/01_c-basic/02_xdx/" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>变量和进制</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-575e6a36><section class="VPSidebarItem level-0 collapsible collapsed" data-v-575e6a36 data-v-b8d55f3b><div class="item" role="button" tabindex="0" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><h2 class="text" data-v-b8d55f3b>C 语言高级</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b8d55f3b><span class="vpi-chevron-right caret-icon" data-v-b8d55f3b></span></div></div><div class="items" data-v-b8d55f3b><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/coa6/notes/02_dsa/01_xdx/" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>初识 C 语言</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-575e6a36><section class="VPSidebarItem level-0 collapsible collapsed" data-v-575e6a36 data-v-b8d55f3b><div class="item" role="button" tabindex="0" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><h2 class="text" data-v-b8d55f3b>C++ 核心编程</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b8d55f3b><span class="vpi-chevron-right caret-icon" data-v-b8d55f3b></span></div></div><div class="items" data-v-b8d55f3b><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/coa6/notes/03_coa/03_xdx/" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>计算机组成原理前言</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-575e6a36><section class="VPSidebarItem level-0 collapsible collapsed" data-v-575e6a36 data-v-b8d55f3b><div class="item" role="button" tabindex="0" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><h2 class="text" data-v-b8d55f3b>QT 桌面开发</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b8d55f3b><span class="vpi-chevron-right caret-icon" data-v-b8d55f3b></span></div></div><div class="items" data-v-b8d55f3b><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/coa6/notes/04_os/01_xdx/" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>操作系统前言</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-575e6a36><section class="VPSidebarItem level-0 collapsible collapsed" data-v-575e6a36 data-v-b8d55f3b><div class="item" role="button" tabindex="0" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><h2 class="text" data-v-b8d55f3b>Linux 高并发服务器开发</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b8d55f3b><span class="vpi-chevron-right caret-icon" data-v-b8d55f3b></span></div></div><div class="items" data-v-b8d55f3b><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/coa6/notes/04_os/01_xdx/" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>操作系统前言</p><!--]--></a><!----></div><!----></div><!--]--></div></section></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 _coa6_notes_01_c-basic_02_xdx_" data-v-39a288b8><div><h1 id="第一章-变量-⭐" tabindex="-1">第一章:变量(⭐) <a class="header-anchor" href="#第一章-变量-⭐" aria-label="Permalink to "第一章:变量(⭐)""></a></h1><h2 id="_1-1-程序中变化的数据" tabindex="-1">1.1 程序中变化的数据 <a class="header-anchor" href="#_1-1-程序中变化的数据" aria-label="Permalink to "1.1 程序中变化的数据""></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="/coa6/assets/1.CXNJqOOc.png" alt=""></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 "1.2 变量""></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="/coa6/assets/2.E0LS08Y5.png" alt=""></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 "1.3 变量的声明和使用""></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><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;"> <stdio.h></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;"> // 声明一个整型变量,取名为 a</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>
|
||||
<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;"> 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;">"a = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, a);</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;"> <stdio.h></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;"> // 声明一个整型变量,取名为 b ,并直接赋值(初始化,实际开发中最为常用)</span></span>
|
||||
<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;"> 200</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;"> // 修改变量 b 的值,将变量 a 的值赋值给变量 b</span></span>
|
||||
<span class="line"><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;"> 300</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;">"b= </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</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></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;"> <stdio.h></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;"> c1 </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;">, c2 </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;">, c3 </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;">"c1 = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, c1);</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"c2 = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, c2);</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"c3 = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, 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></div></div><h2 id="_1-4-输出变量" tabindex="-1">1.4 输出变量 <a class="header-anchor" href="#_1-4-输出变量" aria-label="Permalink to "1.4 输出变量""></a></h2><ul><li>在计算机中,所谓的<code>输入</code>和<code>输出</code>都是以计算机(CPU 和内存)为主体而言的,即:</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>输入:从输入设备(键盘、鼠标、扫描仪)向计算机输入数据。</p><p>输出:从计算机向外部输出设备(显示器、打印机)输出数据。</p></div><p><img src="/coa6/assets/3.XcPl7d9s.png" alt=""></p><ul><li>在 C 语言中,提供了 <code>printf()</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;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">__format</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><ul><li><code>printf</code> 的标准含义是格式化输出文本,来源于 <code>print formatted(格式化打印)</code>的缩写,其语法规则,如下所示:</li></ul><p><img src="/coa6/assets/4.DL02VQMp.png" alt=""></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>格式化字符串:是使用双引号括起来的字符串,里面包含了普通的字符串和格式占位符。</li><li>格式占位符(格式声明符):由 <code>%</code> 和<code>格式字符</code>组成,作用是将输出的数据转换为指定的格式后输出,这里的 <code>%d</code> 表示整数。</li><li>输出列表:是程序要输出的一些数据,可以是常量、变量或表达式,需要和格式占位符一一对应。</li></ul></div><ul><li><p>在计算机中,二进制、八进制、十进制以及十六进制的英文名称和缩写,如下所示:</p><ul><li>二进制(binary),缩写是 bin。</li><li>八进制(octal),缩写是 oct。</li><li>十进制(decimal),缩写是 dec。</li><li>十六进制(Hexadecimal),缩写是 hex。</li></ul></li><li><p>其实,我们也可以在 Windows 系统中的计算器中来看到,即:</p></li></ul><p><img src="/coa6/assets/5.Dr67r_Ws.png" alt=""></p><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p>在生活中的 decimal 是小数的意思;但是,在 C 语言中,decimal 的完整含义是 decimal integer ,即十进制整数。</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;"> <stdio.h></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;"> 18</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;"> // 使用输出语句,将变量 num 的值输出,其中 %d 表示输出的是整数</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</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;">"</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></div></div><h2 id="_1-5-输入数据赋值给变量" tabindex="-1">1.5 输入数据赋值给变量 <a class="header-anchor" href="#_1-5-输入数据赋值给变量" aria-label="Permalink to "1.5 输入数据赋值给变量""></a></h2><ul><li>在 C 语言中,提供了 <code>scanf()</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;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">__format</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><ul><li>其语法规则,如下所示:</li></ul><p><img src="/coa6/assets/6.C5XiXNVN.png" alt=""></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p><code>&age</code>、<code>&num</code> 中的 <code>&</code>是寻址操作符,<code>&age</code> 表示变量 <code>age</code> 在内存中的地址。</p></div><div class="caution custom-block github-alert"><p class="custom-block-title">CAUTION</p><p></p><ul><li><p>① scanf() 函数中的 <code>%d</code>,如果是连着写,即:<code>%d%d</code>,那么在输入数据的时候,数据之间不可以使用逗号<code>,</code>分隔,只能使用空白字符(空格、tab 键或回车键),即:<code>2空格3tab</code>或<code>2tab3回车</code>等。</p></li><li><p>② 如果是 <code>%d,%d</code>,则输入的时候需要加上逗号<code>,</code>,即:<code>2,3</code>。</p></li><li><p>③ 如果是 <code>%d %d</code>,则输入的时候需要加上空格,即:<code>2空格3</code>。</p></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;"> <stdio.h></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;"> float</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> radius;</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;">"请输入一个半径:"</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;">"</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%f</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</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;">radius);</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;"> area </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 3.1415926</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> radius </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> radius;</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;">"半径是</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%f</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">的圆的面积是</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%.2lf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, radius, area);</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;"> <stdio.h></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>
|
||||
<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;">"请输入一个整数:"</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;">"</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</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;">num);</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;"> absNum;</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;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
|
||||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> absNum </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;">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:#24292E;--shiki-dark:#E1E4E8;"> absNum </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;"> }</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;">"</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:#24292E;--shiki-dark:#E1E4E8;">, num, absNum);</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;"> <stdio.h></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;"> a, b, c;</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"请输入整数 a 、b 和 c 的值:"</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;">"</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> %d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> %d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</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:#D73A49;--shiki-dark:#F97583;">&</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">b, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&</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;"> 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:#24292E;--shiki-dark:#E1E4E8;"> a </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> b </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> c;</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;">"</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;"> = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, a, b, c, result);</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><h2 id="_1-6-标识符" tabindex="-1">1.6 标识符 <a class="header-anchor" href="#_1-6-标识符" aria-label="Permalink to "1.6 标识符""></a></h2><h3 id="_1-6-1-概述" tabindex="-1">1.6.1 概述 <a class="header-anchor" href="#_1-6-1-概述" aria-label="Permalink to "1.6.1 概述""></a></h3><ul><li>在 C 语言中,变量、函数、数组名、结构体等要素命名的时候使用的字符序列,称为标识符。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>在上世纪 60 - 70 年代的时候,因为国家贫穷,人民生活不富裕等原因,家长虽然会给孩子取名为:<code>张建国</code>、<code>李华强</code>等;但是,也会取小名为<code>二狗子</code>、<code>狗剩</code>等,目的是希望孩子能健康成长(养活),像 <code>张建国</code>、<code>李华强</code>、<code>二狗子</code>、<code>狗剩</code>都是名字(标识符),伴随人的一生。</p></div><h3 id="_1-6-2-标识符的命名规范" tabindex="-1">1.6.2 标识符的命名规范 <a class="header-anchor" href="#_1-6-2-标识符的命名规范" aria-label="Permalink to "1.6.2 标识符的命名规范""></a></h3><ul><li><p>强制规范:</p><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><p>建议规范:</p><ul><li>① 为了提高阅读性,使用有意义的单词,见名知意,如:sum,name,max,year 等。</li><li>② 使用下划线连接多个单词组成的标识符,如:max_classes_per_student 等。</li><li>③ 多个单词组成的标识符,除了使用下划线连接,也可以使用小驼峰命名法,除第一个单词外,后续单词的首字母大写,如: studentId、student_name 等。</li><li>④ 不要出现仅靠大小写区分不同的标识符,如:name、Name 容易混淆。</li><li>⑤ 系统内部使用了一些下划线开头的标识符,如:C99 标准添加的类型 <code>_Bool</code>,为防止冲突,建议开发者尽量避免使用下划线开头的标识符。</li></ul></li><li><p>示例:合法(不一定建议)的标识符</p></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>a、BOOK_sun、MAX_SIZE、Mouse、student23、Football、FOOTBALL、max、_add、num_1、sum_of_numbers</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><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>$zj、3sum、ab#cd、23student、Foot-baii、s.com、b&c、j**p、book-1、tax rate、don't</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><h3 id="_1-6-3-关键字" tabindex="-1">1.6.3 关键字 <a class="header-anchor" href="#_1-6-3-关键字" aria-label="Permalink to "1.6.3 关键字""></a></h3><ul><li>C 语言中的关键字是编译器<code>预定义</code>的<code>保留字</code>,它们有<code>特定</code>的<code>含义</code>和<code>用途</code>,用于控制程序的结构和执行。</li><li>C80 和 C90 (ANSI C)定义的关键字,如下所示:</li></ul><table tabindex="0"><thead><tr><th>类型(功能)</th><th>具体关键字</th></tr></thead><tbody><tr><td>数据类型关键字</td><td><code>char</code>、<code>double</code>、<code>float</code>、<code>int</code>、<code>long</code>、<code>short</code>、<code>signed</code>、<code>unsigned</code>、<code>void</code></td></tr><tr><td>存储类说明符关键字</td><td><code>auto</code>、<code>extern</code>、<code>register</code>、<code>static</code>、<code>typedef</code>、<code>volatile</code>、<code>const</code></td></tr><tr><td>控制语句关键字</td><td><code>break</code>、<code>case</code>、<code>continue</code>、<code>default</code>、<code>do</code>、<code>else</code>、<code>for</code>、<code>goto</code>、<code>if</code>、<code>return</code>、<code>switch</code>、<code>while</code></td></tr><tr><td>结构体、联合体和枚举关键字</td><td><code>enum</code>、<code>struct</code>、<code>union</code></td></tr><tr><td>其他关键字</td><td><code>sizeof</code></td></tr></tbody></table><ul><li>C99 新增的关键字,如下所示:</li></ul><table tabindex="0"><thead><tr><th>类型(功能)</th><th>具体关键字</th></tr></thead><tbody><tr><td>数据类型关键字</td><td><code>_Bool</code>、<code>_Complex</code>、<code>_Imaginary</code></td></tr><tr><td>存储类说明符关键字</td><td><code>inline</code>、<code>restrict</code></td></tr><tr><td>其他关键字</td><td><code>_Complex</code>、 <code>_Imaginary</code></td></tr></tbody></table><ul><li>C11 新增的关键字,如下所示:</li></ul><table tabindex="0"><thead><tr><th>类型(功能)</th><th>具体关键字</th></tr></thead><tbody><tr><td>存储类说明符关键字</td><td><code>_Atomic</code></td></tr><tr><td>其他关键字</td><td><code>_Alignas</code>、 <code>_Alignof</code>、 <code>_Generic</code>、 <code>_Noreturn</code>、 <code>_Static_assert</code>、 <code>_Thread_local</code></td></tr></tbody></table><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li>① 关键字不能用作标识符(如:变量名、函数名等)。</li><li>② 不要死记硬背这些关键字,在实际开发中,并不一定全部使用到;而且,在学到后面的时候,会自动记住这些关键字以及对应的含义。</li></ul></div><h1 id="第二章-常量-⭐" tabindex="-1">第二章:常量(⭐) <a class="header-anchor" href="#第二章-常量-⭐" aria-label="Permalink to "第二章:常量(⭐)""></a></h1><h2 id="_2-1-概述" tabindex="-1">2.1 概述 <a class="header-anchor" href="#_2-1-概述" aria-label="Permalink to "2.1 概述""></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>,就是一个常量,其值为 3.1415926 。</li><li>② 在生活中,人类的性别只有<code>男</code>和<code>女</code>;其中,<code>男</code>和<code>女</code>也是常量。</li><li>③ ...</li></ul></div><h2 id="_2-2-常量的分类" tabindex="-1">2.2 常量的分类 <a class="header-anchor" href="#_2-2-常量的分类" aria-label="Permalink to "2.2 常量的分类""></a></h2><ul><li>在 C 语言中的变量的分类,如下所示: <ul><li>① 字面量常量。</li><li>② 标识符常量: <ul><li><code>#define</code> 宏定义的标识符常量。</li><li><code>const</code> 关键字修饰的标识符常量。</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>所谓的<code>字面量常量</code>,就是可以直接使用的常量,不需要声明或定义,包括:整数常量、浮点数常量以及字符常量。</li><li>所谓的<code>标识符常量</code>,就是使用标识符来作为常量名,包括: <code>#define</code> 宏定义的标识符常量、<code>const</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;"> <stdio.h></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:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
|
||||
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 'A'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
|
||||
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 12.3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
|
||||
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "你好"</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></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;"> <stdio.h></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:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</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;">"</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;">"字符常量 =》</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%c\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'A'</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;">"浮点数常量 =》</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%f\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">12.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;">"字符串常量 =》</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%s\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"你好"</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></div></div><h2 id="_2-3-使用-define-定义常量" tabindex="-1">2.3 使用 #define 定义常量 <a class="header-anchor" href="#_2-3-使用-define-定义常量" aria-label="Permalink to "2.3 使用 #define 定义常量""></a></h2><ul><li><code>#define</code> 来定义常量,也叫作宏定义,就是用一个标识符来表示一个常量值,如果在后面的代码中出现了该标识符,那么编译时就全部替换成指定的常量值,即用宏体替换所有宏名,简称<code>宏替换</code>。</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:#24292E;--shiki-dark:#E1E4E8;">#define 常量名 常量值</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="caution custom-block github-alert"><p class="custom-block-title">CAUTION</p><p></p><ul><li>① 其实<code>宏定义</code>的常量的<code>执行时机</code>是在<code>预处理</code>阶段,将所有<code>宏常量</code>替换完毕,才会继续编译代码。</li><li>② 不要以 <code>;</code> 结尾,如果有 <code>;</code> ,分号也会成为常量值的一部分。</li><li>③ <code># define</code> 必须写在 <code>main</code> 函数的外面!!!</li><li>④ <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;"> <stdio.h></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;"> PI</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 3.1415926</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;"> double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> radius </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2.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;"> double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> area </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> PI </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> radius </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> radius;</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;">"半径为</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%lf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">的圆的面积是</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%.2lf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, radius, area);</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><h2 id="_2-4-const-关键字" tabindex="-1">2.4 const 关键字 <a class="header-anchor" href="#_2-4-const-关键字" aria-label="Permalink to "2.4 const 关键字""></a></h2><ul><li>C99 标准新增,这种方式跟定义一个变量是类似的;只不过,需要在变量的数据类型前加上 <code>const</code> 关键字。</li><li>和使用 <code>#define定义宏常量</code>相比,const 定义的常量有详细的数据类型,而且会在编译阶段进行安全检查,在运行时才完成替换,所以会更加安全和方便。</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;">const</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></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</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;"> <stdio.h></span></span>
|
||||
<span class="line"></span>
|
||||
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> PI </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 3.1415926</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:#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;"> double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> radius </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2.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;"> double</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> area </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> PI </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> radius </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> radius;</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;">"半径为</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%lf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">的圆的面积是</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%.2lf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, radius, area);</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><h2 id="_2-5-枚举常量" tabindex="-1">2.5 枚举常量 <a class="header-anchor" href="#_2-5-枚举常量" aria-label="Permalink to "2.5 枚举常量""></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;">enum</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 枚举常量 {</span></span>
|
||||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> xxx </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;"> yyy;</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>① 默认情况下,枚举常量是从 0 开始递增的。</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;"> <stdio.h></span></span>
|
||||
<span class="line"></span>
|
||||
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">enum</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> sex {</span></span>
|
||||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> MALE </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;"> FEMALE </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;">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;">"</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, MALE);</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</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;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, FEMALE);</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;"> <stdio.h></span></span>
|
||||
<span class="line"></span>
|
||||
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">enum</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Sex {</span></span>
|
||||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> MALE </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;"> FEMALE </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;">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;"> enum</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Sex sex;</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;">"请输入性别(1 表示男性, 2 表示女性):"</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;">"</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</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;">sex);</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</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;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, sex);</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-6-defind-定义常量-vs-const-定义常量" tabindex="-1">2.6 #defind 定义常量 VS const 定义常量 <a class="header-anchor" href="#_2-6-defind-定义常量-vs-const-定义常量" aria-label="Permalink to "2.6 #defind 定义常量 VS const 定义常量""></a></h2><ul><li>① 执行时机:<code>#define</code> 是预处理指令,在编译<code>之前</code>执行;<code>const</code> 是关键字,在编译<code>过程</code>中执行。</li><li>② 类型检查:<code>#define</code> 定义常量<code>不用指定类型</code>,<code>不进行类型检查</code>,只是简单地文本替换;<code>const</code> 定义常量<code>需要指定数据类型</code>,<code>会进行类型检查</code>,类型安全性更强。</li></ul><h1 id="第三章-二进制" tabindex="-1">第三章:二进制 <a class="header-anchor" href="#第三章-二进制" aria-label="Permalink to "第三章:二进制""></a></h1><h2 id="_3-1-概述" tabindex="-1">3.1 概述 <a class="header-anchor" href="#_3-1-概述" aria-label="Permalink to "3.1 概述""></a></h2><ul><li>计算机的底层只有<code>二进制</code>,即计算机中<code>运算</code>和<code>存储</code>的<code>所有数据</code>都需要转换为<code>二进制</code>,包括:数字、字符、图片、视频等。</li></ul><p><img src="/coa6/assets/7.DO8XxSV6.jpg" alt=""></p><ul><li>之前,我们也提到现代的计算机(量子计算机除外)几乎都遵循<code>冯·诺依曼</code>体系结构,其理论要点如下: <ul><li>① <strong>存储程序</strong>:<code>程序指令</code>和<code>数据</code>都存储在计算机的内存中,这使得程序可以在运行时修改。</li><li>② <strong>二进制逻辑</strong>:所有数据和指令都以<code>二进制</code>形式表示。</li><li>③ <strong>顺序执行</strong>:指令按照它们在内存中的顺序执行,但可以有条件地改变执行顺序。</li><li>④ <strong>五大部件</strong>:计算机由<code>运算器</code>、<code>控制器</code>、<code>存储器</code>、<code>输入设备</code>和<code>输出设备</code>组成。</li><li>⑤ <strong>指令结构</strong>:指令由操作码和地址码组成,操作码指示要执行的操作,地址码指示操作数的位置。</li><li>⑥ <strong>中心化控制</strong>:计算机的控制单元(CPU)负责解释和执行指令,控制数据流。</li></ul></li><li>所以,再次论证了为什么计算机只能识别二进制。</li></ul><h2 id="_3-2-进制" tabindex="-1">3.2 进制 <a class="header-anchor" href="#_3-2-进制" aria-label="Permalink to "3.2 进制""></a></h2><h3 id="_3-2-1-常见的进制" tabindex="-1">3.2.1 常见的进制 <a class="header-anchor" href="#_3-2-1-常见的进制" aria-label="Permalink to "3.2.1 常见的进制""></a></h3><ul><li>在生活中,我们最为常用的进制就是<code>十进制</code>,其规则是<code>满 10 进 1</code> ,即:</li></ul><p><img src="/coa6/assets/8.CUXrdefp.jpeg" alt=""></p><ul><li>在计算机中,常见的进制有<code>二进制</code>、<code>八进制</code>和<code>十六进制</code>,即: <ul><li>二进制:只能 0 和 1 ,满 2 进 1 。</li><li>八进制:0 ~ 7 ,满 8 进 1 。</li><li>十六进制:0 ~ 9 以及 A ~ F ,满 16 进 1 。</li></ul></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>在十六进制中,除了 0 到 9 这十个数字之外,还引入了字母,以便表示超过 9 的值。字母 A 对应十进制的 10 ,字母 B 对应十进制的 11 ,以此类推,字母 F 对应十进制的 15。</p></div><ul><li>进制的换算举例,如下所示:</li></ul><table tabindex="0"><thead><tr><th>十进制</th><th>二进制</th><th>八进制</th><th>十六进制</th></tr></thead><tbody><tr><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>2</td><td>10</td><td>2</td><td>2</td></tr><tr><td>3</td><td>11</td><td>3</td><td>3</td></tr><tr><td>4</td><td>100</td><td>4</td><td>4</td></tr><tr><td>5</td><td>101</td><td>5</td><td>5</td></tr><tr><td>6</td><td>110</td><td>6</td><td>6</td></tr><tr><td>7</td><td>111</td><td>7</td><td>7</td></tr><tr><td>8</td><td>1000</td><td>10</td><td>8</td></tr><tr><td>9</td><td>1001</td><td>11</td><td>9</td></tr><tr><td>10</td><td>1010</td><td>12</td><td>a 或 A</td></tr><tr><td>11</td><td>1011</td><td>13</td><td>b 或 B</td></tr><tr><td>12</td><td>1100</td><td>14</td><td>c 或 C</td></tr><tr><td>13</td><td>1101</td><td>15</td><td>d 或 D</td></tr><tr><td>14</td><td>1110</td><td>16</td><td>e 或 E</td></tr><tr><td>15</td><td>1111</td><td>17</td><td>f 或 F</td></tr><tr><td>16</td><td>10000</td><td>20</td><td>10</td></tr><tr><td>...</td><td>...</td><td>...</td><td>...</td></tr></tbody></table><ul><li>二进制和十六进制的关系:十六进制是以 16 为基数的进制系统,16 在二进制中表示为 ( 2^4 ),即:一个十六进制可以表示 4 位二进制。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>十六进制的范围是:0 ~ F (0 ~ 15)对应的二进制数的范围是:0000 ~ 1111 (0 ~ 15)。</p></div><ul><li>每个十六进制数都可以映射到一个唯一的 4 位二进制数,即:</li></ul><table tabindex="0"><thead><tr><th>十六进制</th><th>二进制</th></tr></thead><tbody><tr><td>0</td><td>0000</td></tr><tr><td>1</td><td>0001</td></tr><tr><td>2</td><td>0010</td></tr><tr><td>3</td><td>0011</td></tr><tr><td>4</td><td>0100</td></tr><tr><td>5</td><td>0101</td></tr><tr><td>6</td><td>0110</td></tr><tr><td>7</td><td>0111</td></tr><tr><td>8</td><td>1000</td></tr><tr><td>9</td><td>1001</td></tr><tr><td>A</td><td>1010</td></tr><tr><td>B</td><td>1011</td></tr><tr><td>C</td><td>1100</td></tr><tr><td>D</td><td>1101</td></tr><tr><td>E</td><td>1110</td></tr><tr><td>F</td><td>1111</td></tr></tbody></table><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>由此可见,每个十六进制数字确实由 4 位二进制数表示。</p></div><ul><li>二进制和八进制的关系:八进制是以 8 为基数的进制系统,8 在二进制中表示为 ( 2^3 );即:一个八进制位可以表示 3 个二进制位。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>八进制的范围是:0 ~ 7 对应的二进制数的范围是:000 ~ 111。</p></div><ul><li>每个八进制数位都可以映射到一个唯一的 3 位二进制数,即:</li></ul><table tabindex="0"><thead><tr><th>八进制</th><th>二进制</th></tr></thead><tbody><tr><td>0</td><td>000</td></tr><tr><td>1</td><td>001</td></tr><tr><td>2</td><td>010</td></tr><tr><td>3</td><td>011</td></tr><tr><td>4</td><td>100</td></tr><tr><td>5</td><td>101</td></tr><tr><td>6</td><td>110</td></tr><tr><td>7</td><td>111</td></tr></tbody></table><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>由此可见,每个八进制数字确实由 3 位二进制数表示。</p></div><h3 id="_3-2-2-c-语言中如何表示不同进制的整数" tabindex="-1">3.2.2 C 语言中如何表示不同进制的整数? <a class="header-anchor" href="#_3-2-2-c-语言中如何表示不同进制的整数" aria-label="Permalink to "3.2.2 C 语言中如何表示不同进制的整数?""></a></h3><ul><li><p>规则如下:</p><ul><li>在 C 语言中,如果是<code>二进制</code>(字面常量),则需要在二进制整数前加上 <code>0b</code> 或 <code>0B</code> 。</li><li>在 C 语言中,如果是<code>八进制</code>(字面常量),则需要在八进制整数前加上 <code>0</code> 。</li><li>在 C 语言中,如果是<code>十进制</code>(字面常量),正常数字表示即可。</li><li>在 C 语言中,如果是<code>十六进制</code>(字面常量),则需要在十六进制整数前加上 <code>0x</code>或<code>0X</code> 。</li></ul></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;"> <stdio.h></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;"> num1 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> 0b</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10100110</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;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num2 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> 0</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">717563</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;"> int</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;"> 1000</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;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> num4 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> 0x</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">af72</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;">"num1 = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num1);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // num1 = 166</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"num2 = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num2);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // num2 = 237427</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"num3 = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num3);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // num3 = 1000</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"num4 = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num4);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // num4 = 44914</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 "3.2.3 输出格式""></a></h3><ul><li>在 C 语言中,可以使用不同的<code>格式占位符</code>来<code>输出</code>不同<code>进制</code>的整数,如下所示: <ul><li><code>%d</code>:十进制整数。</li><li><code>%o</code> :八进制整数。</li><li><code>%x</code>:十六进制整数。</li><li><code>%#o</code> :显示前缀 <code>0</code> 的八进制整数。</li><li><code>%#x</code> :显示前缀 <code>0x</code> 的十六进制整数。</li><li><code>%#X</code> :显示前缀 <code>0X</code> 的十六进制整数。</li></ul></li></ul><div class="caution custom-block github-alert"><p class="custom-block-title">CAUTION</p><p></p><p>C 语言中没有输出二进制数的格式占位符!!!</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;"> <stdio.h></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;"> 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;">"</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;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num, num);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 100 的十进制整数: 100</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</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;">%o\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num, num);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 100 的八进制整数: 144</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</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;">%x\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num, num);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 100 的十六进制整数: 64</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</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;">%#o\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num, num);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 100 的八进制(前缀)整数: 0144</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</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;">%#x\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num, num);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 100 的十六进制(前缀)整数: 0x64</span></span>
|
||||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</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;">%#X\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, num, num);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 100 的十六进制(前缀)整数: 0X64</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="_3-3-进制的转换" tabindex="-1">3.3 进制的转换 <a class="header-anchor" href="#_3-3-进制的转换" aria-label="Permalink to "3.3 进制的转换""></a></h2><h3 id="_3-3-1-概述" tabindex="-1">3.3.1 概述 <a class="header-anchor" href="#_3-3-1-概述" aria-label="Permalink to "3.3.1 概述""></a></h3><ul><li>不同进制的转换,如下所示:</li></ul><p><img src="/coa6/assets/9.uqLiL_yu.png" alt=""></p><ul><li>在计算机中,数据是从右往左的方式排列的;其中,最右边的是低位,最左边的是高位,即:</li></ul><p><img src="/coa6/assets/10.CkykpHY2.png" alt=""></p><h3 id="_3-3-2-二进制和十进制的转换" tabindex="-1">3.3.2 二进制和十进制的转换 <a class="header-anchor" href="#_3-3-2-二进制和十进制的转换" aria-label="Permalink to "3.3.2 二进制和十进制的转换""></a></h3><h4 id="_3-3-2-1-二进制转换为十进制" tabindex="-1">3.3.2.1 二进制转换为十进制 <a class="header-anchor" href="#_3-3-2-1-二进制转换为十进制" aria-label="Permalink to "3.3.2.1 二进制转换为十进制""></a></h4><ul><li>规则:从最低位开始,将每个位上的数提取出来,乘以 2 的 (位数 - 1 )次方,然后求和。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 在学术界,将这种计算规则,称为<code>位权相加法</code>。</li><li>② <code>八进制转换为十进制</code>、<code>十六进制转换为十进制</code>和<code>二进制转换为十进制</code>的算法相同!!!</li></ul></div><ul><li>示例:十进制转十进制</li></ul><p><img src="/coa6/assets/11.DV1YbrOP.png" alt=""></p><ul><li>示例:二进制转十进制</li></ul><p><img src="/coa6/assets/12.AHNJT9TV.png" alt=""></p><h4 id="_3-3-2-2-十进制转换二进制" tabindex="-1">3.3.2.2 十进制转换二进制 <a class="header-anchor" href="#_3-3-2-2-十进制转换二进制" aria-label="Permalink to "3.3.2.2 十进制转换二进制""></a></h4><ul><li>规则:将该数不断除以 2 ,直到商为 0 为止,然后将每步得到的余数倒过来,就是对应的二进制。</li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li>① 在学术界,将这种计算规则,称为<code>短除法</code>或<code>连续除2取余法</code>。</li><li>② 很好理解,只有不断地除以 2 ,就能保证最大的数字不超过 2 ,这不就是二进制(只能有 0 或 1)吗?</li><li>③ <code>八进制转换为二进制</code>、<code>十六进制转换为二进制</code>和<code>十进制转换为二进制</code>的算法相同!!!</li></ul></div><ul><li>示例:十进制转十进制</li></ul><p><img src="/coa6/assets/13.Bs-MOwx2.png" alt=""></p><ul><li>示例:十进制转二进制</li></ul><p><img src="/coa6/assets/14.StzjmBz-.png" alt=""></p><h3 id="_3-3-3-二进制转八进制" tabindex="-1">3.3.3 二进制转八进制 <a class="header-anchor" href="#_3-3-3-二进制转八进制" aria-label="Permalink to "3.3.3 二进制转八进制""></a></h3><ul><li><p>规则:每 3 位二进制就是一个八进制。</p></li><li><p>示例:011 101 001 -> 351</p></li></ul><p><img src="/coa6/assets/15.C0wVWaxD.png" alt=""></p><h3 id="_3-3-4-二进制转十六进制" tabindex="-1">3.3.4 二进制转十六进制 <a class="header-anchor" href="#_3-3-4-二进制转十六进制" aria-label="Permalink to "3.3.4 二进制转十六进制""></a></h3><ul><li><p>规则:每 4 位二进制就是一个八进制。</p></li><li><p>示例:1110 1001 -> 0xE9</p></li></ul><p><img src="/coa6/assets/16.LXJMAihe.png" alt=""></p><h2 id="_3-4-原码、反码和补码" tabindex="-1">3.4 原码、反码和补码 <a class="header-anchor" href="#_3-4-原码、反码和补码" aria-label="Permalink to "3.4 原码、反码和补码""></a></h2><h3 id="_3-4-1-概述" tabindex="-1">3.4.1 概述 <a class="header-anchor" href="#_3-4-1-概述" aria-label="Permalink to "3.4.1 概述""></a></h3><ul><li>机器数:一个数在计算机的存储形式是二进制,我们称这些二进制数为机器数。机器数可以是有符号的,用机器数的最高位来存放符号位,0 表示正数,1 表示负数。</li></ul><p><img src="/coa6/assets/17._UTCq3PD.png" alt=""></p><ul><li>真值:因为机器数带有符号位,所以机器数的形式值不等于其真实表示的值(真值),以机器数 1000 0001 为例,其真正表示的值(首位是符号位)为 -1,而形式值却是 129 ,因此将带有符号位的机器数的真正表示的值称为机器数的真值。</li></ul><p><img src="/coa6/assets/18.BjQ5kBL-.png" alt=""></p><h3 id="_3-4-2-原码" tabindex="-1">3.4.2 原码 <a class="header-anchor" href="#_3-4-2-原码" aria-label="Permalink to "3.4.2 原码""></a></h3><ul><li>原码的表示与机器数真值表示的一样,即用第一位表示符号,其余位表示数值。</li><li>规则: <ul><li>正数的<code>原码</code>是它本身对应的二进制数,符号位是 0 。</li><li>负数的<code>原码</code>是它本身绝对值对应的二进制数,但是符号位是 1 。</li></ul></li><li>+1 的原码,使用 8 位二进数来表示,就是:</li></ul><table tabindex="0"><thead><tr><th>十进制数</th><th>原码(8位二进制数)</th></tr></thead><tbody><tr><td>+1</td><td><code>0</code>000 0001</td></tr></tbody></table><ul><li>-1 的原码,使用 8 位二进数来表示,就是:</li></ul><table tabindex="0"><thead><tr><th>十进制数</th><th>原码(8位二进制数)</th></tr></thead><tbody><tr><td>-1</td><td><code>1</code>000 0001</td></tr></tbody></table><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p>按照原码的规则,会出现 <code>+0</code> 和 <code>-0</code> 的情况,即:<code>0</code>000 0000(+0)、<code>1</code>000 0000(-0),显然不符合实际情况;所以,计算机底层虽然存储和计算的都是二进数,但显然不是原码。</p></div><h3 id="_3-4-3-反码" tabindex="-1">3.4.3 反码 <a class="header-anchor" href="#_3-4-3-反码" aria-label="Permalink to "3.4.3 反码""></a></h3><ul><li><p>规则:</p><ul><li>正数的反码和它的原码相同。</li><li>负数的反码是在其原码的基础上,符号位不变,其余各位取反。</li></ul></li><li><p>+1 的反码,使用 8 位二进数来表示,就是:</p></li></ul><table tabindex="0"><thead><tr><th>十进制数</th><th>原码(8位二进制数)</th><th>反码(8位二进制数)</th></tr></thead><tbody><tr><td>+1</td><td><code>0</code>000 0001</td><td><code>0</code>000 0001</td></tr></tbody></table><ul><li>-1 的反码,使用 8 位二进数来表示,就是:</li></ul><table tabindex="0"><thead><tr><th>十进制数</th><th>原码(8位二进制数)</th><th>反码(8位二进制数)</th></tr></thead><tbody><tr><td>-1</td><td><code>1</code>000 0001</td><td><code>1</code>111 1110</td></tr></tbody></table><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p>按照反码的规则,如果是 <code>+0</code>,对应的原码是 <code>0</code>000 0000;那么,其反码还是 <code>0</code>000 0000 ;如果是 <code>-0</code>,对应的原码是 <code>1</code>000 0000,其反码是 <code>1</code>111 1111,显然不符合实际情况;所以,计算机底层虽然存储和计算的都是二进数,但显然不是反码。</p></div><h3 id="_3-4-4-补码" tabindex="-1">3.4.4 补码 <a class="header-anchor" href="#_3-4-4-补码" aria-label="Permalink to "3.4.4 补码""></a></h3><ul><li><p>规则:</p><ul><li>正数的补码和它的原码相同。</li><li>负数的补码是在其反码的基础上 + 1 。</li></ul></li><li><p>+1 的补码,使用 8 位二进数来表示,就是:</p></li></ul><table tabindex="0"><thead><tr><th>十进制数</th><th>原码(8位二进制数)</th><th>反码(8位二进制数)</th><th>补码(8位二进制数)</th></tr></thead><tbody><tr><td>+1</td><td><code>0</code>000 0001</td><td><code>0</code>000 0001</td><td><code>0</code>000 0001</td></tr></tbody></table><ul><li>-1 的补码,使用 8 位二进数来表示,就是:</li></ul><table tabindex="0"><thead><tr><th>十进制数</th><th>原码(8位二进制数)</th><th>反码(8位二进制数)</th><th>补码(8位二进制数)</th></tr></thead><tbody><tr><td>-1</td><td><code>1</code>000 0001</td><td><code>1</code>111 1110</td><td><code>1</code>111 1111</td></tr></tbody></table><ul><li>如果 0 ,按照 <code>+0</code> 的情况进行处理,即:</li></ul><p><img src="/coa6/assets/19.COIOzcmT.png" alt=""></p><ul><li>如果 0 ,按照 <code>-0</code> 的情况进行处理,即:</li></ul><p><img src="/coa6/assets/20.Cu__mjav.png" alt=""></p><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li>① 补码表示法解决了<code>原码</code>和<code>反码</code>存在的<code>两种</code>零(<code>+0</code> 和 <code>-0</code>)的问题,即:在补码表示法中,只有<code>一个</code>零,即 0000 0000。</li><li>② 补码使得<code>加法运算</code>和<code>减法运算</code>可以统一处理,通过将减法运算<code>转换</code>为加法运算,可以简化硬件设计,提高了运算效率。</li><li>③ 计算机底层<code>存储</code>和<code>计算</code>的都是<code>二进数的补码</code>。</li></ul></div><h3 id="_3-4-5-总结" tabindex="-1">3.4.5 总结 <a class="header-anchor" href="#_3-4-5-总结" aria-label="Permalink to "3.4.5 总结""></a></h3><ul><li>① 正数的原码、反码和补码都是一样的,三码合一。</li><li>② 负数的反码是在其原码的基础上,按位取反(0 变 1 ,1 变 0 ),符号位不变;负数的补码是其反码 + 1 。</li><li>③ 0 的补码是 0 。</li></ul><h2 id="_3-5-计算机底层为什么使用补码" tabindex="-1">3.5 计算机底层为什么使用补码? <a class="header-anchor" href="#_3-5-计算机底层为什么使用补码" aria-label="Permalink to "3.5 计算机底层为什么使用补码?""></a></h2><ul><li>如果计算是 <code>2 - 2</code> ,那么可以转换为 <code>2 + (-2)</code>,这样计算机内部在处理<code>减法计算</code>的时候,就会将其转换为<code>加法计算</code>的形式,以简化硬件设计和提高计算效率。</li><li><code>最高位</code>表示<code>符号位</code>,由于符号位的存在,如果使用<code>原码</code>来计算,就会导致<code>计算结果不正确</code>,即:</li></ul><p><img src="/coa6/assets/21.BX_KzkHt.png" alt=""></p><ul><li><code>补码</code>的设计可以巧妙的让<code>符号位</code>也参与计算,并且可以得到<code>正确的计算结果</code>,即:</li></ul><p><img src="/coa6/assets/22.COt_QxSP.png" alt=""></p></div></div></main><footer class="VPDocFooter" data-v-39a288b8 data-v-d4a0bba5><!--[--><!--]--><div class="edit-info" data-v-d4a0bba5><!----><div class="last-updated" data-v-d4a0bba5><p class="VPLastUpdated" data-v-d4a0bba5 data-v-7e05ebdb>上次更新: <time datetime="2024-07-11T08:05:05.000Z" data-v-7e05ebdb></time></p></div></div><nav class="prev-next" aria-labelledby="doc-footer-aria-label" data-v-d4a0bba5><span class="visually-hidden" id="doc-footer-aria-label" data-v-d4a0bba5>Pager</span><div class="pager" data-v-d4a0bba5><a class="VPLink link pager-link prev" href="/coa6/notes/01_c-basic/01_xdx/" data-v-d4a0bba5><!--[--><span class="desc" data-v-d4a0bba5>上一篇</span><span class="title" data-v-d4a0bba5>C 语言入门</span><!--]--></a></div><div class="pager" data-v-d4a0bba5><a class="VPLink link pager-link next" href="/coa6/notes/02_dsa/01_xdx/" data-v-d4a0bba5><!--[--><span class="desc" data-v-d4a0bba5>下一篇</span><span class="title" data-v-d4a0bba5>初识 C 语言</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("{\"notes_index.md\":\"86O_Lb7b\",\"index.md\":\"LKQAh9T8\",\"notes_01_c-basic_02_xdx_index.md\":\"k6oVENcd\",\"notes_01_c-basic_01_xdx_index.md\":\"D1hb9NAd\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"zh-CN\",\"dir\":\"ltr\",\"title\":\"许大仙\",\"titleTemplate\":\"Hi,终于等到你\",\"description\":\"许大仙前端、Java、大数据、云原生\",\"base\":\"/coa6/\",\"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\":\"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\":\"开源软件\",\"link\":\"https://aexiar.github.io/open-software/notes/\"}],\"sidebar\":{\"/notes/\":[{\"text\":\"C语言基础\",\"collapsed\":true,\"items\":[{\"text\":\"C 语言入门\",\"link\":\"/notes/01_c-basic/01_xdx/\"},{\"text\":\"变量和进制\",\"link\":\"/notes/01_c-basic/02_xdx/\"}]},{\"text\":\"C 语言高级\",\"collapsed\":true,\"items\":[{\"text\":\"初识 C 语言\",\"link\":\"/notes/02_dsa/01_xdx/\"}]},{\"text\":\"C++ 核心编程\",\"collapsed\":true,\"items\":[{\"text\":\"计算机组成原理前言\",\"link\":\"/notes/03_coa/03_xdx/\"}]},{\"text\":\"QT 桌面开发\",\"collapsed\":true,\"items\":[{\"text\":\"操作系统前言\",\"link\":\"/notes/04_os/01_xdx/\"}]},{\"text\":\"Linux 高并发服务器开发\",\"collapsed\":true,\"items\":[{\"text\":\"操作系统前言\",\"link\":\"/notes/04_os/01_xdx/\"}]}]},\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/Aurorxa\"}],\"docFooter\":{\"prev\":\"上一篇\",\"next\":\"下一篇\"},\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2024 许大仙\"},\"outline\":{\"level\":[1,6],\"label\":\"目录\"},\"outlineTitle\":\"当前页大纲\"},\"locales\":{},\"scrollOffset\":134,\"cleanUrls\":false}");</script>
|
||||
|
||||
</body>
|
||||
</html>
|
27
notes/index.html
Normal file
@ -0,0 +1,27 @@
|
||||
<!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.2.3">
|
||||
<link rel="preload stylesheet" href="/coa6/assets/style.93t0OQ_p.css" as="style">
|
||||
|
||||
<script type="module" src="/coa6/assets/app.BmFonQgT.js"></script>
|
||||
<link rel="preload" href="/coa6/assets/inter-roman-latin.Di8DUHzh.woff2" as="font" type="font/woff2" crossorigin="">
|
||||
<link rel="modulepreload" href="/coa6/assets/chunks/framework.D1oHBMsh.js">
|
||||
<link rel="modulepreload" href="/coa6/assets/chunks/theme.DstJSxiY.js">
|
||||
<link rel="modulepreload" href="/coa6/assets/notes_index.md.86O_Lb7b.lean.js">
|
||||
<link rel="shortcut icon" href="/coa6//favicon.ico">
|
||||
<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-ccf7ddec><div class="wrapper" data-v-ccf7ddec><div class="container" data-v-ccf7ddec><div class="title" data-v-ccf7ddec><div class="VPNavBarTitle has-sidebar" data-v-ccf7ddec data-v-ab179fa1><a class="title" href="/coa6/" data-v-ab179fa1><!--[--><!--]--><!--[--><img class="VPImage logo" src="/coa6/logo.svg" alt data-v-8426fc1a><!--]--><span data-v-ab179fa1>许大仙</span><!--[--><!--]--></a></div></div><div class="content" data-v-ccf7ddec><div class="content-body" data-v-ccf7ddec><!--[--><!--]--><div class="VPNavBarSearch search" data-v-ccf7ddec><!--[--><!----><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-ccf7ddec data-v-7f418b0f><span id="main-nav-aria-label" class="visually-hidden" data-v-7f418b0f>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-7f418b0f 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-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>计组6件套</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink active" href="/coa6/notes/" tabindex="0" data-v-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>c/c++</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/web-design/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>前端</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/java/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>Java</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/big-data/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>大数据</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://aexiar.github.io/linux/notes/" target="_blank" rel="noreferrer" tabindex="0" data-v-7f418b0f 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-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>开源软件</span><!--]--></a><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-ccf7ddec data-v-e6aabb21><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-e6aabb21 data-v-d1f28634 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-d1f28634></span><span class="vpi-moon moon" data-v-d1f28634></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-ccf7ddec 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-ccf7ddec data-v-d0bd9dde 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-e7ea1737><!----><!--[--><!--[--><!----><div class="group" data-v-d0bd9dde><div class="item appearance" data-v-d0bd9dde><p class="label" data-v-d0bd9dde>Appearance</p><div class="appearance-action" data-v-d0bd9dde><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-d0bd9dde data-v-d1f28634 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-d1f28634></span><span class="vpi-moon moon" data-v-d1f28634></span><!--]--></span></span></button></div></div></div><div class="group" data-v-d0bd9dde><div class="item social-links" data-v-d0bd9dde><div class="VPSocialLinks social-links-list" data-v-d0bd9dde 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-ccf7ddec 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-ccf7ddec><div class="divider-line" data-v-ccf7ddec></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-575e6a36><div class="curtain" data-v-575e6a36></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-575e6a36><span class="visually-hidden" id="sidebar-aria-label" data-v-575e6a36> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="group" data-v-575e6a36><section class="VPSidebarItem level-0 collapsible collapsed" data-v-575e6a36 data-v-b8d55f3b><div class="item" role="button" tabindex="0" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><h2 class="text" data-v-b8d55f3b>C语言基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b8d55f3b><span class="vpi-chevron-right caret-icon" data-v-b8d55f3b></span></div></div><div class="items" data-v-b8d55f3b><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/coa6/notes/01_c-basic/01_xdx/" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>C 语言入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/coa6/notes/01_c-basic/02_xdx/" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>变量和进制</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-575e6a36><section class="VPSidebarItem level-0 collapsible collapsed" data-v-575e6a36 data-v-b8d55f3b><div class="item" role="button" tabindex="0" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><h2 class="text" data-v-b8d55f3b>C 语言高级</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b8d55f3b><span class="vpi-chevron-right caret-icon" data-v-b8d55f3b></span></div></div><div class="items" data-v-b8d55f3b><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/coa6/notes/02_dsa/01_xdx/" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>初识 C 语言</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-575e6a36><section class="VPSidebarItem level-0 collapsible collapsed" data-v-575e6a36 data-v-b8d55f3b><div class="item" role="button" tabindex="0" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><h2 class="text" data-v-b8d55f3b>C++ 核心编程</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b8d55f3b><span class="vpi-chevron-right caret-icon" data-v-b8d55f3b></span></div></div><div class="items" data-v-b8d55f3b><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/coa6/notes/03_coa/03_xdx/" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>计算机组成原理前言</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-575e6a36><section class="VPSidebarItem level-0 collapsible collapsed" data-v-575e6a36 data-v-b8d55f3b><div class="item" role="button" tabindex="0" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><h2 class="text" data-v-b8d55f3b>QT 桌面开发</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b8d55f3b><span class="vpi-chevron-right caret-icon" data-v-b8d55f3b></span></div></div><div class="items" data-v-b8d55f3b><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/coa6/notes/04_os/01_xdx/" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>操作系统前言</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-575e6a36><section class="VPSidebarItem level-0 collapsible collapsed" data-v-575e6a36 data-v-b8d55f3b><div class="item" role="button" tabindex="0" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><h2 class="text" data-v-b8d55f3b>Linux 高并发服务器开发</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-b8d55f3b><span class="vpi-chevron-right caret-icon" data-v-b8d55f3b></span></div></div><div class="items" data-v-b8d55f3b><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/coa6/notes/04_os/01_xdx/" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>操作系统前言</p><!--]--></a><!----></div><!----></div><!--]--></div></section></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 _coa6_notes_" data-v-39a288b8><div><h1 id="计算机基础知识" tabindex="-1">计算机基础知识 <a class="header-anchor" href="#计算机基础知识" aria-label="Permalink to "计算机基础知识""></a></h1><hr><iframe src="https://roadmap.sh/r/embed?id=668c68522c7edd3e44893630" width="115%" height="500px" frameBorder="0"></iframe></div></div></main><footer class="VPDocFooter" data-v-39a288b8 data-v-d4a0bba5><!--[--><!--]--><div class="edit-info" data-v-d4a0bba5><!----><div class="last-updated" data-v-d4a0bba5><p class="VPLastUpdated" data-v-d4a0bba5 data-v-7e05ebdb>上次更新: <time datetime="2024-07-11T08:05:05.000Z" data-v-7e05ebdb></time></p></div></div><nav class="prev-next" aria-labelledby="doc-footer-aria-label" data-v-d4a0bba5><span class="visually-hidden" id="doc-footer-aria-label" data-v-d4a0bba5>Pager</span><div class="pager" data-v-d4a0bba5><!----></div><div class="pager" data-v-d4a0bba5><a class="VPLink link pager-link next" href="/coa6/notes/01_c-basic/01_xdx/" data-v-d4a0bba5><!--[--><span class="desc" data-v-d4a0bba5>下一篇</span><span class="title" data-v-d4a0bba5>C 语言入门</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("{\"notes_index.md\":\"86O_Lb7b\",\"index.md\":\"LKQAh9T8\",\"notes_01_c-basic_02_xdx_index.md\":\"k6oVENcd\",\"notes_01_c-basic_01_xdx_index.md\":\"D1hb9NAd\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"zh-CN\",\"dir\":\"ltr\",\"title\":\"许大仙\",\"titleTemplate\":\"Hi,终于等到你\",\"description\":\"许大仙前端、Java、大数据、云原生\",\"base\":\"/coa6/\",\"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\":\"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\":\"开源软件\",\"link\":\"https://aexiar.github.io/open-software/notes/\"}],\"sidebar\":{\"/notes/\":[{\"text\":\"C语言基础\",\"collapsed\":true,\"items\":[{\"text\":\"C 语言入门\",\"link\":\"/notes/01_c-basic/01_xdx/\"},{\"text\":\"变量和进制\",\"link\":\"/notes/01_c-basic/02_xdx/\"}]},{\"text\":\"C 语言高级\",\"collapsed\":true,\"items\":[{\"text\":\"初识 C 语言\",\"link\":\"/notes/02_dsa/01_xdx/\"}]},{\"text\":\"C++ 核心编程\",\"collapsed\":true,\"items\":[{\"text\":\"计算机组成原理前言\",\"link\":\"/notes/03_coa/03_xdx/\"}]},{\"text\":\"QT 桌面开发\",\"collapsed\":true,\"items\":[{\"text\":\"操作系统前言\",\"link\":\"/notes/04_os/01_xdx/\"}]},{\"text\":\"Linux 高并发服务器开发\",\"collapsed\":true,\"items\":[{\"text\":\"操作系统前言\",\"link\":\"/notes/04_os/01_xdx/\"}]}]},\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/Aurorxa\"}],\"docFooter\":{\"prev\":\"上一篇\",\"next\":\"下一篇\"},\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2024 许大仙\"},\"outline\":{\"level\":[1,6],\"label\":\"目录\"},\"outlineTitle\":\"当前页大纲\"},\"locales\":{},\"scrollOffset\":134,\"cleanUrls\":false}");</script>
|
||||
|
||||
</body>
|
||||
</html>
|