Home > Article > Backend Development > How to define string array in c language
Characteristics of string arrays: Each element in the array is a string, but the length of each string is different.
The two definition methods in C language are as follows:
1. Define a two-dimensional array of type char
This method is by defining A two-dimensional array of char type is implemented. Each string in the array can be obtained through the row index of the two-dimensional array. The size of the column limits the maximum number of characters that each string can contain, so this definition is used. , the size of the column must not be less than the maximum length of all strings in the array.
Sample code:
When fetching each string in the array, just index the row directly.
2. Define an array of pointers to the char type
This method is implemented by defining an array of pointers to the char type. Each element in the array is is a pointer through which each string in the array can be obtained.
Sample code:
Recommended tutorial: c language tutorial
The above is the detailed content of How to define string array in c language. For more information, please follow other related articles on the PHP Chinese website!