How do you declare an array of strings in the C language?

In C language, you can declare a string array using two different methods.

  1. Using an array of characters:
char strArray[10];  // 声明一个有10个元素的字符数组
  1. “Using an array of pointers:”
char *strArray[10];  // 声明一个有10个指针元素的数组

When declaring a string array using an array of pointers, make sure to allocate memory space for each pointer element in the subsequent code, and assign the address of the string to the corresponding pointer element. For example,

char *strArray[10];
strArray[0] = "Hello";
strArray[1] = "World";

This declares an array of strings that contains two strings.

bannerAds