| nueur (3) | ||||
|
Hey guys, I'm new to C++ and am getting confused while trying to use a 2d array. Here's my code:
And the output:
My main problem is that when set a value for the last column on row 0, it applys that same value to the first column on row 1 (seen above as with value: 3). My second problem, which only seemed to happen during this test?(maybe it happened before but I missed it) is the crazy values in the last row? If anyone could shed any light on my problem, I'd really appreciate it! Thank you for your time. | ||||
|
|
||||
| TheIdeasMan (1752) | |
|
You are overrunning the bounds of the array. The idiom for doing something 5 times is : for( i=0; i<5; i++ ){}// no less than equal the for loop ends when the end condition becomes false. The array values go from 0 to 4. When you specify [0][5] this really [1][1] because arrays are stored in linear order. Same at the end values starting with [5] are past the end of the array - the last one is [4][4]. HTH | |
|
|
|
| nueur (3) | |
|
Wow, I feel foolish now. Tottally missed that. Thanks a lot for clearing that up IdeasMan. | |
|
|
|
| TheIdeasMan (1752) | |
| No worries - any time, just mark the thread as solved, and we will catch up with you next time - cheers. | |
|
|
|