标签:brithday int 第一节 共同体 boy2 boy1 printf 结构 struct
#include<stdio.h>
void main()
{
struct sutdent
{
int nun;
char name[20];
char sex;
int age;
float score;
char addr[30];
};
struct sutdent sutdent1;
struct sutdent sutdent2;
printf("%lu\n", sizeof(sutdent));
}
#if 1
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
void main()
{
#if 0
struct date
{
int month;
int day;
int year;
};
#endif
struct student
{
int num;
char *name;
char sex;
//struct date birthday;
float score;
} boy1, boy2;
boy1.num = 007;
boy1.name = "Jane";
printf("Please input sex and score\n");
scanf("%c %f", &boy1.sex, &boy1.score);
boy2 = boy1;
printf("Number =%d\nName = %s\n", boy2.num, boy2.name);
printf("Sex = %c\nScore = %f\n", boy2.sex, boy2.score);
}
#endif
#if 1
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
void main()
{
struct date
{
int month;
int day;
int year;
};
struct student
{
int num;
char* name;
char sex;
float score;
struct date brithday;
};
struct student boy1;
struct student boy2;
printf("Please input brithday (YY:)");
scanf("%d", &boy1.brithday.year);
printf("Please input brithday (MM:)");
scanf("%d", &boy1.brithday.month);
printf("Please input brithday (DD:)");
scanf("%d", &boy1.brithday.day);
boy2 = boy1;
printf("boy1's brithday is %d-%d-%d\n", boy1.brithday.year, boy1.brithday.month, boy1.brithday.day);
printf("boy2's brithday is %d-%d-%d\n", boy2.brithday.year, boy2.brithday.month, boy2.brithday.day);
#endif
}
Please input brithday (YY:)2022
Please input brithday (MM:)03
Please input brithday (DD:)02
boy1's brithday is 2022-3-2
boy2's brithday is 2022-3-2
结构体变量的引用
(1) 正确引用结构体变量中成员的方式为:结构体变量名.成员名
(2) 如果成员本身又属一个结构体类型,则要用若干个成员运算符,一级一级地找到最低的一级的成员。只能对最低级的成员进行赋值或存取以及运算。
(3)对结构体变量的成员可以像普通变量一样进行各种运算(根据其类型决定可以进行的运算)。
(4)可以引用结构体变量成员的地址,也可以引用结构体变量的地址。
#if 0
#include <stdio.h>
void main()
{
struct student
{
int num;
char *name;
char sex;
float score;
} boy1;
boy1.num = 007;
boy1.name = "Jane";
printf("The address of struct is %o :\n", &boy1 );
printf("The address of num is %o :\n", &boy1.num );
}
#endif
标签:brithday,int,第一节,共同体,boy2,boy1,printf,结构,struct 来源: https://blog.csdn.net/m0_59949484/article/details/123182682
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。