How many bytes are used in integer pointers??

Recommended Answers

All 5 Replies

The same amount of bytes as there are in all other types of pointers (except possibly function pointers, which might take up a different amount on some platforms). How many that are depends on the platform.

You can find out how many bytes are in an int pointer on your platform by doing sizeof(int*) (or sizeof(void*) - as I said it's going to be the same for all non-function pointers).

Usually it would be 4 bytes on a 32-bit platform and 8 bytes on a 64-bit platform (or more generally n/8 bytes on an n-bit platform).

Just to add to the information by sepp2k:
A pointer is basically supposed to hold address of what it is asked. Doesnt matter if it points to a single character, a float, a huge array or a complex structure. What pointer will hold is always going to be an address of the beginning of the memory block. And when we say address, it is nothing but an integer value identifying a memory cell. Hence, always a pointer size will be equal to the size of an integer. Hope that makes sense.

Actually while what sepp2k says is generally true for many many platforms it is not absolutely true it rather depends on the platform's hardware and how it does addressing.

For example I worked with a microprocessor that used 16bit word addressing, that is each 16 bit address gave the location of a 16 bit word. To address a byte in assembly or machine code you needed to indicate if you wanted the high byte or low byte of the word. Because of this in C integer pointers (int) were 16 bits (integers were also 16 bits long), 2 bytes, but char and void* which had to be able to address every 8 bit byte where 17 bits and thus normally 4 bytes long.

I would say that it is possible that in such a situation it may have been better for the platform to define it bytes as being 16 bits long and stuck to straight 16 bit addressing, although I have not thought through all the ramifications of that particularly outlandish suggestion so I could easily be wrong.

There is absolutely no standard requirement for pointers to different types to be the same size.

Pointer holds the address of the value it points.
It dosen't matter weather the value is character , float or integer.
Since pointer holds the address of the value and addresss is always integer so size of pointer is size of integer.

Since pointer holds the address of the value and addresss is always integer so size of pointer is size of integer.

That's utterly and completely wrong. sizeof(int) != sizeof(void*) on all 64-bit platforms that I know.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.