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.
这是一个悬空指针吗?
int x = 25; int** arr = new int*[5]; *arr[1] = x;
我不知道为什么这不起作用... *arr[1] 只是一个指针,并且指向一个有效的内存地址。
arr[1]是一个int*,并且它是未初始化的。取消引用它是未定义的行为。
arr[1]
int*
你可以说arr[1] = &x;, thenarr[1]将指向xand*arr[1]将是 25。
arr[1] = &x;
x
*arr[1]
完成后不要忘记delete [] arr;。
delete [] arr;