Advertisement
ipwxy

Increment & Decrement

Jun 29th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. You can increase a numeric variable's value by 1 using the increment operator: ++
  2.  
  3. number++;
  4.  
  5. You can decrease a numeric value by using the decrement operator: --
  6.  
  7. number--;
  8.  
  9. These are "Post" increment and decrement.
  10.  
  11. 1. The value stored in nunber is modified
  12. 2. The old value is returned
  13.  
  14. If we were to do:
  15.  
  16. int number = 5;
  17. int otherNumber = number++;
  18.  
  19. otherNumber would contain the value 5, number would contain the value 6.
  20. The pre-increment and pre-decrement value return the new number:
  21.  
  22. int number = 5;
  23. int otherNumber = ++number;
  24.  
  25. Now both variables will contain 6.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement