c – What should i do with unhandled exception

I tried a lot of things to do but it still show me the same, that there is unhandled exception: access violation writing location in VS.But it doesn’t happen when i sorting 1d array. Can someone please help me?

int main(void) {
   static int a(3)(4){}, ab(3)(4){};
   int i, j, k, N, M;
   int* a1=nullptr;
   printf("Matrica mora da ima velicinu 3 sa 4n");
   printf("Enter the order nnt");
   scanf_s("%d%d",&N ,&M);
 for (i = 0;i < M;++i)
{
    for (j = 0;j < N;++j)
    {
        scanf_s(" %d", &a(i)(j));
        ab(i)(j) = a(i)(j);
    }
    printf("n");
}

for (i = 0;i < M;++i) {

    for (j = 0;j < N;++j) {

        printf(" %d", a(i)(j));

    }

    printf("n ");
}
    
//classic sorting
for (i=0; i < M; ++i)
{
    for (j = 0;j < N;++j)
    {
        for (k = j + 1;j < N;++k)
            if (a(i)(j) > a(i)(k))
            {
                *a1 = a(i)(j); // there is exception thrown
                a(i)(j) = a(i)(k);
                a(i)(k) = *a1;
            }
    }
}