pointer size

2 views
Skip to first unread message

richa gupta

unread,
Feb 14, 2009, 1:28:30 PM2/14/09
to programmi...@googlegroups.com
can someone tell me following answer?

size of a pointer in 16 bit platform, 32 bit platform and 64 bit platform.

Some sources says that size of a pointer will always be  2 bytes because it just stores the address while some resources say that it is 2, 4, 8 in 16, 32, 64 bit platform.
Please varify with a solid reason.

--
Richa Gupta
(IT-BHU,India)

David Sveningsson

unread,
Feb 14, 2009, 1:51:07 PM2/14/09
to programmi...@googlegroups.com
richa gupta wrote:
> can someone tell me following answer?
>
> *size of a pointer in 16 bit platform, 32 bit platform and 64 bit platform.*

sizeof(void*) will tell you this.

> Some sources says that size of a pointer will always be 2 bytes because
> it just stores the address while some resources say that it is 2, 4, 8
> in 16, 32, 64 bit platform.

2, 4, 8. The size must be large enough to address the entire address space.

> Please varify with a solid reason.
>
> --
> Richa Gupta
> (IT-BHU,India)
>

> --~--~---------~--~----~------------~-------~--~----~
> Visit http://www.gowrikumar.com for good puzzles in C programming
> language and programming interview questions.
>
> You received this message because you are subscribed to the Google
> Groups "Programming Puzzles" group. To post to this group, send email to
> programmi...@googlegroups.com
> -~----------~----~----~----~------~----~------~--~---
>


--


//*David Sveningsson [eXt]*

Freelance coder | Game Development Student
http://sidvind.com

Thou shalt make thy program's purpose and structure clear to thy fellow
man by using the One True Brace Style, even if thou likest it not, for
thy creativity is better used in solving problems than in creating
beautiful new impediments to understanding.

signature.asc

richa gupta

unread,
Feb 14, 2009, 3:31:06 PM2/14/09
to programmi...@googlegroups.com

2009/2/14 David Sveningsson <e...@sidvind.com>

>*size of a pointer in 16 bit platform, 32 bit platform and 64 bit platform.*

>sizeof(void*) will tell you this.

Can you give me reason in support of your answer?
how can a void * tell this size?
What will the size of void* in a 64 bit platform?

(Actuly this ques was asked in an interview. The interviewer gave me three options 2, 4 and 8 for for all the three ( 16, 32, 64 bit platform). )

As far as i know pointer size is always equal to the word size of the machine. So it must be 2,4, 8 for 16, 32, 64 bit platform.

2009/2/14 David Sveningsson <e...@sidvind.com>
richa gupta wrote:
> can someone tell me following answer?
>
> *size of a pointer in 16 bit platform, 32 bit platform and 64 bit platform.*

sizeof(void*) will tell you this.

> Some sources says that size of a pointer will always be  2 bytes because
> it just stores the address while some resources say that it is 2, 4, 8
> in 16, 32, 64 bit platform.

2, 4, 8. The size must be large enough to address the entire address space.

> Please varify with a solid reason.
>
> --
> Richa Gupta
> (IT-BHU,India)
>
> >


--


//*David Sveningsson [eXt]*

Freelance coder | Game Development Student
http://sidvind.com

Thou shalt make thy program's purpose and structure clear to thy fellow
man by using the One True Brace Style, even if thou likest it not, for
thy creativity is better used in solving problems than in creating
beautiful new impediments to understanding.




--
Richa Gupta
(IT-BHU,India)

David Sveningsson

unread,
Feb 14, 2009, 4:26:15 PM2/14/09
to programmi...@googlegroups.com
richa gupta wrote:
>>*size of a pointer in 16 bit platform, 32 bit platform and 64 bit
> platform.*
>>sizeof(void*) will tell you this.
>
> Can you give me reason in support of your answer?
> how can a void * tell this size?

On the same setup all pointers are of equal size. It doesn't matter if
it is a void-pointer, int-pointer, float-pointer, pointer to a large
struct, pointer to a character array, function-pointer or a
int-pointer-pointer-pointer. They are *all of equal size*.

> What will the size of void* in a 64 bit platform?

8 bytes. Try it yourself with printf("%d\n", sizeof(void*));

> (Actuly this ques was asked in an interview. The interviewer gave me
> three options 2, 4 and 8 for for all the three ( 16, 32, 64 bit platform). )

16-bit has 2 byte pointers
32-bit has 4 byte pointers
64-bit has 8 byte pointers

> As far as i know pointer size is always equal to the word size of the
> machine. So it must be 2,4, 8 for 16, 32, 64 bit platform.

The wordsize is *not* equal to the pointer size. On x86 the a word is 16
bits and a dword is 32 bits.

There are multiple books and article written about these concepts if you
are intrested. I suggest reading "What Every Programmer Should Know
About Memory" [1] by Ulrich Drepper.

There is also a good blog [2] by Gustavo Duarte who has written some
great explanations of computer memory.

[1] http://people.redhat.com/drepper/cpumemory.pdf
[2] http://duartes.org/gustavo/blog/

> 2009/2/14 David Sveningsson <e...@sidvind.com <mailto:e...@sidvind.com>>

> --~--~---------~--~----~------------~-------~--~----~
> Visit http://www.gowrikumar.com for good puzzles in C programming
> language and programming interview questions.
>
> You received this message because you are subscribed to the Google
> Groups "Programming Puzzles" group. To post to this group, send email to
> programmi...@googlegroups.com
> -~----------~----~----~----~------~----~------~--~---
>

signature.asc

Deepak Mittal

unread,
Feb 15, 2009, 11:25:22 PM2/15/09
to programmi...@googlegroups.com
Hi,
 
Size of the pointer is the size of the address bus.
As Pointer should be able to access the hignest address in the memory.
 
So for 16 bit Platform it is 2 Bytes.and for 32 bit platform it is 4 bytes and so on.
 
Regards
Deepak Mittal

Reply all
Reply to author
Forward
0 new messages