What is the difference between const and static keywords in c++? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 5

What is the difference between const and static keywords in c++?

C++

10th Mar 2019, 5:34 AM
Shweta Chindhe
Shweta Chindhe - avatar
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
10th Mar 2019, 5:54 AM
Sinjini Das
Sinjini Das - avatar
+ 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..!
10th Mar 2019, 8:04 AM
Kuri
Kuri - avatar