Missing Semicolon
syntax
error: expected ';' before '}' token
Description
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.
Common Causes
- Forgetting to add a semicolon at the end of a statement
- Accidentally deleting a semicolon while editing code
- Confusing C syntax with other languages that don't require semicolons
- Copy-pasting code from languages with different syntax rules
Example of Error
Error Code
#include <stdio.h>
int main() {
int x = 5 // Missing semicolon here
printf("Value: %d\n", x);
return 0;
}Solution
Add the missing semicolon at the end of the statement. In C, all statements (except for control structures like if, for, while, and function/block definitions) must end with a semicolon.
Corrected Code
#include <stdio.h>
int main() {
int x = 5; // Semicolon added here
printf("Value: %d\n", x);
return 0;
}Additional Tips
- Always check for missing semicolons when you get syntax errors
- Some IDEs can automatically add semicolons or highlight missing ones
- Use proper code indentation to make it easier to spot missing semicolons
- Configure your editor to show invisible characters to help identify missing punctuation
- Consider using a linter or static analyzer to catch these errors automatically