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
Post a Comment