expected initializer before 'void'
时间: 2023-09-08 12:08:17 浏览: 107
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.
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)