Usually, if I follow instructions ifwith a single expression, I do not need parentheses. For instance:
if (condition) statement1; statement2;
statement2will work anyway. But this does not happen:
for (j = 0; j < size; j++) {
if (size % 2) if (j % 2) *(minmat + j) *= -1.0;
else {
…
}
}
An operator elsemust be associated with the first operator if, but in fact it is associated with the second. To fix this, I have to do this:
for (j = 0; j < size; j++) {
if (size % 2) { if (j % 2) *(minmat + j) *= -1.0; }
else {
…
}
}
But why does this happen when in the first case it is “implied” that the second statement ifis inside the brackets?
source
share