I was wondering if there was an overhead involved in using post increment operator instead of pre. If the compiler optimizes the code if there is no assignment done while using post operator, there should be no overhead? But is it true?
It depends, for basic types you may or not see any difference.
For classes depends on the implementation, if the post increment is defined to return a temporary object, it will have some overhead caused by the construction of that object
If you use built-in types(such as int) there is no difference in performance.
But if you use custom class then pre increment is faster and compiler can't optimize it.