. Advertisement .
..3..
. Advertisement .
..4..
I get this error ” invalid conversion from int* to int” when running my code.
Here is my code:
#include <iostream>
using namespace std;
int main() {
int p = 20;
int* ptr;
ptr = p; //Invalid conversion.
}
What should I do?
The cause: This error happens because you try to assign an integer value (i.e., p ) to an integer pointer. You must remember that pointers are used to store the address of a particular variable.
Solution: You can solve this error by assigning the address of the variable p by using the
&
symbol.