【发布时间】:2017-11-26 07:24:32
【问题描述】:
#include<stdio.h>
struct stucture
{
int info;
};
typedef struct stucture * ts;
int main()
{
ts exp;
exp->info=10;
printf("working");
}
我不知道这段代码有什么问题。不打印错误语句以便寻找解决方案。程序刚刚终止。
【问题讨论】:
-
不要在 typedef 后面隐藏指针语义...如果你没有隐藏,
exp->info可能会让你看起来更加可疑。 -
你还没有为指针
exp分配内存。在分配之前,您不能存储。首先使用malloc进行分配,然后初始化变量。