アドレス入力
Posted: 2018年2月27日(火) 10:12
double型の変数800個を格納できる領域を動的に確保してdouble型のポインタyにその領域の最初のアドレスを入力したいのですが動的のときに何をすればいいのか分からないですし全体的にどう書けばいいのかわかりません。
#include <stdio.h>
#include <stdlib.h>
#define SIZE (800)
int main(void)
{
double *p, *y;
int i;
p = malloc(sizeof(double) *SIZE);
if (!p) printf("allocation error\n"), exit(1);
for (i = 0; i < SIZE; i++) {
p[i] = i;
}
y = p;
for (i = 0; i < 10; i++) { // とりあえず最初の10個だけ確認
printf("%f\n", *y);
y++;
}
return 0;
}