Array of Strings in C

A string is an array of characters in C programming. An array of strings can be created using a multi-dimensional array.


However, this is not recommended because of the way it gets stored in memory.


A 4x10 array is initialised and the characters are stored as above. The empty boxes represent the allocated but unused memory.

A better memory-optimised way of doing this is as below.


Now the strings are stored in memory as follows,


We can also see that the logic to print the array can be written in fewer lines of code.

The output for both the programs shown above is the same.


Individual characters of each string of a string array can be accessed as follows.


The above program prints the first letter of each string in the string array.


Hope this was helpful for beginners to C programming. :)

The text editor I used is Sublime Text. Download link: https://www.sublimetext.com/download

Comments