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. |
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.) |
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. |
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)) |
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. |
Do not use long, complicated expressions that are difficult to read and understand. Do not make excessive use of ! in boolean expressions. |
Do not write a statement such as
x + 1;that does nothing. If you really want to do nothing, use { }. |