C 고전 구조 체 배열 초기 화

3126 단어 C 기초
#include 

int main(int argc, const char * argv[])
{

    //1
    struct Student{
        int age;
        char *name;
    }stu[3]={{22,"peter"},{33,"tom"},{23,"tiger"}};

    for (int i = 0; i < 3; i ++) {
        printf("%s\t", stu[i].name);
    }
    printf("
"
); //2 struct Student stu1[3] ={{22,"peter"},{33,"tom"},{23,"tiger"}}; for (int i = 0; i < 3; i ++) { printf("%s\t", stu1[i].name); } printf("
"
); //3 struct Student stu2[3]; stu2[0] = (struct Student){22,"peter1"}; stu2[1] = (struct Student){23,"peter2"}; stu2[2] = (struct Student){24,"peter3"}; for (int i = 0; i < 3; i ++) { printf("%s\t", stu2[i].name); } printf("
"
); return 0; }

좋은 웹페이지 즐겨찾기