C语言中运用结构体指针输出结构体中的变量
#include<stdio.h>
struct Data{
int year;
int mounth;
int day;
}data;
int main(){
Data data={2020,11,7};
struct Data *ptr;
ptr=&data;
printf("%d",ptr->year);
printf("-%d",data.mounth);
printf("-%d",ptr->day);
return 0;
}
运行结果!:
2020-11-7
--------------------------------
Process exited after 0.07279 seconds with return value 0
请按任意键继续. . .