【发布时间】:2017-08-07 04:38:36
【问题描述】:
#include <stdio.h>
typedef struct {
int data;
char * string;
}Node;
Node * init(){
Node node;
node.data = 5;
node.string = "hello";
Node * point = &node;
return point;
}
int main() {
Node * test = init();
printf("%d\n", test->data);
printf("%d", test->data);
}
为什么最后两个 printf 语句会产生不同的结果。我怀疑这与我分配测试指针的方式有关,但我不知道如何修复它。
【问题讨论】:
标签: c pointers struct printf return-value