by mnaydin · 3y ago · 0 comments
int (*ap3)[900000] = malloc(sizeof *ap3);
is nicer than int *a = malloc(900000 * sizeof *a);
Notice that, in the former case, the array elements must be accessed as (*ap3)[i] whereas in the latter case the usual method a[i] is fine. int (*arr)[n][m] = malloc(sizeof *arr);
which you have to access with (*arr)[i][j]
I prefer doing int (*arr)[m] = malloc(n*sizeof(*arr));
though this separates m and n to be one on left side while the other on the right side, it allows me to index directly arr[i][j]The goal is to have a pointer to the array, and not a pointer to the first element of the array.
Whether this is "nicer" or not, and whether this is what you need in your application, are out of the scope of the fine article.