Computer Science/Algorithm

[구조체] struct 선언 방법들

해피단무지 2020. 9. 1. 20:33

- 구조체를 선언할 때 typedef를 사용하면 별칭이 꼭 필요하고, 이때는 구조체를 사용할때 별칭만으로 선언 가능하다.

#include <stdio.h>

struct A {
	int a;
    int b;
    int c;
};
typedef struct {
	int a;
    int b;
}b;
typedef struct C {
	int a;
    int b;
}c;

/* 안되는 선언 - typedef로 선언했으면 별칭이 있어야 함*/
typedef struct D{
	int a;
    int b;
}(별칭);

typedef struct A a;

int main (void)
{
	a a1;
    struct A a2;
    b b1;
    c c1;
}