<< Chapter < Page | Chapter >> Page > |
The program in Listing 3 uses both the prefix and postfix forms of the increment operator. (This discussion also applies to the prefix and postfix forms of the decrement operator.)
Outside of another expression
If the increment operator is applied to a variable outside of another expression, as is the case with ++w and x++ in Listing 3 , it doesn't matter whether it is of the prefix or postfix form. The end result will the same in both cases. The value will have been incremented thenext time the variable is referenced. (This is also the case with the use of the increment operator in the adjustment clause of the for loop in Listing 2 .)
Inside of another expression
However, if the increment operator is applied to a variable inside another expression, as is the case with y++ and ++z in Listing 3 , the end result may depend on whether the prefix or postfix form is used.
Rules
Here is a pair of rules that govern such behavior:
And the answer to the question is...
C. 6 51 500 501 5001 5001
I encourage you to run the programs that I have presented in this lesson to confirm that you get the same results. Copy the code for each program into yourIDE. Then compile and run each program. Experiment with the code, making changes, and observing the results of your changes. Makecertain that you can explain why your changes behave as they do.
This section contains a variety of miscellaneous materials.
Financial : Although the Connexions site makes it possible for you to download a PDFfile for this module at no charge, and also makes it possible for you to purchase a pre-printed version of the PDF file, you should be aware thatsome of the HTML elements in this module may not translate well into PDF.
I also want you to know that, I receive no financial compensation from the Connexions website even if you purchase the PDF version of the module.
In the past, unknown individuals have copied my modules from cnx.org, converted them to Kindle books, and placed them for sale on Amazon.comshowing me as the author. I neither receive compensation for those sales nor do I know who does receive compensation. If you purchase such a book, pleasebe aware that it is a copy of a module that is freely available on cnx.org and that it was made and published without my prior knowledge.
Affiliation : I am a professor of Computer Information Technology at Austin Community College in Austin, TX, and have noaffiliation with the College Board .
-end-
Notification Switch
Would you like to follow the 'Ap computer science a, clarification of the java subset' conversation and receive update notifications?