Last active
August 29, 2015 14:11
-
-
Save NigoroJr/91249b58d023fa241190 to your computer and use it in GitHub Desktop.
Sample of function that returns an allocated pointer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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