#include <stdio.h>
// 친구 카드 구조체
struct Friend {
    char *name;
    int age;
    char *hobby;

    struct Friend * best_f;
};

int main() {
    //friend2
    struct Friend friend2 = {"민하", 12, "멀리뛰기", NULL};
    
    //friend1
    struct Friend friend1 = {"이랑", 12, "놀기", &friend2};

    printf("===친구1 카드===\n");
    printf("이름 : %s\n", friend1.name);
    printf("나이 : %d\n", friend1.age);
    printf("취미 : %s\n", friend1.hobby);

    printf("\n===친구2 카드===\n");
    printf("이름 : %s\n", (*friend1.best_f).name);
    printf("나이 : %d\n", (*friend1.best_f).age);
    printf("취미 : %s\n", (*friend1.best_f).hobby);

    printf("\n===친구2 카드===\n");
    printf("이름 : %s\n", friend1.best_f->name);
    printf("나이 : %d\n", friend1.best_f->age);
    printf("취미 : %s\n", friend1.best_f->hobby);
    // -> 주소가 가리키는 구조체 안으로 들어간다

    
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: