struct与typedef struct及指针

#include<stdio.h>

//法一
struct Student
{
    char *name;
    int score;
};

//法二
struct Student1
{
    char *name;
    int score;
}stu2;    //stu2是一个个体

//法三
typedef struct Student2
{
    char *name;
    int score;
}stub;    //stub是一个数据类型

//法四
struct Student3
{
    char *name;
    int score;
}stuc,*pstuc = &stuc;   

//法五
typedef struct Student4
{
    char *name;
    int score;
}stud,*p;    //stud和p都是数据类型,前者是结构体,后者是结构体指针

int main()
{
    struct Student stu1;
    stu1.name = "makaka";
    stu1.score = 1;

    stu2.name = "makaka";
    stu2.score = 2;    

    stub stu3;
    stu3.name = "makaka";
    stu3.score = 3;

    // struct Student3 *pstuc = &stuc;
    stuc.name = "makaka";
    stuc.score = 4;

    stud stu4,*pstu4 = &stu4;
    p tem = &stu4;
    stu4.name = "makaka";
    stu4.score = 5;

    printf("姓名%s,分数%d\n",stu1.name,stu1.score);
    printf("姓名%s,分数%d\n",stu2.name,stu2.score);
    printf("姓名%s,分数%d\n",stu3.name,stu3.score);
    printf("姓名%s,分数%d\n",pstuc->name,stuc.score);
    printf("姓名%s,分数%d\n",pstu4->name,tem->score);
    
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值