C语言编程实例

C | 2018-02-10 23:52:38 | 阅读 471 次 | 评论(0)

#include <stdio.h>
typedef struct Date
{
int year;//年
int month;//月
int day;//日
}DATE;//定义struct Date类型,及其别名为DATE,三个int成员
struct Student//st->birthday.year
{
char m_name[128];//姓名
int n_age;//年龄
DATE birthday;//出生时间
}sa={"习惯了",21,{1996,9,21}};//sa是结构体Student的变量。
typedef struct Student STU;
void show(const STU *st)
{
printf("姓名:%s\n",st->m_name);
printf("年龄:%d\n",st->n_age);
printf("生日:%d年%d月%d日\n",st->birthday.year,
st->birthday.month,st->birthday.day);
}
void grow(STU *st)
{
st->n_age++;
}
void main()
{
STU s4 = {"空城",18,{1996,10,5}};
//STU *ps = &s4;
STU *ps;
ps=&s4;
grow(&s4);
printf("%d\n",ps->n_age);
printf("%s\n",sa.m_name);
printf("%d\n",ps->birthday.year);
show(&s4);
STU *pt=&sa;
show(&sa);
}

文章评论,共0条
游客请输入验证码
最新评论