I am trying to test the basic functioning of init(), but for some reason I am finding that for certain elements in the array, I am either missing a value or a value is doubled. Please help me understand what is causing this. If I place a printf function underneath the line where 'y' is decremented, the array prints as it is supposed to. However, if I attempt to print out individual values outside of the loops, I get some incorrect values. For instance, board[0][3] prints out 11, as does board[1][0]. Everything else prints as it should.

int row, col, d = 4, y = (d*d-1), board [d-1][d-1];

for (row = 0; row < d; row++)
    for (col = 0; col < d; col++)
        board[row][col] = y;

1 Answer 1


When you declare an array, such as board, you want to use the actual size of the array, without subtracting 1.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .