1

What the benefits and disadvantage of using an array of pointers vs a multidimensional array and vica verse in C or C++. They both seem the same to me. For example, take the following

char *people[] = {"Alex", "Tom", "Peter"};

Versus

char people[][9] = {"Alex", "Tom", "Peter"};
Casper Beyer
  • 2,203
  • 2
  • 22
  • 35
user2898696
  • 27
  • 1
  • 4

1 Answers1

5

multidimensional arrays are easier to work with, whereas pointer arrays sometimes result in a faster program.

multidimensional arrays cant be modified, pointer arrays can simply be changed to point elsewhere anytime.

POINTER ARRAYS: pointer arrays MULTIDIMENSIONAL ARRAYS multi-d arrays

Not to mention those unused memory space, such a waste.

justomat
  • 67
  • 1
  • 6
  • 3
    I dont have any photoshop or anything, so paint will do. – justomat Apr 21 '14 at 05:09
  • It is worth noting that it is definitely not a rule that pointer arrays are faster. Sure, they are less wasteful memory-wise, however if you consider the magic of CPU caching, and if your code is more query-heavy than creation-heavy, I would expect multidimensional arrays to totally outspeed pointer arrays. – radrow Aug 10 '23 at 09:16