2024-07-30 07:13:16 +02:00
<!DOCTYPE html>
< html lang = "zh-CN" dir = "ltr" >
< head >
< meta charset = "utf-8" >
< title > 第一章:颇具争议的指针 | Hi, 终于等到你< / title >
< meta name = "description" content = "许大仙前端、Java、大数据、云原生" >
< meta name = "generator" content = "VitePress v1.3.1" >
< link rel = "preload stylesheet" href = "/c/assets/style.DF3ihcHP.css" as = "style" >
2024-07-30 10:30:13 +02:00
< script type = "module" src = "/c/assets/app.C_wOJaqz.js" > < / script >
2024-07-30 07:13:16 +02:00
< link rel = "preload" href = "/c/assets/inter-roman-latin.Di8DUHzh.woff2" as = "font" type = "font/woff2" crossorigin = "" >
< link rel = "modulepreload" href = "/c/assets/chunks/framework.CZKtKhAm.js" >
2024-07-30 10:30:13 +02:00
< link rel = "modulepreload" href = "/c/assets/chunks/theme.AcPY-TgI.js" >
2024-07-30 10:11:19 +02:00
< link rel = "modulepreload" href = "/c/assets/notes_01_c-basic_06_xdx_index.md.6QgdiYnS.lean.js" >
2024-07-30 07:13:16 +02:00
< link rel = "shortcut icon" href = "/c//logo.svg" >
< meta name = "viewport" content = "width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no,shrink-to-fit=no" >
< meta name = "keywords" content = "许大仙,许大仙的博客" >
< script id = "check-dark-mode" > ( ( ) => { const e = localStorage . getItem ( "vitepress-theme-appearance" ) || "auto" , a = window . matchMedia ( "(prefers-color-scheme: dark)" ) . matches ; ( ! e || e === "auto" ? a : e === "dark" ) && document . documentElement . classList . add ( "dark" ) } ) ( ) ; < / script >
< script id = "check-mac-os" > document . documentElement . classList . toggle ( "mac" , /Mac|iPhone|iPod|iPad/i . test ( navigator . platform ) ) ; < / script >
< / head >
< body >
< div id = "app" > < div class = "Layout" data-v-5d98c3a5 > <!-- [ --> <!-- ] --> <!-- [ --> < span tabindex = "-1" data-v-0f60ec36 > < / span > < a href = "#VPContent" class = "VPSkipLink visually-hidden" data-v-0f60ec36 > Skip to content < / a > <!-- ] --> <!-- --> < header class = "VPNav" data-v-5d98c3a5 data-v-ae24b3ad > < div class = "VPNavBar has-sidebar top" data-v-ae24b3ad data-v-6aa21345 > < div class = "wrapper" data-v-6aa21345 > < div class = "container" data-v-6aa21345 > < div class = "title" data-v-6aa21345 > < div class = "VPNavBarTitle has-sidebar" data-v-6aa21345 data-v-ab179fa1 > < a class = "title" href = "/c/" data-v-ab179fa1 > <!-- [ --> <!-- ] --> <!-- [ --> < img class = "VPImage logo" src = "/c/logo.svg" alt data-v-8426fc1a > <!-- ] --> < span data-v-ab179fa1 > 许大仙< / span > <!-- [ --> <!-- ] --> < / a > < / div > < / div > < div class = "content" data-v-6aa21345 > < div class = "content-body" data-v-6aa21345 > <!-- [ --> <!-- ] --> < div class = "VPNavBarSearch search" data-v-6aa21345 > <!-- [ --> <!-- --> < div id = "local-search" > < button type = "button" class = "DocSearch DocSearch-Button" aria-label = "Search" > < span class = "DocSearch-Button-Container" > < span class = "vp-icon DocSearch-Search-Icon" > < / span > < span class = "DocSearch-Button-Placeholder" > Search< / span > < / span > < span class = "DocSearch-Button-Keys" > < kbd class = "DocSearch-Button-Key" > < / kbd > < kbd class = "DocSearch-Button-Key" > K< / kbd > < / span > < / button > < / div > <!-- ] --> < / div > < nav aria-labelledby = "main-nav-aria-label" class = "VPNavBarMenu menu" data-v-6aa21345 data-v-dc692963 > < span id = "main-nav-aria-label" class = "visually-hidden" data-v-dc692963 > Main Navigation < / span > <!-- [ --> <!-- [ --> < a class = "VPLink link vp-external-link-icon VPNavBarMenuLink" href = "https://aexiar.github.io/" target = "_blank" rel = "noreferrer" tabindex = "0" data-v-dc692963 data-v-9c663999 > <!-- [ --> < span data-v-9c663999 > 首页< / span > <!-- ] --> < / a > <!-- ] --> <!-- [ --> < a class = "VPLink link vp-external-link-icon VPNavBarMenuLink" href = "https://aexiar.github.io/coa6/notes/" target = "_blank" rel = "noreferrer" tabindex = "0" data-v-dc692963 data-v-9c663999 > <!-- [ --> < span data-v-9c663999 > 计组6件套< / span > <!-- ] --> < / a > <!-- ] --> <!-- [ --> < div class = "VPFlyout VPNavBarMenuGroup" data-v-dc692963 data-v-b6c34ac9 > < button type = "button" class = "button" aria-haspopup = "true" aria-expanded = "false" data-v-b6c34ac9 > < span class = "text" data-v-b6c34ac9 > <!-- --> < span data-v-b6c34ac9 > 编程语言< / span > < span class = "vpi-chevron-down text-icon" data-v-b6c34ac9 > < / span > < / span > < / button > < div class = "menu" data-v-b6c34ac9 > < div class = "VPMenu" data-v-b6c34ac9 data-v-b98bc113 > < div class = "items" data-v-b98bc113 > <!-- [ --> <!-- [ --> < div class = "VPMenuLink" data-v-b98bc113 data-v-43f1e123 > < a class = "VPLink link" href = "/c/notes/" data-v-43f1e123 > <!-- [ --> c/c++<!-- ] --> < / a > < / div > <!-- ] --> <!-- [ --> < div class = "VPMenuLink" data-v-b98bc113 data-v-43f1e123 > < a class = "VPLink link vp-external-link-icon" href = "https://aexiar.github.io/web-design/notes/" target = "_blank" rel = "noreferrer" data-v-43f1e123 > <!-- [ --> 前端<!-- ] --> < / a > < / div > <!-- ] --> <!-- [ --> < div class = "VPMenuLink" data-v-b98bc113 data-v-43f1e123 > < a class = "VPLink link vp-external-link-icon" href = "https://aexiar.github.io/java/notes/" target = "_blank" rel = "noreferrer" data-v-43f1e123 > <!-- [ --> Java<!-- ] --> < / a > < / div > <!-- ] --> <!-- [ --> < div class = "VPMenuLink" data-v-b98bc113 data-v-43f1e123 > < a class = "VPLink link vp-external-link-icon" href = "https://aexiar.github.io/big-data/notes/" target = "_blank" rel = "noreferrer" data-v-43f1e123 > <!-- [ --> 大数据<!-- ] --> < / a > < / div > <!-- ] --> <!-- [ --> < div class = "VPMenuLink" data-v-b98bc113 data-v-43f1e123 > < a class = "VPLink link vp-external-link-icon" href = "https://aexiar.github.io/linux/notes/" target = "_blank" rel = "noreferrer" data-v-43f1e123 > <!-- [ --> 云原生<!-- ] --> < / a > < / div > <!-- ] --> <!-- [ --> < div class = "VPMenuLink" data-v-b98bc113 data-v-43f1e123 > < a class = "VPLink link vp-external-link-icon" href = "https://aexiar.github.io/go/notes/" target = "_blank" rel = "noreferrer" data-v-43f1e123 > <!-- [ --> Go<!-- ] --> < / a > < / div > <!-- ] --> <!-- [ --> < div class = "VPMenuLink" data-v-b98bc113 data-v-43f1e123 > < a class = "VPLink link vp-external-link-icon" href = "https://aexiar.github.io/python/notes/" target = "_blank" rel = "noreferrer" data-v-43f1e123 > <!-- [ --> Python<!-- ] - -
< 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 23)< / 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 > < / span > < / span >
< span class = "line" > < span > # 检查并添加 module 目录中的所有 C 文件(如果存在)< / span > < / span >
< span class = "line" > < span > if (EXISTS " ${DIR}/module" )< / span > < / span >
< span class = "line" > < span > file(GLOB_RECURSE MODULE_SOURCES " ${DIR}/module/*.c" )< / span > < / span >
< span class = "line" > < span > target_sources(${EXECUTABLE_NAME} PRIVATE ${MODULE_SOURCES})< / span > < / span >
< span class = "line" > < span > endif ()< / span > < / span >
< span class = "line" > < span > endif ()< / span > < / span >
2024-07-30 10:11:19 +02:00
< 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 > < span class = "line-number" > 59< / span > < br > < span class = "line-number" > 60< / span > < br > < span class = "line-number" > 61< / span > < br > < span class = "line-number" > 62< / span > < br > < span class = "line-number" > 63< / span > < br > < span class = "line-number" > 64< / span > < br > < / div > < / div > < ul > < li > 在 CLion 中正常运行代码:< / li > < / ul > < p > < img src = "/c/assets/9.DdSfz-Pf.gif" alt = "" > < / p > < ul > < li > 在 CLion 中通过 valgrind 运行代码:< / li > < / ul > < p > < img src = "/c/assets/10.BMocjVt7.gif" alt = "" > < / p > < h1 id = "第四章-指针的理解和定义-⭐" tabindex = "-1" > 第四章:指针的理解和定义(⭐) < a class = "header-anchor" href = "#第四章-指针的理解和定义-⭐" aria-label = "Permalink to "第四章:指针的理解和定义(⭐)"" > < / 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 > < 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 > < 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 > < p > 在 C 语言中,< code > 普通变量< / code > 是直接存储< code > 数据< / code > 的< code > 变量< / code > 。对于普通变量,支持的操作包括:< / p > < ul > < li > ① < strong > 赋值操作< / strong > :给变量赋值,如:< code > int a = 5< / code > 。< / li > < li > ② < strong > 算术运算< /s
2024-07-30 10:30:13 +02:00
< script > window . _ _VP _HASH _MAP _ _ = JSON . parse ( "{\"index.md\":\"BNNAnhfk\",\"notes_01_c-basic_01_xdx_index.md\":\"DQ3v2Fil\",\"notes_01_c-basic_02_xdx_index.md\":\"BJ3pJ0Cz\",\"notes_01_c-basic_03_xdx_index.md\":\"DIl_eIAg\",\"notes_01_c-basic_04_xdx_index.md\":\"CwyFE3Gl\",\"notes_01_c-basic_05_xdx_index.md\":\"BHSBkPcK\",\"notes_01_c-basic_06_xdx_index.md\":\"6QgdiYnS\",\"notes_index.md\":\"qg0s9W8s\"}" ) ; window . _ _VP _SITE _DATA _ _ = JSON . parse ( "{\"lang\":\"zh-CN\",\"dir\":\"ltr\",\"title\":\"许大仙\",\"titleTemplate\":\"Hi, 终于等到你\",\"description\":\"许大仙前端、Java、大数据、云原生\",\"base\":\"/c/\",\"head\":[],\"router\":{\"prefetchLinks\":true},\"appearance\":true,\"themeConfig\":{\"lastUpdatedText\":\"上次更新\",\"returnToTopLabel\":\"返回顶部\",\"search\":{\"provider\":\"local\"},\"logo\":\"/logo.svg\",\"nav\":[{\"text\":\"首页\",\"link\":\"https://aexiar.github.io/\"},{\"text\":\"计组6件套\",\"link\":\"https://aexiar.github.io/coa6/notes/\"},{\"text\":\"编程语言\",\"items\":[{\"text\":\"c/c++\",\"link\":\"/notes/\"},{\"text\":\"前端\",\"link\":\"https://aexiar.github.io/web-design/notes/\"},{\"text\":\"Java\",\"link\":\"https://aexiar.github.io/java/notes/\"},{\"text\":\"大数据\",\"link\":\"https://aexiar.github.io/big-data/notes/\"},{\"text\":\"云原生\",\"link\":\"https://aexiar.github.io/linux/notes/\"},{\"text\":\"Go\",\"link\":\"https://aexiar.github.io/go/notes/\"},{\"text\":\"Python\",\"link\":\"https://aexiar.github.io/python/notes/\"}]},{\"text\":\"开源软件\",\"link\":\"https://aexiar.github.io/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\":\"数据类型和运算符\",\"link\":\"/notes/01_c-basic/03_xdx/\"},{\"text\":\"流程控制\",\"link\":\"/notes/01_c-basic/04_xdx/\"},{\"text\":\"数组\",\"link\":\"/notes/01_c-basic/05_xdx/\"},{\"text\":\"指针\",\"link\":\"/notes/01_c-basic/06_xdx/\"},{\"text\":\"函数\",\"link\":\"/notes/01_c-basic/07_xdx/\"},{\"text\":\"预处理器\",\"link\":\"/notes/01_c-basic/08_xdx/\"},{\"text\":\"自定义数据类型\",\"link\":\"/notes/01_c-basic/09_xdx/\"},{\"text\":\"字符串和时间\",\"link\":\"/notes/01_c-basic/10_xdx/\"},{\"text\":\"内存管理\",\"link\":\"/notes/01_c-basic/11_xdx/\"},{\"text\":\"文件操作\",\"link\":\"/notes/01_c-basic/12_xdx/\"},{\"text\":\"调试工具和调试技巧( gdb和make) \",\"link\":\"/notes/01_c-basic/13_xdx/\"},{\"text\":\"常用库函数\",\"link\":\"/notes/01_c-basic/14_xdx/\"}]},{\"text\":\"C 语言高级\",\"collapsed\":true,\"items\":[]},{\"text\":\"C++ 核心编程\",\"collapsed\":true,\"items\":[]},{\"text\":\"C++ 标准库\",\"collapsed\":true,\"items\":[]},{\"text\":\"QT 桌面开发\",\"collapsed\":true,\"items\":[]},{\"text\":\"Linux 高并发服务器开发\",\"collapsed\":true,\"items\":[]}]},\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/Aurorxa\"}],\"docFooter\":{\"prev\":\"上一篇\",\"next\":\"下一篇\"},\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2024 许大仙\"},\"outline\":{\"level\":[1,6],\"label\":\"目录\"},\"outlineTitle\":\"当前页大纲\"},\"locales\":{},\"scrollOffset\":134,\"cleanUrls\":false}" ) ; < / script >
2024-07-30 07:13:16 +02:00
< / body >
< / html >