C言語なら俺に聞け(入門編)Part 129 [転載禁止]©5ch.io
■ このスレッドは過去ログ倉庫に格納されています
0320デフォルトの名無しさん
2015/06/23(火) 23:47:19.57ID:x6cWTlKo#include <stdlib.h>
#include <malloc.h>
void getm(int n, double ***y) {
inti;
double**x;
x = (double**)malloc(sizeof(double*) * n);
if(x == NULL){
puts("メモリを確保できませんでした");
exit(0);
}
for(i=0;i<n;i++){
x[i] = (double*)malloc(sizeof(double) * n);
if(x[i] == NULL){
puts("メモリを確保できませんでした");
exit(0);
}
}
*y = x;
}
int main(void) {
int n,i;
double **a = NULL;
n = 5;
getm(n,&a);
for(i=0;i<n;i++) free(a[i]);
free(a);
return 0;
}
■ このスレッドは過去ログ倉庫に格納されています