Two-dimensional array, IF condition check

advertisements

I've came across a problem when coding with C++ 2D array. Just a little question, what does the code below mean?

...

if(array[x][y] >= 9){

...

}

...

Does that mean when the sum of x and y of the array is greater or equal to 9, then only the body of the IF will run? Or ........?

Please explain and provide some simply examples.


the array is two dimensional, it means the element at array[x][y]

unlike 1D arrays, which only require 1 index, 2D arrays require 2 indices in the form of array[x][y] presumably in a nested for loop.

You can iterate through such an array like this

for (int x = 0; x < arrayLength; x++) {
    for (int y = 0; y < array[x]Length; y++) {

    // do something with array[x][y]

    }
}

where arrayLength is the length of array and array[x] length is the length of array[x].

So in reference to the code that you posted, it's testing to see if the member of the 2D array is greater than or equal to 9.