Array of Characters (Strings)
There is one popular use of array that is the 1D array of characters that is used to represent the textual data. It is more commonly known as strings. The strings are essentially an array of character that is terminated by a NULL character (‘\0’).
Syntax
char name[] = "this is an example string"
Here, we don’t need to define the size of the array. It will automatically deduce it from the assigned string.
Example
// C++ Program to illlustrate the use of string
#include <stdio.h>
int main()
{
// defining array
char str[] = "This is w3wiki";
printf("%s", str);
return 0;
}
Output
This is w3wiki
To know more about strings, refer to this article – Strings in C
One Dimensional Arrays in C
In C, an array is a collection of elements of the same type stored in contiguous memory locations. This organization allows efficient access to elements using their index. Arrays can also be of different types depending upon the direction/dimension they can store the elements. It can be 1D, 2D, 3D, and more. We generally use only one-dimensional, two-dimensional, and three-dimensional arrays.
In this article, we will learn all about one-dimensional (1D) arrays in C, and see how to use them in our C program.