Common C Programming Errors
Identify and understand frequent mistakes in C code.
Missing Semicolon
error: expected ';' before '}' token
A semicolon is missing at the end of a statement. In C, most statements must end with a semicolon to indicate the end of the statement.
Unmatched Parentheses, Braces, or Brackets
error: expected ')' before ';' token
Parentheses, braces, or brackets are not properly matched. Every opening symbol must have a corresponding closing symbol.
Undeclared Variable
error: expected ')' before ';' token
Using a variable that hasn't been declared. In C, all variables must be declared before use.
Invalid Syntax in Control Statements
error: expected expression before ')' token
Incorrect syntax in control statements like if, for, while, or switch.
Missing Header File
error: implicit declaration of function 'printf'
Using a function without including the appropriate header file.
Type Mismatch in Assignment
warning: assignment makes integer from pointer without a cast
Assigning a value of one type to a variable of an incompatible type.
Function Return Type Mismatch
warning: return makes integer from pointer without a cast
Returning a value that doesn't match the function's declared return type.
Incompatible Function Arguments
warning: passing argument 1 of 'function' makes pointer from integer without a cast
Passing arguments to a function that don't match the function's parameter types.
Using Uninitialized Variables
warning: 'x' is used uninitialized in this function
Using a variable before it has been assigned a value.
Array Index Out of Bounds
warning: array index 5 is past the end of the array
Accessing an array element with an index that is outside the array's bounds.
Undefined Reference to Function
undefined reference to 'customFunction'
The linker cannot find the implementation of a function that is called in the code.
Multiple Definition of Symbol
multiple definition of 'globalVar'
The same symbol (variable or function) is defined in multiple source files.
Undefined Reference to Main
undefined reference to 'main'
The linker cannot find the main function, which is the entry point of a C program.
Undefined Reference to Standard Library Function
undefined reference to 'sqrt'
The linker cannot find a standard library function that is used in the code.
Segmentation Fault
Segmentation fault (core dumped)
The program tried to access memory it doesn't have permission to access.
Bus Error
Bus error (core dumped)
The program tried to access memory in a way that is not allowed by the hardware, often due to alignment issues.
Floating Point Exception
Floating point exception (core dumped)
The program performed an invalid floating-point operation, such as division by zero.
Stack Overflow
Segmentation fault (core dumped)
The program's call stack exceeded its maximum size, often due to infinite recursion.
Memory Leak
No runtime error, but program consumes increasing amounts of memory
The program allocates memory but never frees it, causing the program to consume more and more memory over time.
Double Free
double free or corruption
The program attempts to free memory that has already been freed.
Use After Free
heap use after free
The program uses memory after it has been freed, which can lead to unpredictable behavior.
Buffer Overflow
stack smashing detected
The program writes data beyond the end of a buffer, which can overwrite adjacent memory and lead to security vulnerabilities.
Memory Corruption
heap corruption detected
The program writes to memory in a way that corrupts the heap or stack, often leading to crashes or unpredictable behavior.
Invalid Free
invalid free()
The program attempts to free memory that was not allocated with malloc/calloc or has already been freed.
Unused Variable
warning: unused variable 'x'
The program declares a variable but never uses it, which might indicate a logic error or unnecessary code.
Implicit Function Declaration
warning: implicit declaration of function 'customFunction'
The program calls a function without declaring it first, which can lead to unexpected behavior.
Comparison Between Signed and Unsigned
warning: comparison between signed and unsigned integer expressions
The program compares signed and unsigned integers, which can lead to unexpected results due to type conversion.
Format String Mismatch
warning: format '%d' expects argument of type 'int', but argument has type 'char *'
The format specifier in a printf or scanf function doesn't match the type of the provided argument.
Shadowing Variable
warning: declaration shadows a variable in a wider scope
A variable is declared with the same name as a variable in an outer scope, hiding the outer variable.
Missing Library
cannot find -lmylib
The linker cannot find a library that is specified in the compilation command.