The value of this type pointer notation

I have seen this type of ad many times and have no idea what it does:

*(type*)$var

eg:

*(char *)&myChar

If the address myCharis retrieved and a pointer is sent to it char, then why is the extra pointer outside and why is it an address, which is possibly an int value or a hex value as a pointer? It makes no sense to me. I'm a newbie, so please explain step by step what is happening here and why use this confusing format for type casting. Thank.

+4
source share
2 answers
*(char *)&myChar

myChar, char*, , , , , . , .

int x;
char c = *(char*)&x;

x int, char. 1 , char 1 .

, . 4 ( , int 4 ) , . ++ .

+4

*(type *)&var - C- .

,

char buf[4];
*(uint32_t *)&buf = 32;

32 buf.

. . , . . !

+2

Source: https://habr.com/ru/post/1543941/


All Articles