#include <stdio.h>

int main() {
    /* 구조체 정의 
    struct 구조체이름 {
        자료형1 변수이름1;
        자료형2 변수이름2;
    };
    */
    struct Fruit {
        char *name;
        int price;
        float weight;
    };

    struct Fruit apple = {"사과", 1500, 0.25};
    struct Fruit banana = {"바나나", 1200, 0.18};

    printf("%s / %d원 / %.2fkg\n", apple.name, apple.price, apple.weight);

    // 구조체 배열 (자료형 배열이름[배열크기])
    // struct 구조체이름 배열이름[배열크기]
    struct Fruit fruits[3] = {
        {"키위", 1300, 0.1},
        {"용과", 7000, 0.45},
        {"수박", 22000, 7.1}
    };

    printf("%s\n", fruits[0].name);

    // 용과의 가격 출력
    printf("%d원\n", fruits[1].price);

    // 수박의 이름과 무게 출력
    printf("%s / %.2fkg\n", fruits[2].name, fruits[2].weight);

    
    return 0;
}

Embed on website

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