row = 3
この例で言いましょう。
int ***s;
// s=[?]
// s is an uninitialized variable.
s = new int **[row];
// s[*] -> [?]
// [?]
// [?]
// s points to the first element of an array of size 3.
// The elements are uninitialized.
*s = new int *[row];
// s=[*] -> [*] -> [?]
// [?] [?]
// [?] [?]
// We've initialized s[0]. It points to another array of size 3.
// All elements of that array are also uninitialized, along with s[1] and s[2].
**s = new int[row];
// s=[*] -> [*] -> [*] -> [?]
// [?] [?] [?]
// [?] [?] [?]
// More of the same. s[0][0] is initialized.
// This last array contains uninitialized ints, not pointers.
***s = 1;
// s=[*] -> [*] -> [*] -> [1]
// [?] [?] [?]
// [?] [?] [?]
// We traverse three levels of pointers (->) and store 1 in the cell.
これらすべてがコンパイルされ、正常に動作するはずです (初期化されていない要素にアクセスしない限り)。
s + 1
最初の配列の 2 番目の要素を指します。
// s=[*] -> [*] -> [*] -> [1]
// s + 1 -> [?] [?] [?]
// [?] [?] [?]
*(s + 1)
は、上の図で が指すセルを[?]
指します。s + 1
このセルは初期化されていません。
**(s + 1)
ガベージ ポインターを逆参照しようとしますが、これは無効です (そしてしばしばクラッシュします)。