0
What is the difference between static and constant
6 Réponses
+ 4
static variables are shared variables between objects of same class. it has common memory.
constant variables are variables with fixed value which cannot be changed. but in case of static variables value can be changed but it cannot be reinitiallialized ( means address cannot be changed)
+ 3
normal variables are not constant Thier value can be changed & they can also be reinitiallialized
+ 1
An static property can be changed freely during the program execution. A constant has its value defined at the beginning of the execution and can never change its value.
+ 1
Then how it is different from variable?
+ 1
What is the difference b/w Static and variable ?
+ 1
static variables are stored in data segment, thus they are global throughout the program. whereas const variables are stored in the stack (if locally declared) otherwise in the data segment