Unary - A note on increment and decrement and operators...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
A note on increment and decrement, ++ and --, operators whether used as prefix or postfix with variables. They work only with integer variables, not on floating point variables. They are just short hand notations for adding one to or subtracting one from a number. As we have practiced in a programming exercise 3b, you know the different meaning in each pre-and post- case: Postfix: Placing the increment or decrement operator in after the variable means to use the value first, then increment (or decrement) it. x++ ; // is equivalent to x = x + 1; x-- ; // is equivalent to x = x -1 ; Prefix When placing the increment or decrement operator in front of the variable, you intent to increment (or decrement) the value first before using the variable. ++y; // y is add 1 first and the value is being used to represent y. -- y; // y is subtracted 1 first and the value is being used to represent y. If we want to add or subtract more than one to or from a number, we can use a similar
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/20/2010 for the course MATH 107 taught by Professor Christinashow during the Spring '08 term at Mesa CC.

Page1 / 2

Unary - A note on increment and decrement and operators...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online