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?
-
1Only pointers are specifically designed to hold the address of another variable. Often, there is an integer type (and its unsigned counterpart) that can hold an object address — those types are `intptr_t` and `uintptr_t`. Your second sentence isn't very clear. Not all simple variables can hold address values. Very often, the result truncates part of the address. (Also, function pointers need not be the same size as object pointers.) . There's no particular data structure that is the 'design for a pointer variable'. – Jonathan Leffler Jan 11 '19 at 05:50
-
possible duplicate of [What is the data type of pointer variables?] (https://stackoverflow.com/questions/26976496/what-is-the-data-type-of-pointer-variables) – P.W Jan 11 '19 at 05:51
-
A pointer can point to an arbitrary, but defined, C type (very often some `struct`) – Basile Starynkevitch Jan 11 '19 at 06:05
-
In second sentence, I am trying to say that, when we assign address of a variable in other variable(not a pointer variable) i.e. int var1=10, var2; var2=&var1;. it will hold the address but as value and if address is large (out of range) than it will truncate the other part. – amit Jan 11 '19 at 07:17
1 Answers
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?

- 133,132
- 16
- 183
- 261
-
Thank you saurav for this explanation, but will you please tell me memory allocation of pointer variable (as memory view of pointer variable). – amit Jan 11 '19 at 07:21
-
@amit What do you mean by memory allocation? How the memory is allocated? That depends on the compiler - for compile time allocation. If the question is how much memory is allocated - that once again depend on your environment, usually (however, not universal), the size of a pointer is 4 in a 32 bit environment and 8 in a 64 bit environment – Sourav Ghosh Jan 14 '19 at 06:07