When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.
14 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.
In C you can combine expressions
A common thing is something like this:
while (i < max)
{
int a = foo[i++];
int b = foo[i++];
...
}
Here int a = foo[i++]; is the same as doing this:
int a = foo[i];
i++;
We can also do it the other way, first update:
int a = foo[++i];
This is the same as:
i++;
int a = foo[i];
Now we can do this inside a complex expression, like this:
int a = ++i < 10 ? j++ : ++k;
The above can be rewritten like this:
++i;
int a;
if (i < 10)
{
a = j;
j++;
}
else
{
k++;
a = k;
}
Once you understand the above you can understand how you can both combine < and -- inside of () into an expression.