Please have a look at the following code
#include <iostream>
using namespace std;
int main()
{
int a = 5;
int *aPtr1 = &a;
int *aPtr2 = aPtr1;
int *aPtr3 = aPtr2;
cout << "'a' value: " << a << endl;
cout << "'aPtr1' value: " << *aPtr1 << endl;
cout << "'aPtr2' value: " << *aPtr2 << endl;
cout << "'aPtr2' value from 'aPtr3': " << **aPtr3 << endl;
}
In here, at the last line, I am trying to get the ‘aPtr2’ value from ‘aPtr3’. In other words, this is my attempt to find the ‘Pointer Before’. But it gives me the error
PointerTest.cpp:16: error: invalid type argument of `unary *'
How can I make this OK? Please help!
aPtr3is equal toaPtr2. AndaPtr2is the adress ofa. When writing*aPtr3, you already access the value pointed by the adress it contains (ie, the adress ofa).If you wanted to use this syntax, you should have had