Java Learning Made Easy by Dheeraj Mehrotra - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

Increment & Decrement Operators

01646.jpg01647.jpg

 

The increment operator is indicated by ++ and is used to 01648.jpg01649.jpgincrement the variable by 1.

 

01650.jpg01651.jpg01652.jpg01653.jpgeg. ++marks;

 

01654.jpg01655.jpgincrements the value of the variable marks by 1.

 

01656.jpg01657.jpg01658.jpg01659.jpg

It can be used in two ways : as a prefix, (++var), meaning that

01660.jpg

the operator precedes the variable; and as a postfix, (var++), where the operator follows the variable.

01661.jpg01662.jpg01663.jpg01664.jpg

In prefix the variable gets incremented first where as in postfix

01665.jpg

the variable gets incremented after the operation of function of its associate operator.

01666.jpg01667.jpg01668.jpg01669.jpg

Decrement Operators are similar to Increment Operators except

01670.jpg

the fact for the operation of decrementation by 1. It can also be

01671.jpg

used both as prefix and postfix forms of its format.

01672.jpg

eg. --marks;

01673.jpg

is used to decrement the value of marks by 1.

01674.jpg01675.jpg01676.jpg01677.jpgattention@computerscienceexpertise.com

 

01678.jpg01679.jpg01680.jpg01681.jpg01682.jpg01683.jpg01684.jpg01685.jpg01686.jpg01687.jpg01688.jpg01689.jpg01690.jpg01691.jpg01692.jpg01693.jpg01694.jpg01695.jpg01696.jpg01697.jpg