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"