Imnitializing a prmitive array - corrupting other arrays

I am using primitive array type in xcode. Example:

int matrix [10][10];

I am also using a simple loop to initialise the array

for(int x=0;x<=10;x++)
  for(int y=0;y<=1;0y++)
     matrix[x][y] = 0;

I initialize sevreal matrices in this manner throughout the code. I noticed at times after the initialization is performed, an array that was prviously initialized or updated now contains garbage. Is there a simpler way to initialize an array of this type. And/Or why does this seem to corrupt other arrays.

Answers


Your array has 10 positions in both dimensions, but your loops go up to eleven.

Try

for(int x = 0; x < 10; x++)
  for(int y = 0; y < 10; y++)
     matrix[x][y] = 0;

Notice the use of the lesser than comparator instead of lesser than or equal to.


Need Your Help

unexpected android system call makes smooth display of scrolling graphic stutter

android graphics scroll system real-time

I am currently writing an app that should display a real time measurement curve in a scrolling fashion (think ECG recorder or oscilloscope). An unexpected system call in the UI-Thread makes the dis...

How to say that you need to turn your mobile phone in javascript/css?

javascript html css css3

I have a website wich you can only view on a horizontal way.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.