Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top