Home > Article > Backend Development > Understanding char** in C/C
In C and C , char** is a pointer to a pointer of type char. It is commonly used to represent arrays of strings, such as command-line arguments (argv), dynamic arrays of strings, or 2D arrays where each row is a string. Though initially confusing, with some examples, you’ll see how it operates similarly to handling a "table of strings."
What is char* *?
A char* is a pointer to a char, representing a single string.
A char** is a pointer to a char*, which means it points to an array of strings (or an array of char* pointers).
Example:
#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; }
Breakdown:
Visual Representation:
Main Index (char**) → String 1 (char*) → "I love" → String 2 (char*) → "Embedded" → String 3 (char*) → "Systems"
Key Points:
Conclusion:
Working with char** is powerful when handling dynamic arrays, command-line arguments, or multi-dimensional arrays of strings in C/C . Once you understand its structure, it simplifies the process of managing arrays of strings in your programs.
The above is the detailed content of Understanding char** in C/C. For more information, please follow other related articles on the PHP Chinese website!