Frage

I'm just playing with arrays and I've written this tiny thing in Emacs (OSX) and I'm getting a Bus error: 10 when I try to run it. I don't know why that is, maybe someone can show me...

#include <iostream>

int main()
{    
  int array[3][3];

  for (int i = 0; i < 3; i++)
    {
      for (int j = 0; i < 3; j++)
      {
        array[i][j] = j + i;
      }
    }
  for (int i = 0; i < 3; i++)
    {
      for (int j = 0; j < 3; j++)
      {
        std::cout << array[i][j];
      }
    }
  return 0;
}
War es hilfreich?

Lösung

Riiiiight here:

  for (int j = 0; i < 3; j++)

I think you want a j there in the middle.

  for (int j = 0; j < 3; j++)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top