6.5. Types, Constants and Expressions

Use constants with the correct type [CONSTANT]

Use 0 for an integer or real constant, '\0' for a character constant and NULL for a pointer constant. If you mean '0', write '0', not 48. If you mean '\n', write '\n', not 10.

Only use boolean operations on boolean values [BOOLEAN-OP]

Boolean operations (!, && and ||) should only be used on boolean values (which are known to be 0 or 1). Do not use them on integers, pointers, etc. (But see the exception in the next entry.)

Conditions should be boolean [BOOLEAN-CONDITION]

The condition in an if-statement, while-statement, for-statement, do-statement, or any other construct that performs a yes/no test should be a boolean value. It should not be a number or a pointer.

An exception is an expression that uses the ctype library, such as isdigit(c) and isalpha(c). Those can be used in tests as boolean values.

Do not use == true or == false [BOOLEAN-EQ]

An if-statement, while-statement, etc. tests whether its condition is true. Do not write something like
  if(isEmpty(x) == true)
where you redundantly ask if isEmpty(x) is true. Write
  if(isEmpty(x))
Use ! for negation. Instead of
  if(isEmpty(x) == false)
write
  if(!isEmpty(x))

Do not use if(x = y) [ASSIGN-IN-TEST]

Even if it is what you intend to write, do not use an assignment as the test in an if, while, do or for statement.

Avoid long and complicated expressions

Do not use long, complicated expressions that are difficult to read and understand. Do not make excessive use of ! in boolean expressions.

Do not use a statement that has no effect [NO-EFFECT]

Do not write a statement such as
  x + 1;
that does nothing. If you really want to do nothing, use { }.