在c++和c++中,char**是指向char类型的指针。它通常用于表示字符串数组,例如命令行参数 (argv)、动态字符串数组或每行都是一个字符串的二维数组。尽管一开始会令人困惑,但通过一些示例,您将看到它的操作方式与处理“字符串表”类似。
什么是 char* *?
char* 是指向 char 的指针,代表单个字符串。
char** 是指向 char* 的指针,这意味着它指向一个字符串数组(或一个 char* 指针数组)。
示例:
#include <stdio.h> int main() { char* strings[] = {"i love", "embedded", "systems"}; // create a char** pointer to the strings array char** string_ptr = strings; // access and print the strings using char** for (int i = 0; i < 3; i++) { printf("%s\n", string_ptr[i]); } return 0; }
细分:
视觉表现:
Main Index (char**) → String 1 (char*) → "I love" → String 2 (char*) → "Embedded" → String 3 (char*) → "Systems"
要点:
结论:
立即学习“C++免费学习笔记(深入)”;
在 c/c++ 中处理动态数组、命令行参数或多维字符串数组时,使用 char** 非常强大。一旦您理解了它的结构,它就会简化程序中管理字符串数组的过程。
以上就是理解 C/C++ 中的 char**的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号