Cにおける構造体使用


#define _CRT_SECURE_NO_WARNINGS
#include 
#include 
#include 

/*
1、       
2、       
3、         
4、typedef    
5、             
6、           ,    ,     
*/

//1、       
//struct   
//struct Teacher       
//{}     
struct Teacher
{
	char name[50];
	int age;
};

//2、       
//1.     ,     (  )
struct Teacher t1; //    


//2.           
struct Teacher2
{
	char name[50];
	int age;
}t3 = {"tom", 66};

struct
{
	char name[50];
	int age;
}t5;

//3、         
//          ,  {}
struct Teacher t7 = { "lily", 18 };

//4、typedef    
typedef struct Teacher3
{
	char name[50];
	int age;
}Teacher3;

struct Teacher3 t8;
Teacher3 t9;

int main(void)
{
	//1.     ,     (  )
	struct Teacher t2; //    

	printf("%s, %d
"
, t7.name, t7.age); //5、 /* struct Teacher { char name[50]; int age; }; */ strcpy(t2.name, "xiaoming"); t2.age = 22; printf("%s, %d
"
, t2.name, t2.age); // , , struct Teacher *p = NULL; p = &t2; strcpy(p->name, "xiaojiang"); p->age = 22; printf("%s, %d
"
, p->name, p->age); return 0; }