[ C언어: 구조체의 배열 ]


[ C언어: 구조체의 배열 ]

구조체 배열의 선언 struct student { int number; int name[20]; double grade; }; struct student list[100]; : student 구조체의 배열을 list[]란 이름으로 선언 list[2].number =24; strcpy(list[2].name, "홍길동"); // 문자열은 항상 strcpy를 이용하여 대입 list[2].grade = 4.3; → 배열 인덱스가 2인 요소의 구조체에 값을 저장 구조체 배열의 초기화 struct student list[3] = { { 1, "Park", 3.42 }, { 2, "Kim", 4.31 }, { 3, "Lee", 2.98 } }; +) 구조체 배열의 원소 개수 계산하기 n = sizeof(list)/sizeof(list[0]); n = sizeof{list)/sizeof(struct student); < 예제 > #include <stdio.h> #define _CRT_SEC...


#c언어 #구조체 #배열

원문링크 : [ C언어: 구조체의 배열 ]