Search: | |||||

| ||||

Home » Forum » Java | RSS Feeds |

I'm rereading the beginning chapters of the textbook by Walter

Savitch and in Chapter 2, there is a paragraph about increment and

decrement operators in expressions.

I understand, on page 67 and 68, what the paragraph said about the

following and how the result is 15:

int n=3;

int m=4;

int result;

result=n* ++m;

result = 3 * (m=4+1)

result = 3*5

result =15

I understand that the ++m increases the value of m by 1 before it

does the multiplication.

What I don't understand is why is the answer to the next expression

12 instead of 13?

int n=3;

int m=4;

int result;

result=n* m++;

result = 3*(m=4+1)

result = 3*4

result =12

In this second expression, the book says that if the ++ is after the

m, then the value of m is increased after its value is used in the

expression. What happened to the increase of 1 in "4+1". Do you

just discontinued the rest of the value in m=4+1. My way of

thinking would be:

result=3*(m=4+1)

result=3*(4)+1

I just can't understand why m=4+1 stays a 4 all the time. What

happens to the 1?

I appreciate any instruction. I'm trying to get through chapters 1

through 5 before I take my next semester of Java.

Didn't find what you were looking for?
Find more on Increment & Decrement Operator in Expressions
Or get search suggestion and latest updates.

Related Topics:

- post vs pre increment implementation
- Problem in incrementing
- incrementing and scope
- Add-Ins loaded into Excel
- Relation between "new" operator and "ClassLoader" class ?
- Bitwise Operators
- == operator problem
- Operator '!=' cannot be applied to operands of type 'System.DateTim
- Operator Overloading in VB.Net
- Bit operators in EJBQL
- operator ^ cannot be applied to double
- pls casting operator with example
- Regular expression
- Regular expressions
- Binary tree for algebraic expression
- AND - Only two expressions
- Converting Expression from postfix to infix
- regular expression object in java
- Regular expression help