My cousin has a school project and we can't figure out why is the array different the second time it's printed when there is no values changing in between?
Basically you enter a number which states how many rows/columns will the matrix have, and during first loop he assigns a number to every position and prints out the random number. However, the second time we go through the matrix the numbers are different and it seems that they are copied through the matrix from bottom left corner to top right corner for some reason. It seems strange to us because we never assign a different value to a position in the array after defining it for the first time.
int i,j,n,matrica[i][j],suma=0; srand(time(NULL)); printf("\nunesi prirodan broj N[3,20] = \n"); scanf("%d",&n); for(i=0;i<n;i++) { for(j=0;j<n;j++) { matrica[i][j]=rand()%100; printf("%d, %d = %4d ",i, j, matrica[i][j]); if(j==n-1) { printf("\n"); } } } printf("\n"); for(i=0;i<n;i++) { for(j=0;j<n;j++) { printf("%d, %d = %4d ", i, j, matrica[i][j]); if(j==n-1) { printf("\n"); } } } And here is the result of this (the code I pasted here has 2 prints, and in the image there is 3 but every time you go through the matrix after the first time it's going to be the same):

iandjwill be used and when they are initialized...if(j==n-1) { printf("\n"); }- Why not just put this after the for loop and remove the condition?int i,j,n,matrica[i][j],…; what is the value ofiwhenmatricais defined? You have no clue; I have no clue; no-one has a clue; the value ofiis undefined and could be anything. Dittoj. You have to defer the allocation ofmatricauntil you know how big it needs to be. This is just expanding on what @Someprogrammerdude said. You might useint matrica[n][n];after thescanf()— and after checking that thescanf()succeeded and entered a number that's bigger than zero and not too big (for an ill-defined 'too big'; 64 or 100 might be suitable checks).matrica[i][j]is allocated statically using whatever valuesiandjhave at that moment (and they are undefined). It's possible the compiler just doesn't allocate anything. But it most certainly doesn't get resized when you assign values to it, there isn't such thing in C.