C言語なら俺に聞け(入門篇) Part 13
■ このスレッドは過去ログ倉庫に格納されています
0718717
2007/06/09(土) 00:01:27malloc関数に関する質問です。
#include <stdlib.h>
#include <stdio.h>
struct st {
int a;
};
void func(struct st* b) {
b = (struct st*)malloc(sizeof(struct st*));
printf("2.func:%p\n",b);
// free(b);
}
void main(void) {
struct st* a = NULL;
printf("1.main:%p\n",a);
func(a);
printf("3.main:%p\n",a);
}
を実行すると
1.main:00000000
2.func:00431EA0
3.main:00000000
Press any key to continue
と出力されます。次の出力
1.main:00000000
2.func:00431EA0
3.main:00431EA0
Press any key to continue
を期待していたのですが、うまくいきません。何が原因でしょうか?
■ このスレッドは過去ログ倉庫に格納されています