Thanks for any attention and appreciate your answer in advance.
You have not initialized anything, so what do you expect??
Those variables you used, contain random trash.
Given the following declaration:
int *a;
With the given declaration, ++a does not increment the address value of 'a'
by 1, but rather by sizeof(int), so that the memory address "++a" points to
the next, following, int in memory.
a+1 returns the same value: not the memory address of 'a' plus 1, but a
memory address of the next int, after 'a'.
Similarly: given two pointers:
int *a, *b;
Presuming that both a and b are pointing to elements of the same array,
the expression (b-a) does not result in the difference between the memory
addresses of b and a, but that difference divided by sizeof(int).
This is so that:
int c=b-a;
This gives the number of ints between a and b, not the number of bytes
between a and b, so that "a+c" returns the same pointer as 'b', or, in other
words:
(b-a) + a == b
Because on your machine, pointers are 4 bytes?
> > Thanks for any attention and appreciate your answer in
> > advance.
> You have not initialized anything, so what do you expect??
> Those variables you used, contain random trash.
He doesn't actually use the variables except for address
calculations, so it doesn't matter that they're not initialized.
--
James Kanze (GABI Software) email:james...@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Thank you for your detailed explanation.
The answer is really what I need.:)