Hello i am new to C language and trying to understand pointers.
Doing some examples i stumbled with this function and im not completely sure what it is about.
void dump(void *p, int n)
{
unsigned char *p1 = p;
while (n--)
{
printf("%p - %02x\n", p1, *p1);
p1++;
}
}
I dont understand the p
in unsigned char *p1 = p;
there is no other use for it in the function. I also dont quite understand the p1
in printf("%p - %02x\n", p1, *p1);
, is it the actual value of the *p1 pointer?
Can anyone explain this topics to me? I'll be very grateful.
In the example it shows me that when a i run with this main()
int main(void)
{
int i = 10000;
dump(&i, sizeof(i));
return 0;
}
the output is
0x7ffd7e787e74 - 10
0x7ffd7e787e75 - 27
0x7ffd7e787e76 - 00
0x7ffd7e787e77 - 00