Pointer

When i use the following:
*p = val;
p++;

I do not get the correct value
but when i do
*p = val;
//next iteration
*(p+1) = val1;

i can access all elements correctly
I have no idea what it is you're asking, but
1
2
*p = val;
p++;


Will assign the value "val" to what "p" is pointing to, and then increment "p" by sizeof(val); So if p is a pointer to a 4 byte integer, and was previously pointing to an integer at location "1000", it will afterwards point to an integer at location "1004".

Whereas

1
2
3
*p = val;
//next iteration
*(p+1) = val1;


Will assign "val" to what "p" is pointing to, and then increment the value that p is pointing to by 1.
Last edited on
Topic archived. No new replies allowed.