C语言结构体与共用体01

小甲鱼结构体与共用体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);
}

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值