- 하나 이상의 변수를 묶어서 새로운 자료형을 정의.
- 구조체 선언
struct point{
int xpos;
int ypos;
};
- 구조체 변수. struct point pos;
초기화 외 char 입력시, strcpy 필요.
- 구조체 배열. struct point arr[크기];
바로 초기화 할 수 있음.
- 구조체 변수를 만들고, 해당 구조체 변수의 포인터를 구조체 포인터 변수에 삽입.
struct point *pptr = &pos;
- 접근 방법.
(*pptr).xpos = 10;
pptr->ypos = 13;
- 구조체 변수 선언 떄마다 struct를 포함하지 않기 위해 사용.
- 해당 자료형의 이름은 대문자로 시작하는 것이 관례.
- 선언
struct point{};
typedef struct point Point;
또는
struct point{}Point;
- union
- 메모리 공간을 2byte, 1byte 씩 접근.
- Enumerated
- 선언
typedef enum syllable{
Do=1, Re=2, Mi=3, Fa=4, Sol=5, La=6, Si=7
};
- 사용
syllable tone;
for(tine = Do; tone <=Ti; tone+=1) Sound(tone);
- 값을 정해두지 않으면 0부터 순서대로. a=3, b, c=7
처럼 값이 연속적이지 않고, 할당된 값이 없다면, 앞에 선언된 값에서 +1
한 값인 b=4
할당.