2 ms·
> Wasn't that sort of the point or using arrays instead of pointers? There is less dereferencing to get to the data, so you need to dereference fewer pointers.
by eridius 9y ago
> Wasn't that sort of the point or using arrays instead of pointers? There is less dereferencing to get to the data, so you need to dereference fewer pointers.
No, and that's why the article is confusing. It makes it seem like that's true but it's really not.
If you remove everything else and just look at passing the pointer itself, the fundamental difference between the pointer version and the array version is the pointer version isn't constant, and therefore has one level of indirection. This is because you can reassign to the `ptr` variable. But the array is constant, you can't reassign `ary`. All you really have to do here is put `const` on the `ptr` variable and suddenly you get the exact same code. Or in other words,
const char * const ptr = "Foo";
behaves the same way as
const char ary[] = "Foo";
And the only practical difference between the two at this point is how the sizeof() operator works.