I am trying to figured out what happen when loop run on hardware. how it works on hardware. I wrote c program for "for " to store values in variable
at the start 0 store in variable i and pointer hold the address of variable i so the value store in variable is 0 and address of variable i is 0061FF28. When loop start i set to 0 the address of variable is same had previous address then we compare value of i with 4 if it's less the 4 then print its value and address if its false then just stop loop
value of variable: 0
address of variable : 0061FF28
value of variable: 0
address of variable : 0061FF28
value of variable: 1
address of variable : 0061FF28
value of variable: 2
address of variable : 0061FF28
value of variable: 3
address of variable : 0061FF28
value of variable: 4
address of variable : 0061FF28
Program show that the value of variable change but the address of that variable will be same.
I don't understand why the value of variables changes when loop exit. What happen when this program run on hardware.
C:
#include<stdio.h>
int main(void)
{
int i = 0;
int *pointer;
pointer = &i;
printf("value of variable: %d \n", i);
printf("address of variable : %p \n",&pointer);
for(i = 0; i < 4; i++)
{
printf("value of variable: %d \n", i);
printf("address of variable : %p \n",&pointer);
}
printf("value of variable: %d \n", i);
printf("address of variable : %p\n",&pointer);
return 0;
}
value of variable: 0
address of variable : 0061FF28
value of variable: 0
address of variable : 0061FF28
value of variable: 1
address of variable : 0061FF28
value of variable: 2
address of variable : 0061FF28
value of variable: 3
address of variable : 0061FF28
value of variable: 4
address of variable : 0061FF28
Program show that the value of variable change but the address of that variable will be same.
I don't understand why the value of variables changes when loop exit. What happen when this program run on hardware.