confusion with pointers and memory cell's

Discussion in 'C++' started by Virtual_X, Jul 12, 2007.

  1. Virtual_X

    Virtual_X Guest

    - as we know that the pointer points to a memory cell
    - and each memory cell has the minimal size that the computer manage
    (1 byte)
    - that code

    int *p;
    int x;

    p= &x;

    - that mean that p will point to x which have the size of int type
    4bytes
    - so the pointer point to 4 cells in the memory not one cell
    - here the memory address saved in p is the address of the which cell
    one or two or three of four
     
    Virtual_X, Jul 12, 2007
    #1
    1. Advertising

  2. Virtual_X wrote:
    > - as we know that the pointer points to a memory cell
    > - and each memory cell has the minimal size that the computer manage
    > (1 byte)
    > - that code
    >
    > int *p;
    > int x;
    >
    > p= &x;
    >
    > - that mean that p will point to x which have the size of int type
    > 4bytes
    > - so the pointer point to 4 cells in the memory not one cell
    > - here the memory address saved in p is the address of the which cell
    > one or two or three of four


    Which one is "one"? Which one is "four"?

    Anyway, what you're asking is related to "Endianness". Please read
    about it in Wikipedia.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Jul 12, 2007
    #2
    1. Advertising

  3. Virtual_X

    Virtual_X Guest

    On Jul 12, 10:14 am, "Victor Bazarov" <> wrote:
    > Virtual_X wrote:
    > > - as we know that the pointer points to a memory cell
    > > - and each memory cell has the minimal size that the computer manage
    > > (1 byte)
    > > - that code

    >
    > > int *p;
    > > int x;

    >
    > > p= &x;

    >
    > > - that mean that p will point to x which have the size of int type
    > > 4bytes
    > > - so the pointer point to 4 cells in the memory not one cell
    > > - here the memory address saved in p is the address of the which cell
    > > one or two or three of four

    >
    > Which one is "one"? Which one is "four"?
    >
    > Anyway, what you're asking is related to "Endianness". Please read
    > about it in Wikipedia.
    >
    > V
    > --
    > Please remove capital 'A's when replying by e-mail
    > I do not respond to top-posted replies, please don't ask


    thanks' i get it
     
    Virtual_X, Jul 12, 2007
    #3
  4. Virtual_X

    James Kanze Guest

    On Jul 12, 7:14 pm, "Victor Bazarov" <> wrote:
    > Virtual_X wrote:
    > > - as we know that the pointer points to a memory cell
    > > - and each memory cell has the minimal size that the computer manage
    > > (1 byte)
    > > - that code


    > > int *p;
    > > int x;


    > > p= &x;


    > > - that mean that p will point to x which have the size of int type
    > > 4bytes


    Maybe. (There are machines where int's aren't four bytes.
    There are some where they are only one byte, and I'm aware of at
    least one where they are 6 bytes.)

    > > - so the pointer point to 4 cells in the memory not one cell
    > > - here the memory address saved in p is the address of the which cell
    > > one or two or three of four


    > Which one is "one"? Which one is "four"?


    > Anyway, what you're asking is related to "Endianness". Please read
    > about it in Wikipedia.


    Regretfully, that article isn't particularly good. Endianness
    is only an issue on byte addressable architectures (and as I'm
    fond of pointing out, at least three byte orders have been used
    on those). I've worked on word addressed machines, where int*
    would point to a word, and char* required extra bits to select
    which byte in the word.

    The real answer in C++, of course, is that int* doesn't point to
    any individual byte of an int; it points to the entire int.
    What that means depends on the hardware.

    --
    James Kanze (Gabi Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Jul 12, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. news.rcn.com
    Replies:
    1
    Views:
    9,800
    Chris Smith
    Jul 12, 2004
  2. Roger Leigh
    Replies:
    8
    Views:
    473
    Karl Heinz Buchegger
    Nov 17, 2003
  3. =?ISO-8859-1?Q?Martin_J=F8rgensen?=

    problem with memcpy and pointers/arrays confusion - again

    =?ISO-8859-1?Q?Martin_J=F8rgensen?=, Mar 9, 2006, in forum: C Programming
    Replies:
    39
    Views:
    1,292
    Ben Pfaff
    Mar 21, 2006
  4. cham
    Replies:
    5
    Views:
    791
  5. cerr

    pointers, pointers, pointers...

    cerr, Apr 7, 2011, in forum: C Programming
    Replies:
    12
    Views:
    729
Loading...

Share This Page