I’m learning about references and pointers, and something in the tutorial isn’t compiling for me (I’m using GCC).
Okay, here is the code:
#include <iostream>
using namespace std;
int main()
{
int ted = 5;
int andy = 6;
ted = &andy;
cout << "ted: " << ted << endl;
cout << "andy: " << andy << endl;
}
The compiler output says “error: invalid conversion from ‘int*’ to ‘int'”
I also tried a string = v; v = &andy; but that didn’t work either.
How can I assign the memory address to a variable?
A pointer holds a memory address. In this case, you need to use a pointer to an int:
int*.For example: