Hi, I am attempting to come to terms with pointers and have come up against a problem. By my understanding the code below should:
a, assign the value 3200 to total.
b, attach the memory address of total to ptr.
c, send the value at ptr to val.
d, display val (which will be the same as total)
but heres problem, if I then change the value of total as shown in the code the original value of 3200 comes back from val even if the value of total is different?
using namespace std;
total = 3200;// assign 3200 to total
ptr = &total; // get address o total
val = *ptr; // get value at that address
cout << "Total is:" << val << '\n';
cout << "Enter total";
cin >> total;
cout << "Total is: <<val << '\n';
Any help would be greatly appreciated.