2019/c++

dynamic allocation of 2-dimension array

fw93 2018. 3. 20. 11:03
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
#include "stdafx.h"
#include <cstdio>
 
using namespace std;
 
int main() {
    int ** tmp;
    tmp = new int *[10];
    for (int i = 0; i < 10; i++) {
        tmp[i] = new int[10];
    }
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            tmp[i][j] = i + j;
        }
    }
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            printf("%d ", tmp[i][j]);
        }
        printf("\n");
    }
    while (1) {}
    return 0;
}
cs


'2019 > c++' 카테고리의 다른 글

Strings(2)  (0) 2018.03.22
relational data structures & strings (C++ STL)  (0) 2018.03.21
c++ reference variables  (0) 2018.03.18
Template classes, operator overloading  (0) 2018.03.18
time&chronos  (0) 2018.03.17