Re: pointer question in C
Quote:
Originally posted by TheMummy
hi
i have a question on pointer. suppose p is a dynamically allocated memory pointer. now if i do a p++ does it mean i will get p[0], p[1],p[2] etc ?
or in other words, does it mean
p[0]= p
p[1] = = p+sizeof(data_type) // this is basically p++
can you tell what is the relation between p++ and pointer indexes ?
thanks
p++ would be the same address as &p[1]
p[0] != p but *p
p[1] != p+sizeof(data_type) but rather *(p+1).
Also... p+sizeof(data_type) would only be the same address as p++ if data_type is char. sizeof(int) for example, is 4 (On a 32bit machine), and therefore p+sizeof(int) would be the same as &p[4];