コメントのある行を参照してください:
- 例に括弧を追加すると、配列のすべての内容が出力されるのはなぜですか?
この例では、「one」を出力してから、ゴミを出力します。
#include <iostream>
int main() {
const char* a[3] = { "one", "two", "three" };
const char*(*p)[3] = &a;
for(int i = 0; i < 3; i++) {
std::cout << *p[i] << std::endl; // this line
}
return 0;
}
これに変更した後に動作します:
std::cout << (*p)[i] << std::endl;