简体   繁体   中英

Confused about macros using pointers in C

I want to understand this bit of code

#define GET(p) (*(unsigned int*) (p)) 

I learned about pointers but I can't figure out what the statement above means. When I use GET(ptr), am I getting the value at the address ptr points to or the address that ptr contains?

It means the following.

  1. Cast the pointer p to the type unsigned int* .
  2. De-reference the pointer to get the value at that address.

Another way of putting it is that the macro gets the value of the unsigned int at the address specified by p .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM