Pointers in C/C++

This is a discussion on Pointers in C/C++ within the C++ Programming forums, part of the General Programming Boards category; Dear Sir, I have a question on pointers which is disturbing me for last three/four days .The question is : ...

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    10

    Unhappy Pointers in C/C++

    Dear Sir,


    I have a question on pointers which is disturbing me for last three/four days .The question is :


    Q:- Memory gives pointers 2bytes to store the address of any variable of any data type , but when we print that variable on screen it shows a address of 4bytes , How?


    I will very thankful to u to give me the answer.

  2. #2
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    What makes you think that two bytes are used to store pointers?
    Last edited by Rashakil Fol; 10-19-2005 at 03:00 AM.

  3. #3
    Registered User
    Join Date
    Jul 2005
    Posts
    10
    Quote Originally Posted by Rashakil Fol
    What makes you think that two bytes are used to store pointers?

    Plz read my question carefully,my question is in c++
    Q:-pointers uses two bytes to store an address of any variable ,but print the address of 4bytes like 0x879fffff which is 4 bytes how?

  4. #4
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    Your question is in English, and I have read it very carefully. You are saying that pointers use two bytes to store an address. Right? They don't. They use four bytes. At least that's the case on many computers.

  5. #5
    Bond sunnypalsingh's Avatar
    Join Date
    Oct 2005
    Posts
    162
    Quote Originally Posted by Rashakil Fol
    Your question is in English, and I have read it very carefully. You are saying that pointers use two bytes to store an address. Right? They don't. They use four bytes. At least that's the case on many computers.
    well...it's compiler dependent....most probably it is equal to unsigned int or unsigned long int(not sure which of them)

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,765
    How about posting some code which leads you to your "conclusion" and state your Operating system and compiler.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Aug 2005
    Posts
    113
    In console programming a pointer takes 2 bytes(size equivalent to unsigned int) to store.As int is 4 bytes in window programming so pointers may be having 4 bytes(i'm not sure since i haven't done window programming.)Now that should put end to Salem's confusion.

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Now that should put end to Salem's confusion.
    There's more confusion on your part I think, since Salem certainly knows what he's talking about. The size of a pointer is not set in stone, nor does it have to be equivalent to the size of an unsigned int. It could be 2 bytes on older systems, it could be 4 bytes, and it could be different for each pointer type on the same system. Saying that it's one or the other without telling us what compiler and operating system you're using is pointless.
    My best code is written with the delete key.

  9. #9
    Bond sunnypalsingh's Avatar
    Join Date
    Oct 2005
    Posts
    162
    Well...what i earlier said is most probably wrong...because now couldn't find anything which says pointers should be atleast equal to unsigned int or unsigned long int.......

    Well u were asking about the compiler...
    i tested it on turbo C...it came out to be 2 bytes...and when i tested it on VC6.0 and DEV C++ compiler...it came out to be 4 bytes......i guess that's because pointers in turbo C are near by default...that is why it is showing that......

    plz comment

  10. #10
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,765
    > Now that should put end to Salem's confusion.
    Absolutely, now I know you are clueless.
    Everything you know about how big a pointer is is wrong.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  11. #11
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,765
    Of course, if you ever get to work on a machine where sizeof(void*) is 1, then you'll really realise how little you know
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Variable pointers and function pointers
    By Luciferek in forum C++ Programming
    Replies: 11
    Last Post: 08-02-2008, 03:04 AM
  2. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 06:59 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 01:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21