C Compiler Errors: Find the Right Fix

C Compiler Errors: Find the Right Fix

Start with the first diagnostic in your compiler output. Match the message below, check the likely cause, and open the guide for an explanation and corrected example. Later errors can be consequences of the first one.

Match your error message

  1. Fix “expected declaration at end of input” in C

    Compiler Syntax

    expected declaration or statement at end of input

    Fix “expected declaration at end of input” in C

    Check first: Look for an unclosed function or block earlier in the file. Match each opening brace to its intended closing brace; do not add a brace blindly.

  2. Expected Semicolon in C: Common Compiler Errors & Solutions

    Compiler Syntax

    expected ';' before …

    Expected Semicolon in C: Common Compiler Errors & Solutions

    Check first: Inspect the statement before the reported token. Check for a missing semicolon after a declaration, expression, or struct definition.

  3. Implicit Declaration of Function in C: How to Fix It

    Type & Declaration

    implicit declaration of function

    Implicit Declaration of Function in C: How to Fix It

    Check first: Include the header that declares the function, or put a matching prototype before the call. Check spelling rather than suppressing the diagnostic.

  4. Undefined Reference in C: Fix Main and Linker Errors

    Linker Errors

    undefined reference to … / ld returned 1 exit status

    Undefined Reference in C: Fix Main and Linker Errors

    Check first: Read the undefined-reference message before the final linker status. Confirm the function is defined and its source file or library is included in the link.

  5. Segmentation Fault in C: Common Causes and How to Fix It

    Runtime Signals

    Segmentation fault (core dumped) / SIGSEGV

    Segmentation Fault in C: Common Causes and How to Fix It

    Check first: Check the failing memory access: pointer validity, array bounds, object lifetime, and writes to string literals. A backtrace or sanitizer can help locate it.

  6. Floating Point Exception in C (SIGFPE): Root Causes & Fixes

    Runtime Signals

    Floating point exception (core dumped) / SIGFPE

    Floating Point Exception in C (SIGFPE): Root Causes & Fixes

    Check first: Inspect integer division and remainder operations for a zero divisor or signed quotient overflow. Despite the name, SIGFPE is not limited to floating-point arithmetic.

  7. Assignment to Expression with Array Type in C: Why It Fails

    Type & Declaration

    assignment to expression with array type

    Assignment to Expression with Array Type in C: Why It Fails

    Check first: Initialize the array at declaration or copy elements into its storage with checked capacity. Array assignment is not pointer reassignment.

  8. Format Expects Argument of Type in C: Match printf Specifiers

    Type & Declaration

    format expects argument of type / printf format mismatch

    Format Expects Argument of Type in C: Match printf Specifiers

    Check first: Match the conversion to the actual argument type: %zu for size_t, %ld for long and %p for a void pointer.

Compiler wording varies by version. Signal numbers and shell exit statuses are platform-dependent; use the diagnostic and failing operation rather than an exit code alone.