Looking for relevant Development Whitepapers? Visit the SearchWinDevelopment.com Research Library.
YuvalShavit | Jul 8 2008 2:20PM GMT
Take this with a grain of salt, but I believe they are not stored in either the stack or the heap. Because they’re constant, consts are evaluated at compile-time and plugged straight into the machine code. So as an example, if you have a const AVG_CHILDREN=2.5, then familySize = 2+ AVG_CHILDREN; is exactly the same as familySize = 4 + 2.5; (which would itself be optimized to just familySize = 6.5;).
The advantage of using the const as opposed to just typing in 2.5 is that if the average number of children per family changes, you have to alter just one line of code — the const declaration — instead of finding every instance of that 2.5 and changing it.