将stuct中的指针设置为null

时间:2016-01-20 22:04:37

标签: c pointers struct

我想将Student struct中的指针*name*age设置为NULL。我不知道如何从main()做到这一点。

typedef struct Student Student;
typedef struct Student{
    char *name; 
    int *age;
} Student;

我想在我的主程序中将上面提到的指针设置为NULL。

我在学生的主要声明是:

Student Tom;

我不确定如何将tom.name和tom.age指针设置为NULL。

1 个答案:

答案 0 :(得分:1)

您可以通过以下方式执行此操作

Student Tom = { NULL, NULL };

Student Tom = { .name = NULL, .age = NULL };

Student Tom;

Tom.name = NULL;
Tom.age = NULL;