-2

This is a much discussed question however my doubt is that in C, *t++ is equivalent to *(t++) as precedence of ++ (post increment operator) is greater than *. Therefore,in while (*t++ = *s++); won't the first character be skipped while copying from s to t; To frame it better, will the copy take place before the increment operator or afterwards and why?

sb18
  • 1
  • 1

1 Answers1

2

No, the first character won't be skipped. The result of evaluating t++ (post-increment) is the value of t before the increment occurred, so the pointer dereference goes to the position pointed to before t was incremented. You can use the pre-increment operator (++t) to increment t and produce the value after the increment.

Todd Knarr
  • 1,255
  • 1
  • 8
  • 14