C Compiler Logo

Errors

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.

syntax
View Solution

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.

syntax
View Solution

Undeclared Variable

error: expected ')' before ';' token

Using a variable that hasn't been declared. In C, all variables must be declared before use.

syntax
View Solution

Invalid Syntax in Control Statements

error: expected expression before ')' token

Incorrect syntax in control statements like if, for, while, or switch.

syntax
View Solution

Missing Header File

error: implicit declaration of function 'printf'

Using a function without including the appropriate header file.

syntax
View Solution

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.

semantic
View Solution

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.

semantic
View Solution

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.

semantic
View Solution

Using Uninitialized Variables

warning: 'x' is used uninitialized in this function

Using a variable before it has been assigned a value.

semantic
View Solution

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.

semantic
View Solution

Undefined Reference to Function

undefined reference to 'customFunction'

The linker cannot find the implementation of a function that is called in the code.

linker
View Solution

Multiple Definition of Symbol

multiple definition of 'globalVar'

The same symbol (variable or function) is defined in multiple source files.

linker
View Solution

Undefined Reference to Main

undefined reference to 'main'

The linker cannot find the main function, which is the entry point of a C program.

linker
View Solution

Undefined Reference to Standard Library Function

undefined reference to 'sqrt'

The linker cannot find a standard library function that is used in the code.

linker
View Solution

Segmentation Fault

Segmentation fault (core dumped)

The program tried to access memory it doesn't have permission to access.

runtime
View Solution

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.

runtime
View Solution

Floating Point Exception

Floating point exception (core dumped)

The program performed an invalid floating-point operation, such as division by zero.

runtime
View Solution

Stack Overflow

Segmentation fault (core dumped)

The program's call stack exceeded its maximum size, often due to infinite recursion.

runtime
View Solution

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.

runtime
View Solution

Double Free

double free or corruption

The program attempts to free memory that has already been freed.

memory
View Solution

Use After Free

heap use after free

The program uses memory after it has been freed, which can lead to unpredictable behavior.

memory
View Solution

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
View Solution

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.

memory
View Solution

Invalid Free

invalid free()

The program attempts to free memory that was not allocated with malloc/calloc or has already been freed.

memory
View Solution

Unused Variable

warning: unused variable 'x'

The program declares a variable but never uses it, which might indicate a logic error or unnecessary code.

warning
View Solution

Implicit Function Declaration

warning: implicit declaration of function 'customFunction'

The program calls a function without declaring it first, which can lead to unexpected behavior.

warning
View Solution

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.

warning
View Solution

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.

warning
View Solution

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.

warning
View Solution

Missing Library

cannot find -lmylib

The linker cannot find a library that is specified in the compilation command.

warning
View Solution