0
char*s[20] a 1D or a 2D array and why?
8 Answers
+ 6
Shivansh Mathur Please don't ask a question if you think that you know the answer better than everyone who answers it. What you do with an array doesn't change how many dimensions it has.
"Arrays can be single or multidimensional. The number of subscript or index determines the dimensions of the array."
https://overiq.com/c-programming-101/one-dimensional-array-in-c/
+ 1
it's one dimensional array of size 20 and it holds character pointers
+ 1
arrays are essentially pointers so you can do s[0][3] but it doesn't mean its 2D array, only one dimension is on stack
s[0][3] => *(*(s+0)+3)
what we are doing is simple pointer arithmetic.
correct me if I am wrong
+ 1
If we go by actual definition of array, its members are stored on consecutive memory location. then *s[20] is 1D, yes individual characters are consecutive but last char pointer of s[0] and s[1] are not consecutive. similarly **s is not array
0
you're correct code learner
- 1
No, it can be both 1D and 2D array depending on what you're doing with it
- 1
If it is being used to store individual bytes then it is 2D