If I declare the following variables:
int array[10] = { 34, 43,12, 67, 34, 43,26, 98, 423,1 };
int * p = array;
Then, this loop:
for ( int i = 0; i < 10; i++ )
{
std::cout << &*p++ << " ";
}
gives me different output ( a different set of addresses ), to this code:
for ( int i = 0; i < 10; i++ )
{
std::cout << p++ << " ";
}
Why? Aren't they semantically equivalent?
EDIT:
Well, my apologies to everyone that answered this one, I don't have the original code, it was a test that I did at home and it turns out that I deleted that code from my project. ( my broadband is not yet connected, so I waited till I got to work to post this ). Anyway - I am pretty sure that I was forgetting to initialise p
. But the question of "aren't they semantically equivalent?" has been answered. Thanks.