Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


++ operator

Posted on 2004-11-20
Medium Priority
Last Modified: 2010-03-31

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.
Question by:Ravi Singh
LVL 13

Accepted Solution

petmagdy earned 200 total points
ID: 12633562
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
LVL 18

Author Comment

by:Ravi Singh
ID: 12633591
thanks for clearing that up.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month12 days, 4 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question