I know that && can be used to check if the both conditions are satisfied when it is used in a conditional statement but how do you explain
full[i][j] = open[i][j] && full[i - 1][j]; ??
In case we are reading this piece of code how do we explain this?
Notice that full and open are two 2D Boolean arrays
//i = column j = row
for (int i = 1; i < N; i++) {
for (int j = 0; j < N; j++) {
full[i][j] = open[i][j] && full[i - 1][j];
//^^ what happens here?
}
full[i][j] = open[i][j] && full[i - 1][j];
意味着[i][j] && full[i - 1][j]
将解析为布尔值并将其分配为另一个数组中的布尔元素。
I think (Not 100% sure) that it is assigning values, When we are using primitive data types we can use a single & to do bit wise anding, While we are doing the same for boolean values,
full[i][j] = open[i][j] && full[i - 1][j];
Means we are assigning anded boolean value
of open[i][j]
and full[i-1][j]
to full[i][j]
.
By default all the values of full array are false.
Initially for i=1 and j=0. Value of full[0][0] will false. So whatever open[][] value is , full[1][0] will have false value.
Correct me if I understand your question worong.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.