Hi all.
I am trying to get my head around pointers.
I created a little program::
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
#include <iostream>
using namespace std;
int main ()
{
char a[20] = "this is a test";
char * pa;
pa = &a[0];
for (int i =0; i< 20; i++)
{
cout << "Address: " << pa << ", value: " << *pa << endl;
pa += 1;
}
return 0;
}
|
The ouput from which is:
Address: this is a test, value: t
Address: his is a test, value: h
Address: is is a test, value: i
Address: s is a test, value: s
Address: is a test, value:
Address: is a test, value: i
Address: s a test, value: s
Address: a test, value:
Address: a test, value: a
Address: test, value:
Address: test, value: t
Address: est, value: e
Address: st, value: s
Address: t, value: t
Address: , value:
I can understand the value, but shouldn't the address be a hex address in memory? when i run the same with a int * i do get a hex memory address increasing by 4, since for my compiler sizeof(int) = 4. Please could someone explain?
Many thanks all,
Matthew