+ 1
[C++ Constant] Can constants be declared while the program is running?
I see that constant variables have to be initialized at the time of their creation and they also cannot be changed while the program is running. (Almost similar to a Python's tuple). However, can it be declared when the program is running? I.E.: "int my_func { const int x = 42; return x; } int main { cout << my_func() << endl; }
2 ответов
+ 14
You may. The constant will be local to my_func, and will be re-declared and initialised every time the function is called. This is similar to declaring a constant in main, wherein the constant will be local to main.
+ 3
Thank you Hatsy, or I should say "Haste-ey" for the swift response xD