is there any advantage apart from the fewer memory allocations?
array = (int ***) malloc( 10 * sizeof(int **) );
array[0] = (int **) malloc( 10 * 20 * sizeof( int *) );
array[0][0] = (int *) malloc( 10 * 20 * 30 * sizeof(int) );
for ( j = 1 ; j < 20 ; ++j ) {
array[0][j] = array[0][j-1] + 30;
}
for ( i = 1 ; i < 10 ; ++i ) {
array[i] = array[i-1] + 20;
array[i][0] = array[i-1][20-1] + 30;
for ( j = 1 ; j < 20 ; ++j ) {
array[i][j] = array[i][j-1] + 30;
}
}
for (i=0; i<10; i++) {
array[i][0] = array[(i+1)*10];
}
Although that doesn't quite seem right with a 2d deference on the left and a 1d on the right.array = (int ***) malloc( 10 * sizeof(int **) );
array[0] = (int **) malloc( 10 * 20 * sizeof( int *) );
array[0][0] = (int *) malloc( 10 * 20 * 30 * sizeof(int) );
for ( j = 1 ; j < 20 ; ++j ) {
array[0][j] = array[0][j-1] + 30;
}
for ( i = 1 ; i < 10 ; ++i ) {
array[i] = array[i-1] + 20;
array[i][0] = array[i-1][20-1] + 30;
for ( j = 1 ; j < 20 ; ++j ) {
array[i][j] = array[i][j-1] + 30;
}
}
ok.png
(i*dimension)
key part, which moves along like your first 2d example. This wasn't in the code in the lecture notes, however I was forgetting that each iteration through the loop the previous iteration had already incremented along 30, so the next time was 30 along, ready for another 30 (if that makes sense).Title | # Comments | Views | Activity |
---|---|---|---|
pgpool-II on Ubuntu 14.04... ARGH! | 5 | 809 | |
C#, VS15, StructLayout | 1 | 116 | |
Passing a array as parameter - C | 2 | 77 | |
Need example | 5 | 100 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
19 Experts available now in Live!