Resources‎ > ‎Programming‎ > ‎C++‎ > ‎

Low level details

Here are some questions and answers used to better understand how C/C++ behaves under the hood. While most behaviour is dictated by the compiler and the options used, there are some general answers that apply.

Memory management of function call stacks in C

Q: After a function is called, what happens to the returned variable?

A: The EAX register for x86 architecture is used to store the return parameter. The calling convention __cdecl, __stcall, __fastcall will dictate how arguments are ordered for function stack and either the callee or caller will clean the stack. In both cases, the return value is copied onto a reserved register (EAX for x86). This is not a problem for nested functions, or recursion because there is never more than one return parameter at any one time. After calling a function, EAX is copied directly to any local variable that takes the value. No stack related memory operations apply.

More information can be found here