RSS Forums RSS

Howmany byte is pointer?

Please support our C++ advertiser: Programming Forums
Reply
Posts: 1
Reputation: quocnam00 is an unknown quantity at this point 
Solved Threads: 0
quocnam00 quocnam00 is offline Offline
Newbie Poster

Howmany byte is pointer?

  #1  
Nov 30th, 2008
Hello every one, I got a interview and 1 of interviewer ask me that Howmany byte is a pointer? I can not answer this question. seem it is trick question. All I know is pointer is an address location where the pointer point to.
Anyone get input to make it clear would be appreciate.
thanks
AddThis Social Bookmark Button
Reply With Quote  
Posts: 717
Reputation: MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice 
Solved Threads: 80
MosaicFuneral's Avatar
MosaicFuneral MosaicFuneral is offline Offline
Master Poster

Re: Howmany byte is pointer?

  #2  
Nov 30th, 2008
Ask him/her what platform.
"Jedenfalls bin ich überzeugt, daß der Alte nicht würfelt."
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
Reply With Quote  
Posts: 77
Reputation: mahlerfive is an unknown quantity at this point 
Solved Threads: 16
mahlerfive mahlerfive is offline Offline
Junior Poster in Training

Re: Howmany byte is pointer?

  #3  
Nov 30th, 2008
It depends on the platform. Since a pointer is an address, it must be big enough to store the largest address. I'm fairly sure that in windows addresses are 32bits (4 bytes). In linux/unix it may be different.
Reply With Quote  
Posts: 55
Reputation: nmaillet is an unknown quantity at this point 
Solved Threads: 11
nmaillet nmaillet is offline Offline
Junior Poster in Training

Re: Howmany byte is pointer?

  #4  
Nov 30th, 2008
It's 4 bytes on a 32-bit system (reason for a 4GB RAM limit), and 8 bytes on a 64-bit system. I believe you can check using something like sizeof(void*).
Last edited by nmaillet : Nov 30th, 2008 at 9:38 pm.
Reply With Quote  
Posts: 2,000
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 331
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: Howmany byte is pointer?

  #5  
Dec 1st, 2008
It's so simple: exactly sizeof(void*) . Let the interviewer counts
Last edited by ArkM : Dec 1st, 2008 at 8:56 am.
Reply With Quote  
Posts: 7,460
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 676
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Howmany byte is pointer?

  #6  
Dec 1st, 2008
>seem it is trick question.
It is a trick question. Not only can the size of a pointer vary depending on the system, the size of pointers to different types aren't required to be the same. The best answer to this question would be sizeof p , where p is defined as the pointer one wants to test.

>It's so simple: exactly sizeof(void*) .
How do you propose this to be meaningful for pointers to functions?
I'm here to prove you wrong.
Reply With Quote  
Posts: 55
Reputation: nmaillet is an unknown quantity at this point 
Solved Threads: 11
nmaillet nmaillet is offline Offline
Junior Poster in Training

Re: Howmany byte is pointer?

  #7  
Dec 1st, 2008
Originally Posted by Narue View Post
>It's so simple: exactly sizeof(void*) .
How do you propose this to be meaningful for pointers to functions?

The size of a pointer has to be consistent for a particular system. It is the reason for labeling a system as 32-bit, 64-bit, etc. The reason for having different types of pointers is for the allocation of memory at that particular location, and to help prevent buffer overflows when passing a pointer.
Reply With Quote  
Posts: 15,222
Reputation: jbennet is a glorious beacon of light jbennet is a glorious beacon of light jbennet is a glorious beacon of light jbennet is a glorious beacon of light jbennet is a glorious beacon of light jbennet is a glorious beacon of light 
Solved Threads: 455
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: Howmany byte is pointer?

  #8  
Dec 1st, 2008
http://bytes.com/groups/c/216087-size-sizeof-pointer

The size of a pointer has to be consistent for a particular system. It is the reason for labeling a system as 32-bit, 64-bit, etc. The reason for having different types of pointers is for the allocation of memory at that particular location, and to help prevent buffer overflows when passing a pointer.

not nececerially. there is no default pointer size, just the actual size it is. If there were, it would imply that you could
somehow specify any size you wished. No mention of a default size is mentioned in the C spec.

There is no guarantee that all pointer types will have the same sizeeither (except in the case of pointers to structures and unions).

e.g an int* may be larger than a char*. This is particuarly true with regards to function pointers and data pointers, which are, for example, different sizes from each other in DOS depending on which memory model is used. For example, the AS/400 PS by IBM specifies additional informationb with regards to function pointers whioch can make it significantly bigger than an ordinary data pointer.

However, On most modern OS platforms and Compilers, all pointer types are of equal size and are reprsesneted in the same way on a low level.

In most cases, word length / register size of the processor (CPU) determines the size of a pointer which is generally 2 or 4 or 8 bytes for 16,32 and 64 bit CPUs respectively, but as i said, you should never assume this to always be the case. Thats why the size of a pointer determines the maximum memory that can be
addressed at once e.g the 4gb limit on 32 bit systems.
Last edited by jbennet : Dec 1st, 2008 at 12:09 pm.
Master of puppets Im pulling your strings - blinded by me, you cant see a thing. Master! Master!

If i am helpful, please give me reputation points.
Reply With Quote  
Posts: 2,000
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 331
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: Howmany byte is pointer?

  #9  
Dec 1st, 2008
Originally Posted by Narue View Post
>seem it is trick question.
It is a trick question. Not only can the size of a pointer vary depending on the system, the size of pointers to different types aren't required to be the same. The best answer to this question would be sizeof p , where p is defined as the pointer one wants to test.

>It's so simple: exactly sizeof(void*) .
How do you propose this to be meaningful for pointers to functions?

1. The void* type size is the supremum of all pointer type sizes because it's possible to assign arbitrary pointer type value (including function pointers) to the void* type variable and get back the original value. It's impossible to do if sizeof(void*) < sizeof(wide_pointer_type) for wide_pointer_type (set theory).

Of course, a schizophrenical software architect is capable to invent the C or C++ implementation with unused data fields in all pointers except void* ones. Well, let's remember default argument promotion rules and %p format specification. It's too hard job for lunatic to implement all these features with such exotic pointers...

Make a compromise: sizeof(pointer_type) <= sizeof(void*)
2. Don't tread on me with member pointers , otherwise it was an ill-formed question...

3. The only type sizes in C and C++ are introduced via operator sizeof. Strictly speaking any answer without sizeof is incorrect (or the question is ill-formed )...
Last edited by ArkM : Dec 1st, 2008 at 12:53 pm.
Reply With Quote  
Posts: 7,460
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 676
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Howmany byte is pointer?

  #10  
Dec 1st, 2008
>The size of a pointer has to be consistent for a particular system.
Correct, but keep in mind that T* is a completely different type from U*, assuming T and U don't map to the same type. You seem to be pretending that all pointers have the same type (a universal pointer type), which is false.

>It is the reason for labeling a system as 32-bit, 64-bit, etc.
An xx-bit system is where xx is the number of bits that can be processed in parallel. Usually this means the data bus of the CPU, not the size of pointers in the addressing system.

>because it's possible to assign arbitrary pointer type value (including
>function pointers) to the void* type variable and get back the original value
That's incorrect. A pointer to void is defined to work only with object types, not function types. It's not safe to assign the address of a function to a pointer to void.

>Don't tread on me with member pointers
I'm not quite that pedantic.
I'm here to prove you wrong.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Other Threads in the C++ Forum
Views: 601 | Replies: 9 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 3:22 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC