c++ - Is there any difference between static memory allocation and automatic memory allocation? -


i reading static memory allocation , dynamic memory allocation. static memory int = 2; space a allocated on stack. if do, int * = new int; *a = 3, here memory allocated on heap. then, can former called automatic memory allocation? thanks!

forget stack , heap. these terms not defined in c++ standard (except things stack unwinding , std::stack). talking storage duration, can be:

  • static
  • thread
  • automatic
  • dynamic

dynamic storage duration applied objects created using new. such objects live until delete them.

automatic block-scope variables not declared static or extern, local variables in function. these automatically (aptly) destroyed when block ends.

thread variables declared thread_local. these exist until thread in created finishes.

static else, variables declared @ file scope or static keyword. such variables exist duration of program.


Comments