I am trying to follow this basic program involving pointer into the memory. At first We define counter to be 0 (outside main) then we make p_int to point at the same address as a counter. But when i go into the loop for some reason it compares the register with 21 instead of 2. after that when i have tried to change the adress and value of the pointer to a tottaly different vaue and address, it exits in an error,although it compiled well. Whele did i go wrong? Thanks.
int counter=0;
int main()
{
int *p_int;
p_int=&counter;
while (*p_int <2)
{
(*p_int)++;
}
p_int=(int*)0x20000002U;
*p_int=0xDEADBEEF;
return 0;
}
User contributions licensed under CC BY-SA 3.0