confusion with pointers and memory cell's

V

Virtual_X

- 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
 
V

Victor Bazarov

Virtual_X said:
- 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
 
J

James Kanze

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.)
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top