Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 백준 2812번
- BFS(Breadth First Search)
- 백준 2261번
- 그래프(Graph)
- 위상 정렬(Topology Sort)
- 백준 9012번
- 분할 정복(Divide and Conquer)
- 백준 1707번
- DFS
- DFS(Depth First Search)
- 스택(Stack)
- 백준 17608번
- 백준 21606번
- 큐(Queue)
- 이분 탐색(Binary Search)
- 동적 프로그래밍(Dynamic Programming)
- 백준 10000번
- 알고리즘 개념
- 백준 2504번
- 이분 그래프(Bipartite Graph)
- 위상 정렬(Topological Sort)
- BFS
- 트리(Tree)
- 백준 2493번
- DFS & BFS
- 백준 1948번
- 다익스트라 알고리즘(Dijkstra Algorithm)
- 그리디 알고리즘(Greedy Algorithm)
- 백준 18352번
- 플로이드 워셜 알고리즘(Floyd-Warshall Algorithm)
Archives
- Today
- Total
Always Be Wise
구조체 배열 본문
728x90
일반 변수에 배열이 있듯이 구조체에도 배열이 있다. 구조체 배열을 선언하는 방법은 일반적인 배열을 선언하는 방법과 동일하다.
아래 코드에서 구조체도 문자열은 선언할 때만 초기화 할 수 있으므로 먼저 선언과 동시에 초기화를 해주고, 나머지 값들은 선언 후에
대입하였다.
#include <stdio.h>
typedef struct {
char name[30];
int age;
} Student;
int main(){
Student goorm[3] = { {.name = "해리 포터"}, {.name = "헤르미온느 그레인저"}, {.name = "론 위즐리"} };
goorm[0].age = 10;
goorm[1].age = 10;
goorm[2].age = 10;
printf("이름 : %s / 나이 : %d\n", goorm[0].name, goorm[0].age);
printf("이름 : %s / 나이 : %d\n", goorm[1].name, goorm[1].age);
printf("이름 : %s / 나이 : %d\n", goorm[2].name, goorm[2].age);
return 0;
}
'프로그래밍 언어 > C' 카테고리의 다른 글
메모리 구조와 동적 메모리 할당 (0) | 2021.12.04 |
---|---|
구조체 포인터 (0) | 2021.12.04 |
typedef를 이용한 구조체 선언 (0) | 2021.12.04 |
구조체란? (0) | 2021.12.04 |
이중 포인터와 포인터 배열 (0) | 2021.12.04 |
Comments