Getting started
Function pointers
Operators
Data types
Arrays
Undefined behavior
Random numbers
Preprocessor and macros
Signal handling
Variable arguments
Files and I/O streams
Assertion
Linked lists
Generic selection
X-macros
Function parameters
Pointers
Structs
Sequence points
Command-line arguments
Aliasing and effective type
Compilation
Identifier scope
Bit-fields
Strings
Comman pitfalls
Common pitfalls
Mixing signed and unsigned integers in arithmetic operations
Macros are simple string replacements
Forgetting to copy the return value of realloc into a temporary
Forgetting to allocate one extra byte for 0
Misunderstanding array decay
Forgetting to free memory memory leaks
Copying too much
Mistakenly writing instead of when comparing
Incautious use of semicolons
Adding a semicolon to a define
Newline character is not consumed in typical scanf call
Checking logical expression against true
Undefined reference errors when linking
Doing extra scaling in pointer arithmetic
Multi-line comments cannot be nested
Comparing floating point numbers
Ignoring return values of library functions
Floating point literals are of type double by default
Recursive function missing out the base condition
Using character constants instead of string literals and vice versa
Overstepping array boundaries
Passing unadjacent arrays to functions expecting real multidimensional arrays
Error handling
Implicit and explicit conversions
Type qualifiers
Valgrind
Typedef
Selection statements
Declaration vs. definitio
Standard math
Boolean
Literals for numbers, characters and strings
Storage classes
Declarations
Formatted Input/Output
Compound literals
Inline assembly
Threads native
Initialization
Structure padding and packing
Memory management
Implementation-defined behaviour
Atomics
Iteration statements, loops, for, while, do-while
Enumerations
Jump Statements
Create and include header files
Testing frameworks
ctype.h characters classification
Pass 2D-arrays to functions
Side effects
Multi-character character sequences
Constrains
Inlining
Unions
Multi-threading
Common idioms and developer practices
Inter-process communication (IPC)
Comments
Contributors

Incautious use of semicolons

suggest change

Be careful with semicolons. Following example

if (x > a);
   a = x;

actually means:

if (x > a) {}
a = x;

which means x will be assigned to a in any case, which might not be what you wanted originally.

Sometimes, missing a semicolon will also cause an unnoticeable problem:

if (i < 0) 
    return
day = date[0];
hour = date[1];
minute = date[2];

The semicolon behind return is missed, so day=date[0] will be returned.

One technique to avoid this and similar problems is to always use braces on multi-line conditionals and loops. For example:

if (x > a) {
    a = x;
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents