++ operator


whats the difference between doing:


int len = 0;

array[++len] = "hello";
array[len++] = "bye";

Using the incrementing operator as a prefix or postfix, is it effectively the same thing?
I looked at the official java tutorial and it says:

++          op++    Increments op by 1; evaluates to the value of op before it was incremented
++       ++op       Increments op by 1; evaluates to the value of op after it was incremented

Don't understand what it means by "evaluates to the value of op before it was incremented". Can someone explain it in terms of my example above. And also, is this what people mean by 'efficient' programming, i.e. putting what could be two statements into one.

Cheers - Zephyr.
LVL 18
Ravi SinghSenior Software EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

if u tried
 int len = 0;

array[++len] = "hello";
array[len++] = "bye";

then "hello" will be inserted at index 1 and then "bye" will overwrite at the same index

>>what it means by "evaluates to the value of op before it was incremented"?

means if ++len is in a statment the statment will use the len value after the increament but if len++ it will use the len value before the increament

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ravi SinghSenior Software EngineerAuthor Commented:
thanks for clearing that up.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.