val = n++ + arr[n];
How can I rewrite the line of code above to become more readable? How is this code evaluated by a compiler?
val = n++ + arr[n];
How can I rewrite the line of code above to become more readable? How is this code evaluated by a compiler?
This code is invalid (reason) so you should bin it.
It is better to write more lines to keep the code readable and correct than to write "hacky" complex expressions.
val = n + arr[n];
n++;
It's not a matter of readability. That's undefined behavior.
In C +
is not a sequence point, therefore you can't know if n++
will be executed before or after arr[n]
Sequence points in the C standard
See the section relative to Program execution
The presence of a sequence point between the evaluation of expressions A and B implies that every value computation and side effect associated with A is sequenced before every value computation and side effect associated with B. (A summary of the sequence points is given in annex C.)
It depend on the case, You can do like this.
val = n + arr[n + 1];
n++;