Originally posted by Kumaran Pillai:
Thanks Keith for your brief explanation.
But my doubt is : In the line m = m++ , as you said, the value of M ( which is 1 because of previous increment) will be assigned to M and after it gets incremented as per the Post increment rule. But when i try to print the value of M, instead of giving 2, it is giving the output as 1. Will the value alone be assigned to M and the increment will happen after the value gets printed ?
Could you shed some more light on this area which will be appreciable.
Thanks,
Kumaran,
This is your original code.
In line 1, the value of ++m is 1 since that will be the value of m after the increment. Then you assign 1 to m.
In line 2, the value of m is 1, so the value of m++ is 1. Even though m++ will increment m to 2, the assignment is performed after that. Since the value of m++ is 1, m is reset to 1.