Arrays are strange

Consider the two following C++ programs

  • Program A:
1
2
3
4
5
6
7
8
9
#define L 1000

int main() {
    int array[L][L];
    for (int i=1; i < L; i++)
        for (int j=1; j < L; j++)
            array[i][j] = i*j;
    return 0;
}

  • Program B:
1
2
3
4
5
6
7
8
9
#define L 1000

int main() {
    int array[L][L];
    for (int j=1; j < L; j++)
        for (int i=1; i < L; i++)
            array[i][j] = i*j;
    return 0;
}

Usually, one would expect them to run typically in the same time. Do they?

×

Problem Loading...

Note Loading...

Set Loading...