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

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -