Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing a pointers value

Tags:

c

pointers

#include <stdio.h>

int main(void)
{
   int x = 99;
   int *pt1;

   pt1 = &x;

   printf("Value at p1: %d\n", *pt1);
   printf("Address of p1 (with %%p): %p\n", pt1);
   printf("Address of p1 (with %%d): %d\n", pt1);

   return 0;
}

What are the downsides/dangers to printer pointer values with %d instead of %p?

like image 453
abishell Avatar asked Dec 07 '25 04:12

abishell


1 Answers

%d displays an integer - there is no need for the size of a pointer to equal the size of an integer.

like image 151
daven11 Avatar answered Dec 08 '25 18:12

daven11



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!