How to define string array in C language

王林
Release: 2020-06-12 15:13:42
Original
35166 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!