can realloc move pointer if new size smaller?

后端 未结 6 548
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-09 20:43

I am wondering whether the C or C++ standard guarantees that a pointer is not changed when realloc is called with a smaller (nonzero) size:

size_t n=1000;
T*         


        
6条回答
  •  Happy的楠姐
    2020-12-09 21:09

    http://opengroup.org/onlinepubs/007908775/xsh/realloc.html

    Upon successful completion with a size not equal to 0, realloc() returns a pointer to the (possibly moved) allocated space.

    Nope, no guarantee

提交回复
热议问题