Assuming that I have initialized an int array using double pointer
int **array;
I have used malloc to give the wanted size of the array like this
array = malloc( sizeof *array * ROWS );
if ( array ){
for ( size_t i = 0; i < ROWS; i++ )
*(array + i) = malloc( sizeof *(*(array + i)) * COLS );
}
Every index of the array is declared with a random int number. I am trying to find a faster way to copy a row or a column rather than using for loops. My choice is to use memcpy, it looked like a good idea on the beginning since I had no problem copying a row using
memcpy((array + 1), (array + 3), (int)sizeof(int **));
However when it comes to columns using
memcpy(*(array + 1), *(array + 3), (int)sizeof(int *));
does not actually worked as I expected and only one element was copied. Is there something that I am missing?
*(array + 1);array[1]is simpler and more readable.memcpy((array + 1), (array + 3), (int)sizeof(int **));" copy more bytes then the number of bytes a pointer of typeint**uses (typically 4 or 8 bits depending on the OS)?