Memory management scope in C/C++ -


when freeing memory in c , c++, need memory address or require specific variable?

so if such as:

int* test() {     int* x = new int(5);     return x; }  int main(int argc, char** argv) {     int* y = test();      delete y;      return 0; } 

would cause memory leaks? thanks!

no, there wouldn't leaks there, again, neither there in

int test() {     return 5; }  int main(int argc, char** argv) {     int y = test();     return 0; } 

avoid dynamic allocation if can.


Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -