# Thread: Simple Question

1. ## Simple Question

Hi All, simple question i hope,

Just wanted some clarification on some of the arrays i've being fiddlng with, i won't get into to much detail but essentially a 2D array comprising two integers X and Y.

i.e: Grid[X][Y];

With X and Y set to 5 for example.

Now if i want to look at Grid[4][5], i can simply do Grid[--X][Y] and this allows me to look at those 'coordinates' and also sets the integer X to value 4.

Now what i wanted to ask is whether looking at Grid[3][5] by simply doing Grid[X-2][Y] ALSO changes the value of the integer X by -2 to the value 3 or whether it only allows me to look at the 'coordinates' but not change the integer?

Hope that was all clear, any help is appreciated

Regards Wolfe

2. GRID[X-1][Y] will get you value at "X less one", Y, in your example 4,5. GRID[X-2][Y] does "x less two", Y, and in your example 3, 5. Neither case will change the value of X.

--
Mats

3. Thanks, by the way [--X] will change the value of X, well looks like i've got some changes to do

Thanks Wolfe

4. Originally Posted by Cdrwolfe
Thanks, by the way [--X] will change the value of X, well looks like i've got some changes to do

Thanks Wolfe
Yes, --X or X-- will change the value of X. As will X += 2, X -=2 and X++.

--
Mats

5. Originally Posted by Cdrwolfe
Thanks, by the way [--X] will change the value of X, well looks like i've got some changes to do

Thanks Wolfe
You could just change --X to X-1...

QuantumPete

6. Originally Posted by QuantumPete
You could just change --X to X-1...

QuantumPete
Sorry, but i needed the actual value of X to change as well after it had been 'scanned' so to speak. saves me having to add in a line X = X - 1; later one even though i still have to do it for X - 2 .

Regards Wolfe

7. Originally Posted by Cdrwolfe
Sorry, but i needed the actual value of X to change as well after it had been 'scanned' so to speak. saves me having to add in a line X = X - 1; later one even though i still have to do it for X - 2 .

Regards Wolfe
Well, that's what I mean, if you change --X to X-1, you can then treat it the same way as X - 2, which will save you special conditions depending on whether you're subtracting one or two. Implicit code is always better than explicit code.

QuantumPete

8. if you did --X once for getting the 4 value so to speak, and you did it again it would get the 3 value, without having to do X - 2.

Code:
```grid[x][y]; //say its at 5,5 to start

grid[--x][y]; //this is now 4,5

grid[--x][y]; //now its 3,5```

Popular pages Recent additions