Using original pointer after realloc?

后端 未结 2 1671
后悔当初
后悔当初 2021-01-17 14:45

I was reading Richard Reese\'s new (May 2013) O\'Reilly book \"Understanding and Using C Pointers\", and I have a question about some code therein, on page 87.



        
2条回答
  •  悲哀的现实
    2021-01-17 15:34

    once a pointer is dangling, is it safe to use the address contained in the pointer for any purpose, such as calculating offsets?

    No, it is not safe. After free the pointer value is an invalid address and an invalid address cannot be used for pointer arithmetic without invoking undefined behavior.

提交回复
热议问题