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.
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.
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
Post a Comment