It depends. Your program has several constants:
int a = 5;
This is a “static” initialization (which occurs when the program text and data are loaded before starting). The value is stored in memory reserved a , which is located in the "program section of the read-write data section". If something changes a , the value 5 is lost.
int b=5;
This is a local variable with a limited scope (only main() ). Storage may be a processor register or a location on the stack. Instructions created for most architectures will contain a value of 5 in the instruction as “immediate data” for the x86 example:
mov eax, 5
The ability for instructions to hold arbitrary constants is limited. Small constants are supported by most CPU instructions. Large constants are usually not supported directly. In this case, the compiler will save the constant in memory and load it. For instance,
.psect rodata k1 dd 3141592653 .psect code mov eax k1
The ARM family has a powerful design for loading most constants: any 8-bit constant value can be rotated any number of times. See this page 2-25.
The statement contains not one obvious, but a completely different element:
printf("%d", b+c);
The string %d in modern semantics of C, is a constant array of three char . Most modern implementations will store it in permanent memory, so attempts to change it will cause SEGFAULT, which is a CPU error at a low level, which usually causes the program to interrupt instantly.
.psect rodata s1 db '%', 'd', 0 .psect code mov eax s1 push eax
source share