desglose[][]
is referencing a two-dimensional array (a matrix). Which its value in position [a][c]
is being assigned to 0
.
For example: If you have a 3X3 matrix, it would look something like this:
j j j
i [][][]
i [][][]
i [][][]
If you mix two for cycles (as it seems to be your case) to fill the matrix with zeros you should do something like this:
for(int i = 0; i < 3; ++i){
for(int j = 0; j < 3; ++j){
desglose[i][j] = 0;
}
}
Where the first cycle for corresponds to the value of your rows and that of the second cycle corresponds to your columns.
We can see it in the following way. In the first for cycle, which is repeated 3 times, a for cycle is created, which is repeated 3 times. This means that in the first iteration of the first cycle for the variable i
will have a value of 0
. This value will continue in 0
for the 3 turns of the second for cycle. Where the variable j
will increase.
desglose[0][0] = 0; // [variable i][variable j]
desglose[0][1] = 0; // [variable i][variable j]
desglose[0][2] = 0; // [variable i][variable j]
After fulfilling 3 iterations within the variable cycle j
, the value of variable i
of the first cycle is increased by 1. Whereas the variable j
returns to a value of 0
and is increased again 3 times.
desglose[1][0] = 0; // [variable i][variable j]
desglose[1][1] = 0; // [variable i][variable j]
desglose[1][2] = 0; // [variable i][variable j]
This means that if the first for cycle has n
iterations and the second cycle has m
iterations a total of n*m
iterations will be made to fill the matrix. In this case it is a matrix of 3*3
.