// 如何定义结构体.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <stdio.h>
//第一种方式,推荐使用
struct Student1
{
float score;
char sex;
char name[20];
};
//第二种方式
struct Student2
{
float score;
char sex;
char name[20];
} student;
//第三种方式,不能再次定义一个变量
struct
{
float score;
char sex;
char name[20];
} student3;
int main(void)
{
student.sex = 'm';
Student2 student2;
student2.sex = 'f';
student3.sex = 'f';
//student3 set;//error,不能定义,因为不知道类型
printf("%c,%c,%c\n", student.sex, student2.sex, student3.sex);//%s是以字符串的形式输出
return 0;
}
如何定义结构体
最新推荐文章于 2023-11-03 17:40:12 发布