- #1
levadny
- 32
- 16
Dear Friends!
My post about dinamic arrays. For example little bit code.
Question. I not use equals code in project. This code is work, no problem.
Do you think this is a literate code?
It is clear?
My post about dinamic arrays. For example little bit code.
Code:
// size
int const X = 5;
int const Y = 4;
int const Z = 3;
// one dimension array
printf("\nOne dimension\n");
// array of pointers
int * Arr;
// create array
Arr = new int [X];
// work with array
for(int i = 0; i < X; i++)
Arr[i] = (i + 1);
// print array
for(int i = 0; i < X; i++)
printf("Arr[%d] = %d\n", i, Arr[i]);
// remove array
delete[] Arr;
printf("\n");
// Two dimensions
printf("\nTwo dimensions\n");
// array of pointers
int **Arr2;
// create "strings"
Arr2 = new int*[X];
// create colomns
for(int i = 0; i < X; i++)
Arr2[i] = new int[Y];
// work with array
for(int i = 0; i < X; i++)
for(int j = 0; j < Y; j++)
Arr2[i][j] = 10 * (i + 1) + (j + 1);
// print
for(int i = 0; i < X; i++)
{
for(int j = 0; j < Y; j++)
printf("%d\t", Arr2[i][j]);
printf("\n");
}
// remove
for(int i = 0; i < X; i++)
delete[] Arr2[i];
delete[] Arr2;
Question. I not use equals code in project. This code is work, no problem.
Do you think this is a literate code?
It is clear?