(UINT16 *)&apple

B

boki

Dear All,


I knew "&apple" could get the address of apple variable, about why we use a
(UINT16 *) command before "&apple" ?

What is this function for?


Thank you very much for your help.

Best regards,

Boki.
 
G

Gernot Frisch

I knew "&apple" could get the address of apple variable, about why
we use a
(UINT16 *) command before "&apple" ?

What is this function for?

It's a 'cast 'operator'. If Apple e.g. is of the type 'INT16', but
your function requires a UINT16*, you must cast it to that type. Be
sure you know what you do, since this:

double a=5;

*((int*)&a) = 5;
printf("%d", a);

will result in a funny number. The memory used for 'a' will be cast so
the compiler thinks it really _is_ an int that you are pointing to.
Assinging the first 4 bytes of a double with 0x00000005 will result in
anything else than '5.0'.
-Gernot
 

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

Forum statistics

Threads
474,176
Messages
2,570,950
Members
47,501
Latest member
log5Sshell/alfa5

Latest Threads

Top