简体   繁体   中英

what kind of data structure is given to pointer?

Why only pointer variable can hold the address of any other variable? If we store address of any variable in simple variable then its store that address as value. What kind of data structure is design for pointer variable?

I believe you are missing the point that pointer is also a type , a separate one, just like the standard integer types, floating types etc.

Quoting C11 , chapter §6.2.5

  • A pointer type may be derived from a function type or an object type, called the referenced type. A pointer type describes an object whose value provides a reference to an entity of the referenced type. A pointer type derived from the referenced type T is sometimes called ''pointer to T''. [...]

This type is designed to hold the address of another type (including a pointer type itself). Just like an int is designed to hold the integer values and double or float for floating point values. There is no separate data structure needed or mandated for pointer types, it's just defined to be able to hold an address as the value of the pointer variable.

FWIW, there are other types defined in header stdint.h which are capable of holding an address as a value:

The following type designates a signed integer type with the property that any valid pointer to void can be converted to this type, then converted back to pointer to void, and the result will compare equal to the original pointer:

 intptr_t 

The following type designates an unsigned integer type with the property that any valid pointer to void can be converted to this type, then converted back to pointer to void, and the result will compare equal to the original pointer:

 uintptr_t 

These types are optional.

For probable usage, see What is the use of intptr_t?

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