Memory location of static variables
Question
In a C++ program, where in memory do static variables live?
Short answer
In the static data area, not on the stack or heap. Initialised statics go in the data segment and zero-initialised ones in the BSS segment; they exist for the whole run of the program. Function-local statics share this storage but are initialised the first time control passes through their declaration.
Adapted from Joshi, Denson & Downes, Quant Job Interview Questions and Answers, Q7.19, p.227; question and answer rewritten by SelfMadeQuant.com.
See the hint and the full worked solution in the question bank (free account).
Open the worked solution