동일한 자료형을 여러 개 이어서 사용하는 것
자료형 변수명[배열 갯수]
int arr[10] = {}; // 선언, 초기화
// 빈 중괄호 == 모두 0으로 선언
arr[0] = 1;
arr[1] = 2;
arr[2] = 3;
...
arr[9] = 10;
int iArray[10] = {};
iArray[10] = 10;
배열 사용 시에는 접근 때 범위를 넘지 않게 유의해야 함.
사용자 정의 자료형
// 사용자 정의 자료형
typedef struct _tagMyST
{
int a;
float f;
}MYST; // 새로운 이름 정의
int main()
{
MYST t; // 구조체 : 크기는? 8 byte
int size = sizeof(MYST); // 8
t.a = 1;
t.f = 10f;
return 0;
}
typedef struct _tagBig
{
MYST t;
int i;
char c;
}BIG;
typedef 자료형 새_자료형의_이름
struct 키워드를 자료형으로 사용struct _tagMyST
{
int a;
float f;
};
struct NewStruct
{
int a;
char s;
};
int main()
{
// c에서 이렇게 사용하면 오류임
_tagMyST s;
NewStruct st;
// 앞에 struct 키워드를 붙여줘야함.
// 이 키워드를 토대로 묶어서 컴퓨터가 검색함.
struct _tagMyST s2;
struct NewStruct st2;
}
typedef struct NewStruct
{
int a;
char s;
} NEWST; // 새로운 이름 정의
int main()
{
NEWST a;
return 0;
}
struct _tagMyST
{
int a;
float f;
};
typedef struct NewStruct
{
int a;
char s;
} NEWST; // 새로운 이름 정의
int main()
{
_tagMyST st; // 이렇게도 가능
NEWST a;
NewStruct b;
return 0;
}
typedef struct NewStruct
{
int a;
char s;
} NEWST; // 새로운 이름 정의
배열 초기화와 유사.
int main()
{
MYST t = { 1, 3.14f };
}