Home>Article>Backend Development> How to define string array in C language

How to define string array in C language

王林
王林 Original
2020-06-12 15:13:42 35108browse

How to define string array in C language

You can define a string array in the following two ways:

Method 1: By defining a two-dimensional array of type char

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. Therefore, when using this definition method, the column The size of must not be less than the maximum length of all strings in the array.

The definition code is as follows:

How to define string array in C language

When fetching each string in the array, just index the row directly.

Method 2: By defining an array of pointers to char type to achieve

Each element in the array is a pointer, through which the array can be obtained of each string.

The definition code is as follows:

How to define string array in C language

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn