문제

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;
}
도움이 되었습니까?

해결책

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++)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top