Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

converting a pointer to a non pointer type

Tags:

c

pointers

What exactly happens when you convert a pointer to a non-pointer type?
For example:

int i = 7;
int *y = &i;

printf("%x %d %x", y, (int)y,7);

The result when compiled and run is:

29ff00 2752256 7

But what actually resulted - where did the number come from? Is it a random number or something related to what the pointer held?

Does it have a mathematical value such as the address or is the value of the pointer converted by some standard?

like image 422
thingybingytie Avatar asked Mar 24 '26 03:03

thingybingytie


1 Answers

2752256 is the decimal value of the memory address 29ff00. You'd get a similar result with

printf("%x %d", y, y);
like image 169
twentylemon Avatar answered Mar 26 '26 15:03

twentylemon



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!