Real meaning of addresses

T

tfelb

Hi group!

I read yesterday in a c book something about how does C reference
memory addresses but it's a little bit tricky.

so for example if I have

int num;

and the address of num is 100 then the compiler would treat that
variable internally as (int *)100 so
an address &num IS the same as (int *)100.


So the compiler treat the statement int num = 3; as *(int *)100 = 3
right?


But why I need a pointer type and not for example (int)100 or
unsigned
int(100)?


Thank you!

Tom F.
 
T

tfelb

It's more like that
if the address of num is (int*)100
then the computer might
treat it like 100 internally for some certain arithmetic contexts.


Because the meaning of the data in an object
depends on the type with which the object is accessed.

If you have a negative value stored in a signed char object,
and you access that object as an unsigned char,
then the value will be positive.

If an integer value is accessed as an integer,
then its value is not an address.

You're always answer my questions. A big thank you pete and for sure
the other experts here. Thanks!

Tom F.
 
T

tfelb

You're always answer my questions. A big thank you pete and for sure
the other experts here. Thanks!

Tom F.- Zitierten Text ausblenden -

- Zitierten Text anzeigen -

oh I mean YOU not you're sorry I lexical mistake ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,438
Messages
2,571,699
Members
48,796
Latest member
Greg L.
Top