![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2006
Posts: 5
Rep Power: 0
![]() |
Strange bug with a 2d array
Edit: I was changing a value that didn't exist. It's been a long day. Mods, feel free to delete this.
![]() Hi all. I have no idea why this is happening, but whenever I change a value in my array to 1, it also changes the value in another place. It only does this when I try to change the last item on the first row. Here's a bit of code I made to illustrate what's happening in my larger program. #include <iostream>
using namespace std;
int main() {
int matrix[3][3];
matrix[0][3] = 1;
cout << matrix[0][3] << " " << matrix[1][0];
return 0;
}That outputs two 1's on my screen I tried this wth mingw under windows and g++ under linux, same thing. Which leads me to believe I'm probably missing something really simple. Thanks for the help ![]() Last edited by ZenOswyn; Nov 20th, 2006 at 8:08 PM. Reason: I was being stupid |
|
|
|
|
|
#2 | |
|
Programmer
Join Date: Mar 2006
Posts: 60
Rep Power: 3
![]() |
Quote:
So, for example, if you try the following you will see that matrix[1][0] will not be identical to the value that is assigned to matrix[0][3]: #include <iostream>
using namespace std;
int main() {
int matrix[4][4];
matrix[1][0] = 3;
matrix[0][3] = 2;
cout << matrix[0][3] << " " << matrix[1][0];
return 0;
} |
|
|
|
|
|
|
#3 |
|
Hobbyist Programmer
|
arrays start counting on 0. 0,1,2,3... but we normaly count on 1. 1,2,3,4... so when you say int list[3]; the varius indexes are list[0], list [1], list[2].
__________________
i dont know much about programming but i try to help |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| strange symbol | hush | Visual Basic .NET | 4 | Aug 26th, 2006 1:35 PM |
| changing size of an array | Eric the Red | Java | 3 | Apr 3rd, 2006 9:19 PM |
| string array problem | MADTech | C++ | 8 | Jul 27th, 2005 7:19 AM |
| Installing IPB 2.03 | bh4575 | Other Web Development Languages | 0 | Apr 23rd, 2005 3:36 AM |
| Converting 1-dimensional array to 2-dimensional array | Tazz_Mission_13 | Java | 6 | Apr 8th, 2005 12:58 PM |