Unspoken rules in the IF brackets

Source: Internet
Author: User

650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0013.gif "alt=" J_0013.gif "/> True and false judgment

1. Comparison of Boolean variables with 0
You cannot compare Boolean variables with true FALSE 0 or 1.

if (flag==true)//Bad style if (flag==1)//Bad style

The Boolean type represents nonzero as true (true), non-zero is False (false), but true and false do not have a uniform standard when defined, such as true in Visual C + + 1, and 1 in Visual Basic.

if (flag)//is expressed as true if (! Flag)//denotes false

2. Shaping variables and 0 comparisons
Compare directly to 0

if (value==1)//correct style if (value)//bad style, cannot imitate Boolean type style write

3. Floating-point variable versus 0-value comparison
You cannot compare floating point numbers with = = or! = with any number. Due to the limitation of precision, it should be managed to convert to <= or >=

if (X<=epsinon)//epsion i.e. accuracy, allowable error, generally very small

4. Pointer variable versus 0 value comparison
Pointer variables are directly compared to NULL with! = or = =

In the IF statement has bad style and good style, good style written code is simple and easy to understand and beautiful, bad code written out others will think your C language is not standard, appear very low. I hope we all develop a good writing style yo ~650) this.width=650; "Src=" Http://img.baidu.com/hi/jx2/j_0037.gif "alt=" J_0037.gif "/>

This article is from the "incomparable Warm yang" blog, please be sure to keep this source http://10797127.blog.51cto.com/10787127/1757944

Unspoken rules in the IF brackets

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.