+ 5
What is the difference between const and static keywords in c++?
C++
2 ответов
+ 5
A const is a promise that you will not try to modify the value once set.
A static variable means that the object's lifetime is the entire execution of the program and it's value is initialized only once before the program startup. All statics are initialized if you do not explicitly set a value to them.The manner and timing of static initialization is unspecified.
https://code.sololearn.com/c6ahrgeCALEY/?ref=app
+ 1
Hi.. If use CONST, corresponding value will be allocated in ROM - Read only memory.
If use keyword STATIC, Value will be stored in RAM - Random access memory.
ROM value stays for whole life till SW is changed. while RAM Content remains till system is powered off... Hope this helps..!