#include "stdio.h"
#include <stdlib.h>
#include <string.h>
//定义了一种数据类型。固定大小内存块的别名,没有分配内存。
struct T1
{
char *name;
int age;
int score;
};
//
//定义类型的三种方法
typedef struct T2
{
char *name;
int age;
int score;
} T2;
struct Tm
{
char name[20];
int age;
int score;
}T3,T4;//定义类型的同时定义变量
struct
{
char name[20];
int age;
int score;
}T5={"switch",14,56},T6;//匿名类型定义变量
//
//
//初始化变量的三种方法
//1.定义变量然后初始化
//2.
//
void main()
{
//分配内存
struct T1 s;
T2 m;
T2 *pS = NULL;
pS = &m;
s.name = "White";
s.age=15;
m.age = 13;
m.name = "mime";
m.score = 78;
//printf("%d\n",sizeof(s));
printf("%s,%d\n",s.name,s.age);
// printf("%d\n",s->age);
printf("%s,%d,%d\n",T5.name,T5.age,T5.score);//.操作符 起寻址作用 没有操作内存
printf("%s,%d,%d\n",pS->name,pS->age,pS->score);
system("pause");
}
结构体基础
最新推荐文章于 2024-09-24 17:39:35 发布