Why?
In your second bit of code:
1. you define a char* variable sting which points at value 1
2. you define a new char* valiable ptr, initializing it to point at the same place as sting. i.e. value 1
3. you set the old variable sting to point at a new value (value 2)
4. you output the new char* valiable ptr which is still pointing at the old value (value 1), as that's what you set it to in step 2.
So you get the old value (value 1)
Andy
PS In your first bit of code you set ptr to point at your buffer sting and then copy the new value into the buffer.
Last edited on