OK... I may talking to myself here as I see no response, but I am very active and am coming across some odd problems. I came up with the notion of reducing the address as follows:
Code:
#include <iostream.h>
typedef int* IntPtr;
void sample_function(IntPtr& pointer);
main()
{
IntPtr p1, p2;
sample_function(p1);
cout << "The current value of *p1 is " << *p1 << " and it is at address " << p1 << endl;
p1 = p1 - 1;
cout << "*p1 is now equal to " << *p1 << " and is at memory loc " << p1 <<endl;
return 0;
}
void sample_function(IntPtr& pointer)
{
for (int i = 0; i < 25; i++)
{
pointer = new int;
*pointer += i;
cout << *pointer << " is now stored in address " << pointer <<endl;
}
}
It produced very odd results. The following is the output I obtained from it (for space, I am starting at 10);
Code:
10 is now stored in address 0x8049d98
11 is now stored in address 0x8049da8
12 is now stored in address 0x8049db8
13 is now stored in address 0x8049dc8
14 is now stored in address 0x8049dd8
15 is now stored in address 0x8049de8
16 is now stored in address 0x8049df8
17 is now stored in address 0x8049e08
18 is now stored in address 0x8049e18
19 is now stored in address 0x8049e28
20 is now stored in address 0x8049e38
21 is now stored in address 0x8049e48
22 is now stored in address 0x8049e58
23 is now stored in address 0x8049e68
24 is now stored in address 0x8049e78
The current value of *p1 is 24 and it is at address 0x8049e78
*p1 is now equal to 17 and is at memory loc 0x8049e74
Why is the integer 17 being stored at memory location 0x8049e74 when it has been indicated that 17 is located at memory location 0x8049e08?