error: argument of type "int *" is incompatible with parameter of type "int **"
时间: 2023-11-30 16:05:17 浏览: 248
This error occurs when a function is expecting a pointer to a pointer (e.g. int **), but a pointer to a single integer (e.g. int *) is passed as an argument.
For example, consider the following code:
```c
void foo(int **p) {
// do something with p
}
int main() {
int x = 5;
foo(&x); // ERROR: argument of type "int *" is incompatible with parameter of type "int **"
return 0;
}
```
In this example, the function `foo` expects a pointer to a pointer to an integer, but we are passing a pointer to a single integer `x`. To fix this error, we need to pass the address of a pointer to an integer, like this:
```c
void foo(int **p) {
// do something with p
}
int main() {
int x = 5;
int *ptr = &x;
foo(&ptr); // OK
return 0;
}
```
Here, we create a pointer `ptr` that points to `x`, and then pass the address of `ptr` to `foo`. Now, `foo` can access `x` through the pointer `ptr`.
阅读全文
相关推荐




















