for loop - C: Filling a matrix -
for loop - C: Filling a matrix -
i'm trying fill matrix loop, i'm coming problem 2 coordinates x_0 , y_0 interchangeable. emphasize problem i've simplified downwards basic example:
i'm filling next 2x2 matrix , having print value @ 1,2 (or [0][1] within array):
int matrix[1][1]; for(j=0; j<2; j++){ for(i=0; i<2; ++i){ scanf("%d", &matrix[j][i]); } } printf("%d \n", matrix[0][1]);
however returns value entered third, or [1][0]. thought might have messed loop, printing matrix[1][0] returns same (although here appropriate value).
thank help
edit: added declaration.
it appears confisuing indexing allocation,
int matrix[1][1]
allocates 1×1 matrix, and
int matrix[2][2]
allocates 2×2 matrix matrix[1][1]
actual m2,2 element of matrix, because index of first-row,first-column 0,0.
c for-loop matrix
Comments
Post a Comment