Question

If I write such operator:

int a=32;

Do I properly understand , that integer literal 32 is storing like int number somewhere in code, and then, this constant is assigned to my variable a?

Était-ce utile?

La solution

Not necessarily. int a actually means "keep sizeof(int) bytes on the stack available and let's call a that pace, and fill it with the 32 number.

The =, here is not an assignment (a does not exist before: it is created as such), but an initializer.

And where the number 32 goes, it depends on the underlying processor and relative instructions. It can even go inside the code itself, with instruction like LD (DS+a), 32, where DS is the data-segment pointer, a the offset of the a variable and 32 just the bit representation in binary of the number 32.

Autres conseils

CPU instructions often have a form that holds a literal value; in that case, the store instruction that's generated by a = 32 contains the value to be stored; in other cases, the value is stored somewhere in program data and copied from there into the variable.

Back in the olden days of FORTRAN, you could pass a constant to a function which modified it, and from then on the constant had the new value. This was not a good thing.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top