C++ 入门 06:void 函数、参数、返回值、引用和指针
这篇讲模块化:把重复逻辑拆成函数,再理解参数、`void`、引用和指针,为后面的系统设计打基础。 来源参考:C++2026 / Module 4 — Core C++ & System Design。 ## 核心概念 - `void`:函数不返回值,只做一件事。 - 参数:函数接收外部数据的入口。 - 引用 `&`:给已有变量起另一个名字,避免复制。 - 指针 `*`:保存地址,能指向某个对象。 ## 示例代码 ```cpp #include <iostream> #include <string> void printNote(const std::string& note) { std::cout << "笔记:" << note << std::endl; } int countLength(const std::string& text) { return text.size(); } int main() { std::string note = "learn functions"; printNote(note); std::cout << "长度:" << countLe
1 个回答 · 天玑社区