Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- void reserveMemory(int ***a, int x, int y)
- {
- *a = (int **)malloc(sizeof(int*) * x);
- for (int i = 0; i < x; i++)
- (*a)[i] = (int *)malloc(sizeof(int) * y);
- for (int i = 0; i < x; i++)
- for (int j = 0; j < y; j++)
- (*a)[i][j] = (i * y) + j + 1;
- }
- int **reserveMemory2(int x, int y)
- {
- int **a = (int **)malloc(sizeof(int*) * x);
- for (int i = 0; i < x; i++)
- a[i] = (int *)malloc(sizeof(int) * y);
- for (int i = 0; i < x; i++)
- for (int j = 0; j < y; j++)
- a[i][j] = (i * y) + j + 1;
- return a;
- }
- int main()
- {
- int **a, **b;
- reserveMemory(&a, 10, 10);
- b = reserveMemory2(10, 10);
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++)
- printf("%d\t", a[i][j]);
- printf("\n");
- }
- printf("\n");
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++)
- printf("%d\t", b[i][j]);
- printf("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement