How to define string array in c language

王林
Release: 2020-05-12 09:58:25
Original
13171 people have browsed it

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:

How to define string array in c language

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:

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