Pointer to Value of another pointer in C (Embedded)

95 Views Asked by At

In this code: Pointer_pu32 points to variable a, but which is pointer Boot_st point to?

 int * Boot_st;
 int a = 15;
 int * Pointer_pu32 = &a;
 Boot_st = (int *)(*Pointer_pu32); /* what was this code line mean? */

When I try to run

printf("Address of A : %ld\n", &a);
printf("Boot_st : %ld\n", Boot_st);
printf("Address Boot_st : %ld\n", &Boot_st);
printf("Pointer_pu32 : %ld\n", Pointer_pu32);

Here is the result:

Address of A: 3996460
Boot_st : 15
Address Boot_st : 3996472
Pointer_pu32 : 3996460

That means: Boot_st contains the value of a, could you explain the behavior of the pointer Boot_st and Pointer_pu32?

1

There are 1 best solutions below

2
On

This code line Boot_st = (int *)(*Pointer_pu32); means

  • take this pointer to an integer Pointer_pu32
  • dereference it (*Pointer_pu32) to read the integer value
  • cast it, to consider that value as a pointer to an integer (int *)
  • write that to a variable of type "pointer to an integer" Boot_st =