Paul said:
Say I have:
char foo[][];
char** bar;
In my understanding, these two have the same meaning in memory.
Could someone elucidate upon these two types and their meanings?
The first one is an array of arrays of chars and second one is a pointer
to a pointer to a char. By the way, the definition of foo is illegal.
Both may be used the same way by, for example, allocating memory
dynamically and setting bar to have the same representation as foo. But
internally, in memory, they will not be the same. foo will be on the
stack and bar will be on the heap. foo will be continuous and bar will
probably be fragmented. foo will be an automatic object, bar will not
be. As I said, they may be used the same way, but logically, they would
represent different things as std::string::size() and
std::string::length() do the same thing, but have a different meaning.
Also, you could use them in a completly different way. For example, you
could use bar as a plain pointer to a pointer to a char :
void f(char **bar)
{
*bar = new char[10];
}
int main()
{
char *s = 0;
f(&s);
// s now points to a buffer of 10 chars
delete s;
}
Here, bar has the same type, but does not represent an array of arrays.
It all depends on what you do with them.
Jonathan