assignment makes pointer from integer without a cast
时间: 2024-05-15 22:16:27 浏览: 13
This error message is usually seen in C or C++ programming languages and it occurs when a program tries to assign an integer value to a pointer variable without explicitly casting it to a pointer type.
For example, consider the following code snippet:
```
int num = 10;
int *ptr;
ptr = num; // assigning an integer value to a pointer without casting
```
In this code, the variable `ptr` is a pointer to an integer, but the variable `num` is an integer. The assignment statement `ptr = num` tries to assign the value of `num` to `ptr`, which is not allowed because `num` is an integer and `ptr` is a pointer. To fix this error, we need to cast the integer value to a pointer type before assigning it to `ptr`.
```
int num = 10;
int *ptr;
ptr = (int*)num; // explicitly casting the integer value to a pointer type
```
In this corrected code, we have cast the integer value to a pointer type using the `(int*)` syntax, which tells the compiler that we want to treat the integer value as a pointer. This prevents the "makes pointer from integer without a cast" error from occurring.