Howmany byte is pointer?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2008
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?

 
0
  #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
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 960
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: 92
MosaicFuneral's Avatar
MosaicFuneral MosaicFuneral is offline Offline
Posting Shark

Re: Howmany byte is pointer?

 
0
  #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 Quick reply to this message  
Join Date: Aug 2008
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?

 
0
  #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 Quick reply to this message  
Join Date: Aug 2008
Posts: 83
Reputation: nmaillet is an unknown quantity at this point 
Solved Threads: 18
nmaillet nmaillet is offline Offline
Junior Poster in Training

Re: Howmany byte is pointer?

 
0
  #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 10:38 pm.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
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: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: Howmany byte is pointer?

 
0
  #5
Dec 1st, 2008
It's so simple: exactly sizeof(void*) . Let the interviewer counts
Last edited by ArkM; Dec 1st, 2008 at 9:56 am.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,687
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: 727
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Howmany byte is pointer?

 
0
  #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 Quick reply to this message  
Join Date: Aug 2008
Posts: 83
Reputation: nmaillet is an unknown quantity at this point 
Solved Threads: 18
nmaillet nmaillet is offline Offline
Junior Poster in Training

Re: Howmany byte is pointer?

 
0
  #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 Quick reply to this message  
Join Date: Apr 2005
Posts: 16,201
Reputation: jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all 
Solved Threads: 538
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: Howmany byte is pointer?

 
0
  #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 1:09 pm.
If i am helpful, please give me reputation points.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
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: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: Howmany byte is pointer?

 
0
  #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 1:53 pm.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,687
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: 727
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Howmany byte is pointer?

 
0
  #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 Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC