BOOL variable, float variable, pointer variable and integer variable compared to "0 value"

Source: Internet
Author: User

BOOL variable, float variable, pointer variable and integer variable compared to "0 value"

Example 1: writes the If statement of the BOOL flag versus the "0 value" comparison .

Answer:

if (flag)

if (!flag)

The following is a bad style :

I f (f l AG = = TRUE)

I f (f l AG = = 1)

I f (f l AG = = FALSE)

I f (f l AG = = 0)

Example 2: Please write out the IF statement of float x compared to "0 value".

Answer:

const float Epsinon = 0.00001;

if ((x >=-Epsinon) && (x <= epsinon))

You cannot use a floating-point variable with "= =" or "! = "Compare with the number 0 , you should try to convert to" >= "or" <= "this

Class form.

The following is the wrong wording :

I f (x = = 0.0)

I f (x! = 0.0)

Example 3: Please write out the IF statement of Char *p compared to "0 value".

Answer:

if (p = = NULL)

if (P! = NULL)

The following is a bad style :

I f (p = = 0)

I f (P! = 0)

I f (P)

I f (!p)

Example 4: Please write out the IF statement of the int x compared to the "0 value".

Answer:

I f (x = = 0)

I f (x! = 0)

You should use the integer variable with " = = " or "! = = "compares directly to 0 .

cannot imitate the style of a Boolean variable and write it :

I f (x) // can make people misunderstand val UE is a Boolean variable

I f (! X)




This article is from the "Rock Owl" blog, please be sure to keep this source http://yaoyaolx.blog.51cto.com/10732111/1765812

BOOL variable, float variable, pointer variable and integer variable compared to "0 value"

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.