结构体和指针
来源:互联网 发布:虚拟机mac可以升级吗 编辑:程序博客网 时间:2024/04/30 11:43
结构体包含结构体:
#include "stdafx.h"
#include <stdlib.h>
struct data
...{
int day,month,year;
} ;
struct stu
...{
char name[20];
long num;
struct data birthday;
} ;
int main()
...{
struct stu *student;
// 申请内存
student = (struct stu *)malloc(sizeof(struct stu));
printf("Input name,number,year,month,day: ");
scanf("%s",&student->name);
scanf("%ld",&student->num);
scanf("%d%d%d",&student->birthday.year,&student->birthday.month,&student->birthday.day);
printf(" Output name,number,year,month,day ");
printf("%20s%10ld%10d/%d/%d ",student->name,student->num,student->birthday.year,
student->birthday.month,student->birthday.day);
// 释放内存
free(student);
return 0;
}
#include <stdlib.h>
struct data
...{
int day,month,year;
} ;
struct stu
...{
char name[20];
long num;
struct data birthday;
} ;
int main()
...{
struct stu *student;
// 申请内存
student = (struct stu *)malloc(sizeof(struct stu));
printf("Input name,number,year,month,day: ");
scanf("%s",&student->name);
scanf("%ld",&student->num);
scanf("%d%d%d",&student->birthday.year,&student->birthday.month,&student->birthday.day);
printf(" Output name,number,year,month,day ");
printf("%20s%10ld%10d/%d/%d ",student->name,student->num,student->birthday.year,
student->birthday.month,student->birthday.day);
// 释放内存
free(student);
return 0;
}
结构体和指针
#include "stdafx.h"
#include <stdlib.h>
struct data
...{
int day,month,year;
} ;
struct stu
...{
char name[20];
long num;
struct data birthday;
} ;
int main()
...{
int i;
struct stu *p,student[4]=...{
...{"liying",1,1978,5,23},
...{"wangping",2,1979,3,14},
...{"libo",3,1980,5,6},
...{"xuyan",4,1980,4,21}
};
/**//*定义结构体数组并初始化*/
p=student;
printf(" ----Outputname,number,year,month,day ");
for(i=0;i<4;i++)
printf("%20s% 10ld% 10d/%d /%d ",
(p+i)->name,
(p+i)->num,
(p+i)->birthday.year,(p+i)->birthday.month,(p+i)->birthday.day);
return 0;
}
#include <stdlib.h>
struct data
...{
int day,month,year;
} ;
struct stu
...{
char name[20];
long num;
struct data birthday;
} ;
int main()
...{
int i;
struct stu *p,student[4]=...{
...{"liying",1,1978,5,23},
...{"wangping",2,1979,3,14},
...{"libo",3,1980,5,6},
...{"xuyan",4,1980,4,21}
};
/**//*定义结构体数组并初始化*/
p=student;
printf(" ----Outputname,number,year,month,day ");
for(i=0;i<4;i++)
printf("%20s% 10ld% 10d/%d /%d ",
(p+i)->name,
(p+i)->num,
(p+i)->birthday.year,(p+i)->birthday.month,(p+i)->birthday.day);
return 0;
}
p->num = (*p).num
- 结构体和指针
- 结构体和指针
- 指针和结构体
- 指针和结构体
- 结构体和指针
- 结构体和指针
- 结构体指针和结构体嵌套
- 结构体数组和结构体指针
- 结构体指针和结构体数组
- 结构体指针和数组
- c指针和结构体
- Golang结构体和指针
- 结构体指针的定义和引用
- C# 结构体和指针转换
- C# 结构体和指针转换
- 复习6:void指针和结构体
- struct 结构体中 数组和指针
- 结构体指针的定义和引用
- jsp读写Cookies
- 标题:一对网络恋人在洞房中的经典搞笑对白不笑你打俺
- 如何在sql的存储过程中用代码将所查询到表的数据导出到execl表中
- 教你用ADO+VC在程序中完成创建和修改ACCESS数据库
- 聚类方法初探
- 结构体和指针
- 号称中国第一美女!!
- 临渊慕鱼,不如退而织网
- ajax
- 《传奇3》我的传奇心情故事
- 抱着希望,坚强的活着
- 老公有外遇了咋办?
- 实例解析SQL Server 2000和JDBC的融合
- fcm code C代码