슈뢰딩거의 고등어
Difference between typedef struct & struct 본문
how to define Struct?
struct SuperMan {
int power;
int age;
};
We can define a Struct named SuperMan like this. But, actually, this doesn't create struct SuperMan itself. It just lets Compiler know how struct SuperMan looks like.
If you want to define a Struct variable that has real memory, you should define it like this.
struct SuperMan ClarkKent;
OR you can make it shorter.
struct SuperMan {
int power;
int age;
}ClarkKent;
AS you know, defining struct means creating a new data type.
Defining struct variable means giving it to the new memory space.
WHAT is typedef??
typedef gives a nametag to a certain data type.
For example, there is a data type named unsigned short int. Typing it every time is exhausting or may cause errors. What if it has another short nickname? So we can give it a nickname like UINT16.
typedef unsigned short int UINT16;
WHAT is typedef struct??
typedef + [type] + [nickname]
typedef struct SuperMan {
int power;
int age;
} sman_t;
[type] : struct SuperMan {}
[nickname] : sman_t;
Therefore, We can call defining struct SuperMan to sman_t;
Now we can define a variable like
sman_t ClarkKent;
So why we use typedef struct is We can make it shorter.
'tech' 카테고리의 다른 글
데이터 단위 KB, MB, GB, TB, PB (0) | 2022.01.15 |
---|---|
컴퓨터의 기본 원리 및 각 부품의 역할 (CPU, RAM, HDD/ SSD, VGA) (0) | 2022.01.15 |
키크론 k3 레트로 후기 (적축) (0) | 2022.01.13 |
python, rpm package download (offline settings) (0) | 2021.12.02 |
linux setting (0) | 2021.12.02 |