#include <stdio.h>
#include <stdlib.h>
#define ROWS 3
#define COLS 4
void clone2DArray(int rows, int cols, int arr2D[][COLS], int clone[][COLS]) {
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
clone[i][j] = arr2D[i][j];
}
}
}
int main() {
int arr2D[][COLS] = {
{1, 2, 3, 0},
{4, 5, 6, 11},
{7, 8, 9, 38}
};
int rows = sizeof arr2D / sizeof arr2D[0];
int cols = sizeof arr2D[0] / sizeof(int);
int clone[ROWS][COLS];
clone2DArray(rows, cols, arr2D, clone);
printf("Cloned Array:\n");
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
printf("%d ", clone[i][j]);
}
printf("\n");
}
return 0;
}
/*
run:
Cloned Array:
1 2 3 0
4 5 6 11
7 8 9 38
*/