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
- Using a variable without declaring it first
- Typo in variable name (using 'counter' when you declared 'Counter')
- Using a variable outside its scope
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
- C is case-sensitive, so 'count' and 'Count' are different variables
- Variables declared inside a block are only accessible within that block
- Consider using a linter to catch undeclared variables