[問題] heap curruption

看板C_and_CPP (C/C++)作者 (123)時間14年前 (2012/03/10 20:55), 編輯推噓1(102)
留言3則, 3人參與, 最新討論串1/1
一段很簡單的code.. 用動態陣列 會報This may be due to a corruption of the heap, which indicates a bug in a.exe or any of the DLLs it has loaded. int main(void){ long n; double *P; P = new double[]; double *R; R = new double[]; cout<<"n"; cin>>n; for(long i=0;i<n;i++){ cout<<endl<<"P"<<i<<" ="; cin>>P[i]; } for(long i=0;i<n;i++){ R[i]=100/P[i]; } system("pause"); return 0; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 42.70.0.107

03/10 22:58, , 1F
為何不在得到n之後new double[n]?
03/10 22:58, 1F

03/10 23:53, , 2F
我比較好奇的是 new double[] 這樣會過編譯喔 @@
03/10 23:53, 2F

03/10 23:55, , 3F
我也沒寫過 [] 裡面沒填數字的情況
03/10 23:55, 3F
文章代碼(AID): #1FMqzQy2 (C_and_CPP)
文章代碼(AID): #1FMqzQy2 (C_and_CPP)