int [3][4];int *p;p=a;报错assignment from incompatible pointertype
时间: 2024-06-03 11:07:26 浏览: 11
int [3][4]是一个二维数组,它的元素类型是int [4]。而p是一个指向int类型的指针,因此p和a的类型不兼容,不能直接进行赋值操作。如果要让p指向a数组,可以使用以下代码:
int a[3][4];
int (*p)[4]; // 定义一个指向int [4]类型的指针
p = a; // p指向a数组的首地址
相关问题
c语言报错:warning: assignment from incompatible pointer type
这个警告通常出现在将一个类型的指针赋值给另一种类型的指针时。比如:
```c
int *ip;
char *cp;
ip = cp; // 这里会出现警告
```
这是因为 `ip` 指向一个 `int` 类型的数据,而 `cp` 指向一个 `char` 类型的数据,它们的类型不同。
如果你想让代码能够编译通过,可以使用类型转换来将 `cp` 指向的数据转换为 `int` 类型,例如:
```c
ip = (int *)cp; // 使用类型转换
```
不过,在进行类型转换时需要确保转换是安全的,否则可能会导致运行时错误。
assignment from incompatible pointer type
This error occurs when a function or expression is expecting a pointer of a certain type, but a pointer of a different type is passed to it.
For example, if a function is expecting a pointer to an integer, but a pointer to a character is passed to it, the error "assignment from incompatible pointer type" will occur.
To fix this error, make sure that the pointer being passed to the function or expression is of the correct type. If necessary, use type casting to convert the pointer to the correct type.
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.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)
![](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)