I know that when a pointer is incremented, it will point to the next element of its type. e.g:
Code:
int a[5]={1,2,3,4,5},*p;
p=a;
cout<<*(p+4)<<endl; //will output 5
This is because the addresses of elements of the array are all adjacent.
My question is applying the same principle, why doesn't the following work:
Code:
int a,b,c,d,e,f,g,h,i,*p;
p=&a;
for(i=0;i<8;i++) *(p+i)=i*i;
/*The loop should put into int a to h the squares of i as i increments*/
Because the variables are all created at the same line, with nothing in between, does it mean their addresses are also adjacent?