C语言——typedef

1#includestdio.htypedef struct Student{int sid;char name[100];char sex;}* PST; // PST 等价于 struct Student * 定义的变量为指针int main(){struct Student st;PST ps = st;ps-sid = 99;printf(%d\n...

1

#include<stdio.h>

typedef struct Student
{
    int sid;
    char name[100];
    char sex;
}* PST;  // PST 等价于 struct Student * 定义的变量为指针

int main()
{
    struct Student st;
    PST ps = &st;
    ps->sid = 99;
    printf("%d\n", ps->sid);

    return 0;
}

2

#include<stdio.h>

typedef struct Student
{
    int sid;
    char name[100];
    char sex;
}* PST, ST;  // PST 等价于 struct Student * 定义的变量为指针, ST 等价于 struct Student 定义的变量为普通的结构体变量

int main()
{
    ST st;          // struct Student st;
    PST ps = &st;   // struct Student * ps = &st;
    ps->sid = 99;
    printf("%d\n", ps->sid);

    return 0;
}

本文标题为:C语言——typedef

基础教程推荐