What is the increment operator?

August 7th, 2009 by uCertify Leave a reply »

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

The increment 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 increment operator increases 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-increment operator, the value of operand a is first incremented 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-increment operator, the initial value of variable a is first assigned to variable b and then the value of a is incremented by 1.

  • 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.