# WHAT ARE INCREMENT AND DECREMENT OPERATORS AND POST FIX AND PREFIX OPERATORS IN JAVA???

2
by irasangwan
++ and -- are increment and decrement operators. Postfix operator is ++ or --. Let x= 10. Expression 5 + (x--) means x is decremented to 9. But to the + operator value returned by expression in paranthesis is equal to 10, previous value. Answer is 15. For prefix operator like -, --, ++. Let x = 10 and we have 5 + (--x) then x is decremented first, so x is now 9. Value returned by parantheses to + operator is also 9. SO answer is 14.

2014-08-01T21:08:43+05:30
++   the increment operator increments a value by 1.
--   the decrement operator decrements a value by 1
class PrePostDemo
{
public static void main(String[] args)
{
int i = 3;
i++;
System.out.println(i); // "4"
++i;
System.out.println(i); // "5"
System.out.println(++i); // "6"
System.out.println(i++); // "6"
System.out.println(i); // "7"
}
}
Click on Thank you if you find it useful
2014-08-01T21:59:43+05:30
++   the increment operator increments a value by 1.
--   the decrement operator decrements a value by 1.
however a++ and ++a have the same result if used as a single .statement as in
{ int a=9;
a++;
System.out.println(a);
}
will give the same result as in
{int a=9;
++a;
System.out.println(a);
}