[語法] 看不懂的程式碼

看板C_and_CPP (C/C++)作者 (呆呆)時間16年前 (2009/05/18 22:17), 編輯推噓2(207)
留言9則, 3人參與, 最新討論串1/1
關於動態記憶分布: #include <iostream> #include <cstdlib> using namespace std; int main() { unsigned int no_of_size; int *ptint,i; cout<<"Input no of data :\n"; cin>>no_of_size; ptint=(int *)calloc(no_of_size,sizeof(int)); if( ptint == NULL) { cout<<"No memory space for input data \n"; exit(1); } cout<<"Input the integer data \n"; for(i=0; i< no_of_size; ++i) cin>>*(ptint+i); cout<<"The input integer data are :\n"; for(i=0; i < no_of_size; ++i) cout<<*(ptint+i)<<", "; cout<<"\n"; free(ptint); return 0; } 我真的看不懂這個程式在做什麼... T^T 煩請高手解惑 感謝 m(_ _)m -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.218.78

05/18 22:41, , 1F
哪邊看不懂
05/18 22:41, 1F

05/18 22:44, , 2F
ptint=(int *)calloc(no_of_size,sizeof(int));
05/18 22:44, 2F

05/18 22:46, , 3F
*(ptint+i)是指ptint[i]嗎?
05/18 22:46, 3F

05/18 22:54, , 4F
if( ptint == NULL)
05/18 22:54, 4F

05/19 01:00, , 5F
取得no_of_size個int大小的空間assign給ptint這個指標
05/19 01:00, 5F

05/19 01:00, , 6F
05/19 01:00, 6F

05/19 01:01, , 7F
如果沒要到空間ptint會是NULL
05/19 01:01, 7F

05/19 01:01, , 8F
要檢查 that all
05/19 01:01, 8F

05/19 06:15, , 9F
感謝樓上!
05/19 06:15, 9F
文章代碼(AID): #1A4MuI4c (C_and_CPP)
文章代碼(AID): #1A4MuI4c (C_and_CPP)