구조체

KakaoTalk_20220324_214813828.jpg

KakaoTalk_20220324_214825599.jpg

구조체 선언 → 틀을 정의

KakaoTalk_20220324_215456256.jpg

/* 
struct 태그(변수x) { 
 멤버;
 멤버; 등등
};
*/
struct student {
	int id;
	char name[10];
	double score; 
};

구조체 정의

/*
1. 변수 선언 후 정의
struct 태그 변수;
	변수.맴버 = 값;
	변수.맴버 = 값; 등등
*/
struct student gunwoo;
gunwoo.id = 2017101182;
gunwoo.name = strcpy(gunwoo.name, "gunwoo");
gunwoo.score = 100.0;

/*
2. 배열처럼 정의
struct 태그 변수 = {값 등등};
*/
struct student gunwoo = {2017101182, "gunwoo", 100.0};

Tip : 구조체 내부에서 함수 선언/정의 가능

Tip : 같은 구조체에 있는 구조체 변수라면 변수들끼리 내용을 한번에 복사가능

struct employee LEE, Kim, team[5];
Lee = Kim; //ㅣLee에 Kim을 복사
Lee = team[2]; // Lee에 team[2]를 복사
team[2]=team[3]; // team[2]에 team[3]을 복사

KakaoTalk_20220331_231543877.jpg