Answer the question
In order to leave comments, you need to log in
What is the correct way to create an array of strings?
Good day!
What advantage does a two-dimensional array have over an array of pointers to these strings?
As for me, the array of pointers looks nice, but for some reason in the lessons that I saw use a two-dimensional array.
Answer the question
In order to leave comments, you need to log in
Usually arrays are used to be traversed in a row. Modern processors work very well if the data is consecutive in memory. Therefore, a two-dimensional character array will run faster due to the cache. If these are pointers to strings, then each string lies anywhere.
However, if there are a lot of strings, they are large, you often refer to random ones, and they are given to you from the outside, then the pointer approach is preferable. In this case, when you create an array, you will not copy the strings. And the advantage of the cache in such work with the array is negligible.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question