PR3-Rust-SS26/D-ownership/example-code/01-motivation/memory_leak.cpp

20 lines
411 B
C++

#include <iostream>
int main() {
// Allocating memory on the heap
int* myPointer = new int(42);
std::cout << "myPointer at address "
<< myPointer << " is equal to " << *myPointer << std::endl;
// Allocating memory on the heap
myPointer = new int(10);
std::cout << "myPointer at address "
<< myPointer << " is equal to " << *myPointer << std::endl;
delete myPointer;
return 0;
}