these are the some silly question ..i want to ask..please help me to comprehend it
const int i=100; //1
///some code
long add=(long)&i; //2
Doubt:for the above code..will compiler first go through the whole code
for deciding whether memory should be allocated or not..or first it ll store the
variable in read only memory place and then..allocate stroage as well at 2
doubt:why taking address of variable enforce compiler to store variable on memory..even
though rom or register too have address
In your code example,
addcontains the address, not the value, ofi. I believe you may have thought thatiwas not stored in normal memory unless/until you take its address. This is not the case.constdoes not mean the value is stored in ROM. It is stored in normal memory (often the stack) just like any other variable.constmeans the compiler will go to some lengths to prevent you from modifying the value.constis not, and was never intended, to be some sort of security mechanism. If you obtain the address of the memory and want to modify it, you can do so. Of course this is almost always a bad idea, but if you really need to do it, it is possible.