Wrong multi-dimensional array variables increase in C
-
28-04-2021 - |
Frage
I have the curiosity to know the behaviour, in C, of a multidimensional array increased as below:
int x[10][10];
y = x[++i, ++j];
I know that is the wrong way. I just want to know what the compiler do in this case and what will be the consequence if a programmer do this in his code.
Lösung
That is the comma operator, misused. ++i, ++j
yields the value of j + 1
and has 2 side effects (modifying i
and j
). The whole thing basically means ++i; y = x[++j]
. Which will work or not, depending on the type of y
.
what will be the consequence if a programmer do this in his code
Well, most likely other programmers will give him/her murderous looks.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow