Example of auto-increment or auto-increment: Similarities and Differences between I ++ and ++ I

Source: Internet
Author: User

# Include <stdio. h> main (I = j =; k = I ++; m = ++ j; printf (

Auto-increment or auto-increment can be divided into two types:

  • I ++ ----> post auto-Increment
  • ++ I ----> auto-Increment

Their similarities are that, whether post-auto-increment or pre-auto-increment, the I value is increased by 1.

In the above Code, I = j = 3, and the values of I and j are both 3. No matter ++ j or I ++, the final value adds 1 to the value of I or j, therefore, the output result is: I = 4; j = 4;

Differences:

The value of post-auto-incrementing I ++ is the value before I + 1, and the value of pre-incrementing ++ I is the value after I + 1;

In the above Code

K = I ++, I ++ is post-auto-increment, k is equal to the value before I + 1, I is 4, and I is 3 before I + 1, so k = 3

M = ++ j, ++ j is the First Auto-increment, and the value of j is equal to the value after j + 1, so m = 4, the value after j + 1 is 4

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.