3) 구조체 문법 정리

구조체의 정의

01   struct student {
02      char name[20];
03      int koread, english, math;
04      double average;
05   }; 

 

구조체 변수의 선언 : 구조체 변수 선언 시 멤버들이 메모리에 할당된다.

01   struct student s1;

 

구조체의 멤버 접근 : 멤버 접근 연산자(.)를 이용한다.

01   s1.average = (double)(s1.korean+s1.english+s1.math)/3;

 

구조체의 초기화 : { }안에 초기값을 나열한다.

01   struct student s1 = {"김모모", 100, 100, 100, 0.0};

 

구조체 배열 및 포인터 : 구조체 배열을 선언하거나 포인터를 선언할 수 있다.