# Thread: Array problem

1. ## Array problem

Which element(s) of the array “e” remain undefined at the end of the sequence?

int e[6];
int *p1;
int *p2 = e;

*p2 = 4;
*(p2+1) = 8;
p1 = p2 + 3;
*p1++ = 2;
*(p1+1) = 3;

Please give detailed explanation. Thanks!

2. Please give detailed explanation.
You make it sound like you're copying a homework assignment ._.

For the question, write it out on paper. I'll give you an example on how to start:

Let's say the array "e" is at a random memory location, say 0x0 to make things easier. P1 is uninitialized and p2 is pointing to the same location, 0x0. Now, let's go through the steps:
• Code:
`*p2 = 4;`
You're dereferencing p2 at where it points to, so the contents of memory location 0x0 is 4. You could also say that e[0] is 4.
• Code:
`*(p2+1) = 8;`
P2 points to 0x0, so by adding one before dereferencing, you're accessing the contents of 0x1. You could also use array notation by saying p2[1], or e[1] as they both point to the same place.

And continue this for the rest of the steps.

3. Thanks for your reply. It is not an assignment. I dont understand even I have the rough answer, which is e[2] and e[4]... /_\
Would you please explain the meaning of "p1 = p2 +3"? What is p1? Thank you.

4. ._.

Here, read this link. It explains everything you need to know about pointers and arrays, and a lot of the stuff looks pretty similar to what you have.

5. I see. I have a clearer picture now. Thank you :-)

Popular pages Recent additions