【学习笔记】2022.9.28 c语言 结构体

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

#include <Windows.h>

#include <stdlib.h>

#include <string.h>

#include  <time.h>

#include <math.h>

struct B//定义一种新的数据类型struct B
{

    char a[20];

    int b;

};

struct student
{

    struct B b;//结构体中可以套结构体

    char name[20];//要写字符数串大小

    int age;

}s1={{"acd",13},"aed",19};//要加分号
                          //定义结构体的同时创建全局变量s1
                          //s1是结构体变量

void print1(struct student a)
{

    printf("%s ", a.b.a);

}

void print2(struct student* a)
{

    printf("%s ", a->b.a);

}

int main()
{

    struct student s2 = { {"asd",23},"zya",18 };//初始化s2
                                                //s2的数据类型是struct student
                                                //{ }里面的{ }可以去掉

    printf("%s ", s2.b.a);

    printf("%d ", s2.age);

    struct student* s_p = &s2;

    printf("%s ", ( * s_p).b.a);// *s_p必须要加( )

    printf("%s ", s_p -> b.a);

    print1(s2);

    print2(&s2);//建议使用传址调用 -> 节省空间,可改变内容

    return 0;

}

//栈是一种数据结构,先进的后出,后进的先出

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值