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"};
1
  • 3
    "visa verse" is the 4-line part of a banker's poem about credit cards. The word you're looking for is "vice versa". Commented Apr 21, 2014 at 4:39

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I dont have any photoshop or anything, so paint will do.
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.