Community
Participate
Working Groups
Build Identifier: 20100617-1415 When practicing dynamic allocation, I wrote some code as follows: int *p, *q; int arr[] = {1,2,3,4,5}; p=arr; q=p+5; *q=6; After the last sentence was exercised, the reference of "p" also changed to "0x06". It seems that when I gave "*q" an assignment, the reference of "p" was assigned with 6 too, while it should not change. Reproducible: Always Steps to Reproduce: 1. reference assignment of a pointer-to-integer "p" with an array "arr" 2. assign "p+5" to another pointer-to-integer "q" 3. assign an integer, say 6, to "*q" Through debug, you can see that value of "p" changes to "0x06" as well
The bug is in your code, not in CDT. p+5 refers outside of the array. Apparently that particular compiler allocates p itself at that memory location, i.e. at the point of initialization.