OneBite.Dev - Coding blog in a bite size

create an array of string in C

Code snippet on how to create an array of string in C

  char* array[3];
  array[0] = "Hello";
  array[1] = "World";
  array[2] = "!";

This code creates a C array of strings. First, the data type is defined: char*, as an array of strings require characters to be stored. An array is then created with size 3, indicated by the [3]. Each element is then assigned a string, with the string being surrounded by double quotation marks. The individual elements of the array can be accessed using the index, with 0 indicating the first element, 1 indicating the second element, and so on. In this case, the first element of the array is “Hello”, the second element is “World”, and the third element is ”!“. This array could be used for a variety of applications, such as printing a simple message.

c