Deleting a heap then dereferencing a pointer to that memory

前端 未结 4 916
误落风尘
误落风尘 2020-12-04 00:06

This is code from an exercise:

#include 
using namespace std;

int main() {
    int n = 13;
    int* ip = new int(n + 3);
    int* ip2 = ip;
         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 00:32

    This behaviour is undefined, and so what will happen is implementation and system dependent.

提交回复
热议问题