Is I ++ and I really no different? I + = 1 is no different from I + 1

Source: Internet
Author: User

WriteArticleRecord small knowledge points.

The first is I ++ and ++ I. Here I am talking about performance problems, rather than being equal to I or equal to I + 1, in fact, it is easy to know that the performance of ++ is better than that of I ++, But weProgramIf it is not affected, I ++ will be used; in fact, this is not a good practice, at least the performance is slightly poor.

++ I simulation:

 
Int fuction () {I = I + 1; return I ;}

I ++ simulation:

 
Int function () {int temp = I; I = temp + 1; return temp ;}

I ++ has more temp and the performance is not good. We recommend that you select ++ I without affecting the program logic ..

 

I + = 1 and I = I + 1.OneYou can see examples frequently.The following statement is as follows:It is based on a language without automatic forced type conversion, such as Java, which does not include C ++.

Example1:

 
Short I = 1; I = I + 1;

Example2:

 

 
Short I = 1; I + = 1;

 

Based on that premise, example1 will certainly have compilation problems. It is not feasible to assign int to short, but example2 is no problem ..

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.