Skip to content

Instantly share code, notes, and snippets.

@NigoroJr
Last active August 29, 2015 14:11
Show Gist options
  • Save NigoroJr/91249b58d023fa241190 to your computer and use it in GitHub Desktop.
Save NigoroJr/91249b58d023fa241190 to your computer and use it in GitHub Desktop.
Sample of function that returns an allocated pointer
#include <iostream>
int* bar() {
int* ret = new int;
return ret;
}
int main() {
for (int i = 0; i < 10; i++) {
int ptr = *bar();
ptr = 12;
std::cout << &ptr << std::endl;
// Pointer gets deleted each iteration
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment