2021-08-06

···

include <stdio.h>

include <string.h>

pragma warning(disable:4996)

struct AGE
{
int year;
int month;
int day;
};
struct STUDENT
{
char name[20]; //姓名
int num; //学号
struct AGE birthday; //生日
float score; //分数
};
int main(void)
{
struct STUDENT student1; /用struct STUDENT结构体类型定义结构体变量student1/
struct STUDENT* p = NULL; /定义一个指向struct STUDENT结构体类型的指针变量p/
p = &student1; /p指向结构体变量student1的首地址, 即第一个成员的地址/
strcpy((p).name, "小明"); //(p).name等价于student1.name
(p).birthday.year = 1989;
(
p).birthday.month = 3;
(p).birthday.day = 29;
(
p).num = 1207041;
(p).score = 100;
printf("name : %s\n", (
p).name); //(p).name不能写成p
printf("birthday : %d-%d-%d\n", p->birthday.year, (
p).birthday.month, (p).birthday.day);
printf("num : %d\n", (
p).num);
printf("score : %.1f\n", (*p).score);
return 0;
}
···

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 结构体指针:当一个指针变量用来指向一个结构体变量时。1.结构体指针变量的值是所指向的结构体变量的起始地址。2.通过...
    liyao阅读 606评论 0 0
  • 结构体概述1.1 概念:有时需要将不同类型的数据组合成一个有机的整体,以便于引用。因此C语言采用结构体形式将不同类...
    Eric_Hunter阅读 4,884评论 0 0
  • 函数:strcpy(t,s);把s中的字符串拷贝到t中。s可以是一个数组名,也可以是有个字符串常量。成功,返回第一...
    henry_bin阅读 3,550评论 0 0
  • 11-结构体 include <stdio.h> include <string.h> /*作业:1>实现mySt...
    萌面大叔2阅读 1,404评论 0 0
  • 第1章 第一个C程序第2章 C语言基础第3章 变量和数据类型第4章 顺序结构程序设计第5章 条件结构程序设计第6章...
    小狮子365阅读 13,640评论 3 71