expected initializer before 'void'
时间: 2023-09-08 07:08:17 浏览: 63
This error message usually occurs when the compiler encounters the keyword "void" in a location where it expects an initializer. Here are some possible causes of this error:
1. Missing semicolon: If you have a function declaration or definition that is missing a semicolon at the end, you might get this error. For example:
```
void myFunction() {
// ...
} // <- Don't forget the semicolon here!
```
2. Invalid syntax: If you have a syntax error in your code, such as a missing parenthesis or a misspelled keyword, the compiler might get confused and report this error. For example:
```
void myFunction() {
int x = 10;
if (x == 5) {
printf("x is equal to 5\n"); // <- Missing closing parenthesis
}
}
```
3. Incorrect placement of function definition: If you are defining a function inside another function, you need to make sure that the inner function is defined before it is used. For example:
```
void outerFunction() {
void innerFunction() { // <- Incorrect placement of function definition
printf("Hello from innerFunction!\n");
}
innerFunction();
}
```
To fix this error, you need to identify the exact location where the error occurs and make the necessary corrections to your code.