Amdocs Interview Question
i++ , ++i are equal when they are the single statement of code in a line
i mean
i++;or
++i;
But they will create a difference when used in an expression like below
++i is better in following condition
sum = ++i + (i++) + (i++);
sum = ++i + (++i) + (++i);
when you have such type of expression it(post increment) makes things complex as such things will depend on compiler.
if you want straight forward logic i = i+1, ++i would be more useful.
because if you see two expression written above, i++ would makes result different because post increment will not make i = i+1 in the same line but next
right also return value optimization cant be done with i++ that is the reason y copy c-or is required.
This is really a stupid question
- Anonymous September 29, 2011