In-depth understanding of prefix ++ and suffix ++ in C

Source: Internet
Author: User

When I first learned C, it was easy to mix up. Later I wrote an example to explain it in depth. Finally, I understood the difference.

First, when the prefix ++ appears before the variable, the value before the variable calculation will increase by 1, and the variable with the suffix ++ needs to increase its own value after calculation.

Second, the ++ symbol can only be used before and after variables.

The following is a detailed example to learn more about it:

# Include <stdio. h>


Int main ()
{
Int sum = 0, I = 0;
Int J = 0, H = 0;
Int f = 0;

Printf ("The I is % d \ n", I ++ );
Sum = I ++ I;
Printf ("The I is % d \ n", I );
Printf ("the sum is % d \ n", sum );

Sum = ++ J;
Printf ("the J is % d \ n", J );
Printf ("the sum is % d \ n", sum );

Sum = H ++ h;
Printf ("the H is % d \ n", H );
Printf ("the sum is % d \ n", sum );

Sum = H ++ h;
Printf ("the H is % d \ n", H );
Printf ("the sum is % d \ n", sum );

Printf ("the F is % d \ n", ++ F );
H = ++ F;
Printf ("the H is % d \ n", H );
// H ++;
Printf ("the H is % d \ n", H ++ );
Printf ("the H is % d \ n", H = (H ++ ));

Return 0;
}


The running result is as follows:


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.