看板 C_and_CPP 關於我們 聯絡資訊
原本這樣可以: int n=100; double *t t = initialization(n) : double *intitaliztion(int n) { double *t; t = (double*)calloc(n,sizeof(double)); // 下面就設定t array的內容 return t; } === 現在若想要對兩個以上的array做初使設定: int n= 100; double *t, *y; initialization(n, t , y); void initialization(int n,double *t ,double *y) { t = (double*)calloc(n,sizeof(double)); y = (double*)calloc(n,sizeof(double)); //塞值進去t, y array中 return; } 這樣是不行的,debug mode是不會過,release mode會不正確 解決方法是把 calloc那行寫在function外面。但我就想把配置那行 寫在function中啊。。。 請問有無大牛知道要怎做呢,謝謝。 不要和我講寫兩個function。。。。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.167.75.177
TroyLee:參數要帶 ** 02/28 15:01
csihcs:for C++ : void init(int n,double *&t ,double *&y) 03/01 10:21
csihcs:其餘不變 03/01 10:21
csihcs:for C : void init(int n,double **t , double **y) 03/01 10:22
csihcs:init(n, &t , &y); 03/01 10:22
csihcs:*t = (double*)calloc(n,sizeof(double)); 03/01 10:23
aaa12345:for csihcs: if C++,t =(double*)calloc(n,sizeof(do.. 03/01 16:00
aaa12345:u say "其餘不變" sorry! sorry! u are right! 03/01 16:02