If I allocate a 2D array like this int a[N][N]; it will allocate a contiguous block of memory.
But if I try to do it dynamically like this :
You can typedef your array (for less headake) and then do something like that:
#include #define N 10 typedef int A[N][N]; int main () { A a; // on the stack a[0][0]=1; A *b=(A*)malloc (sizeof(A)); // on the heap (*b)[0][0]=1; }