Pointers Datatype

What is the datatype of pointer?

Questions by michudeepu

Showing Answers 1 - 6 of 6 Answers

Pointer datatypes are actually the datatype of the variables whose address the pointer is going to store or point to.

i.e. to point an integer value, the pointer should of the same datatype i.e. int type.

  Was this answer useful?  Yes

There is no single "pointer" data type; you have many pointer data types. A pointer to int may have a different size and representation from a pointer to char, which may have a different size and representation from a pointer to an array of char, which may have a different size and representation from a pointer to a struct, etc.

What a pointer "looks like" under the hood will vary from implementation to implementation and may vary from pointer type to pointer type. With a "flat" memory model, it may be just a regular integer value. For a segmented model, it may be a page-offset pair. On a word-addressed system, a pointer to char may be larger than a pointer to int (because you need an additional offset into the word to access specific chars), etc.

Here's what the C language definition has to say:

--------------------------------------------------
6.2.5 Types
...
27 A pointer to void shall have the same representation and alignment requirements as a
pointer to a character type.39) Similarly, pointers to qualified or unqualified versions of
compatible types shall have the same representation and alignment requirements. All
pointers to structure types shall have the same representation and alignment requirements
as each other. All pointers to union types shall have the same representation and
alignment requirements as each other. Pointers to other types need not have the same
representation or alignment requirements.
-----------------------------------------------------

You can convert pointer values to integer values; however, whether those values are meaningful is up to the specific implementation.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions