C Compiler Logo

Type Mismatch in Assignment

Undeclared Variable

syntax

error: 'x' undeclared (first use in this function)

Description

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

Common Causes

Example of Error

Error Code

int main() {
    x = 10;
    printf("Value: %d\n", x);
    return 0;
}

Solution

Declare the variable before using it.

Corrected Code

int main() {
    int x;
    x = 10;
    printf("Value: %d\n", x);
    return 0;
}

Additional Tips