구조체 포인터변수맴버
큐티베이비
2023.04.01
#include stdio.h
#include stdlib.h
typedef struct _Node {
int number;
char name[15];
struct _Node *next;
} Node;
void print_list(Node* );
void main()
{
Node person[3] = {{1, 피카츄}, {2, 라이츄}, {3, 파이리}};
int i;
for(i = 0; i 2; i++)
person[i].next = &person[i+1];
person[2].next = NULL;
print_list(person);
system(pause);
}
void print_list(Node* ptr)
{
while(ptr != NULL)
{
printf(번호 : %d , 이름 : %s \n, ptr-number, ptr-name);
ptr = ptr-next;
}
}
위 구조체 에서 빨강 부분말인데요.
앞에 굳이 struct _Node *next; 이렇게 struct를 꼭 붙이는 이유가 뭔가요? 사과를 사과라고 부르듯이 정해진 약속인가요? typedef로 구조체 선언했으니깐 않써도 될 거 같아서....