- #1
- 4,652
- 37
I have run into a little bit of confusion working with pointers and I am trying to figure out which of the expressions below from my assignment are valid. My definition of a pointer is that it is a variable that contains a memory address, so I get confused about whether I am modifying a location or the value stored at the location. Could someone please look at my responses to the assignment below and straighten me out? Thanks!
Given that pi and pj are pointers to int, and ii and ij are ints, which of the following expressions are valid?
a) pi + ii I think this is valid. But I am not sure if the address that pi points to is getting the int added to it or the value at the address.
b) pi + pj I think this might be invalid. I don't think you can add a pointer to a pointer.
c) pi++ I think this is valid. pi points to a machine address, if pi isincremented by one, pi will point to one unit past that machine address.
Given that pi and pj are pointers to int, and ii and ij are ints, which of the following expressions are valid?
a) pi + ii I think this is valid. But I am not sure if the address that pi points to is getting the int added to it or the value at the address.
b) pi + pj I think this might be invalid. I don't think you can add a pointer to a pointer.
c) pi++ I think this is valid. pi points to a machine address, if pi isincremented by one, pi will point to one unit past that machine address.