Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
次のコードを記述し、xcode でブレークポイントを設定します。
#include <iostream> using namespace std; int main(int argc, const char * argv[]) { int array[12]; return 0; //Set breakpoint here }
デバッガー パネルには、最初の 6 つの要素にゼロ以外intの s が含まれていることが示されています。どうしてこれなの?
int
配列を宣言しただけで、初期化していないためです。
宣言すると、特定のメモリ領域が確保されるだけです。その領域にすでに保存されているものは、他の操作/プログラムから残ったものである可能性があります。
C++ コンパイラは、指示しない限り変数を初期化しません。
配列が初期化されていないためです。デバッガー パネルには、その場所に保存されている以前の値が表示されます。