Why does this program compiles ? Should it not give an error as I am deleting the same thing twice [duplicate]

  c++, heap-memory, oop

This code runs perfectly fine and does not give any error which I think it should as I am deleting the same thing twice.

#include<iostream>
int main(){
    int* var1 = new int;
        int* var2 = var1;
        *var1 = 10;
        *var2 = 15;
        std::cout << var1 << std::endl;
        std::cout<<var2<<std::endl;
return 0;}

Source: Windows Questions C++

LEAVE A COMMENT