What is the decrement operator?

July 16th, 2009 by uCertify Leave a reply »

The decrement operator is a unary operator that decreases the value of its operand by one. For example, the expression a– decreases the value of a by 1. This statement is equivalent to the expression a = a – 1.

The decrement operator can be used in either of the two forms given below:

  1. Prefix form: In the prefix form, it appears before the operand. For example, –a;
  2. Postfix form: In the postfix form, it appears after the operand. For example, a–;

In both forms given here, the decrement operator decreases the value of the operand (a) by 1. However, when these two expressions are a part of a larger expression, they create a significant difference in the value of the expression. For example,

b = –a;
b = a–;

In the first statement, due to the pre-decrement operator, the value of operand a is first decreased by 1 and then this new value of a is assigned to variable b. On the other hand, in the second statement, due to the post-decrement operator, the initial value of variable a is first assigned to variable b and then the value of a is decreased by 1.

Like this article? Share it with others
If you like this article, please leave a comment or subscribe this blog via RSS or via e-mail, Bookmark and share through your network. Click the AddThis button below. Thanks.
  • Share/Bookmark
Advertisement

Leave a Reply

uCertify.com | Our Company | Articles | Contact Us | News and Press Release | uCertify India | Entries (RSS)
MCSE: MCSA, MCTS, MCITP    JAVA Certification: SCJP, SCWCD    Cisco Certification: CCNA, CCENT    A+, Network+, Security+ Project+
Oracle Certification: OCP 11g, OCP 10g, OCA 11g, OCA 10g    CIW foundation    EC-212-32,    CISSP    Photoshop ACE CS4    Adobe Flash ACE, PMP, CAPM
© 2008 uCertify.com. All rights reserved. All trademarks are the property of their respective owners.