-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path48_2DimensionArray2.c
44 lines (35 loc) · 1.17 KB
/
48_2DimensionArray2.c
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
32
33
34
35
36
37
38
39
40
41
42
43
44
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
// 동적 이차원 배열
void SetArray(int** pparray, int column, int row) {
for (int i = 0; i < column; i++) {
for (int j = 0; j < row; j++) {
pparray[i][j] = i * row + j;
}
}
}
void PrintArray(int** pparray, int column, int row) {
for (int i = 0; i < column; i++) {
for (int j = 0; j < row; j++) {
printf("pparray[%d][%d] = %d\n", i, j, pparray[i][j]);
}
}
}
int main() {
int column = 0;
int row = 0;
printf("이차원배열의 가로, 세로 갯수를 입력하세요(10(행) 10(열)) : ");
scanf("%d %d", &column, &row);
int** pparray = (int**)malloc(sizeof(int*) * column); // 동적 포인터 배열 할당
for (int i = 0; i < column; i++) {
pparray[i] = (int*)malloc(sizeof(int) * row); // 동적 int형 배열 할당
}
SetArray(pparray, column, row);
PrintArray(pparray, column, row);
for (int i = 0; i < column; i++) {
free(pparray[i]); // 동적 int 형 배열 반환 처리
}
free(pparray); // 동적 int 형 포인터 배열 반환 처리
return 0;
}