pointers - what is Fixed address variable in C -
i have seen many examples of in books , embedded system related sites.. per understanding , accessing data stored in fixed memory address . here example got in book;
unsigned char *p=(unsigned char *)0x41e;
what use of type cast (unsigned char *)
, there have used directly
unsigned char *p=0x41e;
please explain in detail, what's use of type cast there, , storing address 0x41e
pointer p
or else stored in that?
i totally confused. please help.
what use of type cast.. (unsigned char *) , there have used directly
unsigned char *p=0x41e
0x41e
hexadecimal number , doesn't mean of type unsigned char *
. should have tell compiler, casting unsigned char *
, address (of type unsigned char *
).
are storing address "0x41e" pointer p, or else stored in that.
yes, storing address 0x41e
pointer p
. doing unsigned char *p = (unsigned char *)0x41e
, informing compiler p
pointing memory location 0x41e
, dereferencing p
content stored @ memory location 0x41e
.
check out running code:
#include <stdio.h> int main() { unsigned char *p=(unsigned char *)0x41e; printf("%p\n",p); }
output:
0000041e //output not 0x41e because '0x' used prefix inform compiler hexadecimal number
Comments
Post a Comment