1

I know that this question is similar to this one, but I feel like I don't fully understand C99 standard. I want to ask about parameter evaluation itself, for example:

int index = 0;
sprintf(somebuf, "some-text-%d", index++);

So, it seems like index is not incremented before function call (I got some-text-0 as a result). Is it expected behavior?

Andy
  • 187
  • 2
  • 11

1 Answers1

2

By using the post-increment operator (++ follows index), the value is used first, then incremented. If you wanted to use the incremented value, you should have used the pre-increment operator (++index). FYI, this dates back to the earliest versions of C.

SGeorgiades
  • 1,771
  • 1
  • 11
  • 11