小甲鱼结构体与共用体01
源码①:
#include <stdio.h>
struct student
{
int num;
char name[20];
char sex;
int age;
float score;
char addr[30];
} student1,student2;
void main()
{
printf("%d\n",sizeof(struct student));
}
在Dev下编译运行结果为68,即结构体student的长度。
源码②:
#include <stdio.h>
void main()
{
struct student
{
int num;
char *name;
char sex;
float score;
}boy1,boy2;
boy1.num=007;
boy1.name="Jane";
printf("Pls 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);
}
下面有一道练习,为什么最后输出的结果都是一样的?
#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);
}