mardi 4 août 2015

why the first index of the column of a matrix is negative?

why in this simple part of code to modify the point in the lower left of the bidimensional array have I to put in the coordinate m[37][-40]?

#include <stdio.h>
#include <stdlib.h>
#define MAX 40

int main()
{
    int i, j;
    char m[MAX][MAX];

    for(i=0; i<MAX; i++){
        for(j=0; j<MAX; j++)
            m[i][j]=' ';
    }

    m[37][-40]='X';

    for(i=0; i<MAX; i++){
        for(j=0; j<MAX; j++)
            printf("%c", m[i][j]);
    }
    return 0;
}

Souldn't it be m[37][0]? Becouse the row is 37 and the column is 0...



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire