When you incrementdecrement a pointer are you changing the a

When you increment/decrement a pointer, are you changing the address or the element at the address? If it is the address, how does the program know how much to increment or decrement? Hint: Remember the use of “sizeof” function in earlier chapters.

Solution

When you increment/decrement a pointer you are changing the address not the element at the address. If the address is pointer to a variable of size x bytes, then when you increment by 1 the program actually jumps the pointer by 4 bytes. So the amount the pointer moves depends on the size of the variable it is pointing to. The size of the variable is given by the sizeof function.

When you increment/decrement a pointer, are you changing the address or the element at the address? If it is the address, how does the program know how much to

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site