why does pointer memory command not working

0

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;
}

enter image description here

enter image description here

enter image description here

enter image description here

c
pointers
assembly
arm
main
asked on Stack Overflow May 13, 2020 by rocko445

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0