thought[x]
is an array of chars (which can be implicitly cast to a pointer to a char)
thought
is an array of char arrays (which can be implicitly cast to a pointer to an array of chars)
In C and C++ (barring unusual overloads),
a[b]
is the same as
*(a + b)
. This can be seen any number of ways:
1 2 3 4
|
int foo[5] = {1,2,3,4,5};
cout << foo[2]; // outputs '2'
cout << *(foo+2); // also outputs '2'... it's the same thing as the above line
|
With that in mind,
*(thought[0]+9)
is the same as
thought[0][9]
, it's just an ugly and more confusing way to write it. thought[0][9] gives you the 'k' in "walk".
And therefore,
*(*(thought+0)+5)
is the same as
thought[0][5]
for the same reason. It gives you the space between "Don't" and "walk".
Therefore (Assuming the other errors in this program were fixed), this program would output
k
(that is, k followed by a space).
thought[2][x] and onwards would all be null characters (empty strings). If you partially initialize an array of built-in types, the other elements of that array are automatically zero'd.