Toggle menu
862
3.8K
30.2K
279.1K
Catglobe Wiki
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Pre and Post Increment and Decrement: Difference between revisions

From Catglobe Wiki
Tungocman (talk | contribs)
Created page with "<span style="font-size:14px;">'''Pre and Post Increment and Decrement'''</span>   <span style="color:#000000;">++x is pre-increment  and --x is pre-decrement</span> ..."
 
Tungocman (talk | contribs)
No edit summary
Line 17: Line 17:
<span style="color:#a52a2a;"><span style="font-size: 12px;">'''Examples'''</span></span>
<span style="color:#a52a2a;"><span style="font-size: 12px;">'''Examples'''</span></span>


<span style="color: rgb(165, 42, 42);"><span style="font-size: 12px;"</span></span>
&nbsp;


<span style="color:#000000;">number a = 1;</span>
<span style="color:#000000;">number a = 1;</span>
Line 52: Line 52:


<span style="color:#000000;">print(c);&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#008000;">// 3</span>
<span style="color:#000000;">print(c);&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#008000;">// 3</span>
[[Category:Operators]]

Revision as of 03:24, 14 September 2011

Pre and Post Increment and Decrement

 

++x is pre-increment  and --x is pre-decrement

x++ is post-increment and x-- is post-decrement

 

With ++x and --x:  means x is incremented BEFORE being used.

With x++ and x--:  means x is incremented AFTER being used.

 

Examples

 

number a = 1;

number b;

b = ++a;

print(b);               // 2

print(a);               // 2

b = --a;

print(b);               // 1

print(a);               // 1

 

number c = 3;

number d;

d = c++;

print(d);                  // 3

print(c);                  // 4

d = c--;

print(d);                 // 4

print(c);                 // 3