C Compiler Logo

Unused Variable

Unused Variable

warning

warning: unused variable 'x'

Description

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

Common Causes

Example of Error

Error Code

int main() {
    int x = 10;  // x is never used
    printf("Hello, World!\n");
    return 0;
}

Solution

Remove unused variables or use them in the code.

Corrected Code

int main() {
    printf("Hello, World!\n");
    return 0;
}

Additional Tips