struct student
{int name;
int age;
}student;

typedef struct student* Pstu;


void main()
{
    int a[2]={15,16};
    printf("%d",((Pstu)a)->name);
    printf("%d",((Pstu)a)->age);

}

结果:

结构体强制转换

还可以写成:

 struct stu
{
int name;
int age;
};


void main()
{
    //stu p;
    int a[2]={15,16};
    printf("%d",((struct stu *)a)->name);
    printf("%d",((struct stu *) a)->age);

}

还可以写成:

typedef struct stu
{
int name;
int age;
}p;


void main()
{
    //stu p;
    int a[2]={15,16};
    printf("%d",((p *)a)->name);
    printf("%d",((p *) a)->age);

}

还可以写成:

 struct stu 
{
int name;
int age;
};

typedef struct stu *Pstu;

void main()
{
    //stu p;
    int a[2]={15,16};
    printf("%d",((Pstu)a)->name);
    printf("%d",((Pstu ) a)->age);

}

相关文章: