Array of Pointers to Strings in C
In this class, we will try to understand the Array of Pointers to Strings in C.
We have already discussed an array of strings in our previous class.
The understanding of the previous class is fundamental because we are considering the same example discussed there.
The image below is the outcome of the previous examples declaration.
In the above image, the extra null characters are created, which is a waste of space.
To avoid the extra space, we have another way which is an Array of Pointers to Strings.
The Array of Pointers to Strings
The image below is the programming example for the array of pointers to strings.
The second line of code represents the declaration of The Array of Pointers to Strings.
The variable four_planets is an array of four elements that are pointers to the string constants.
The image below is the visualization for the Array of Pointers to Strings.
The only difference between the array of pointers to strings and the array of strings is that the array of pointers to strings is string constants.
We can access the string constants, but we can not modify them.
If we need to modify the characters of the strings, then we have to use the array of strings
As they are string constants, they are to be initialized in the declaration.