Just experimenting with pointers & arrays. When I increment ptr with ++ptr, I can predict which number in my array list will be dereferenced to and it works. This seems cumbersome though.How do I successfully access matrix elements without going one at a time like ++ptr, etc. I've tried pnt++2 etc., no dice.
Chervil this IS exactly what I had in mind. Its minimal but has so much information for learning points. The two boxes sum it up (as Peter's does as well). I wanted to verify what I was seeing:
My testing code results at the bottom
My test results were that ptr + 3 does not increment the pointer but still has access to the address at ptr+3. I tried several embodiments. I can increment the pointer addresses by incrementing the pointer: ++ptr, ++ptr, etc. How would I increment the pointer in this fashion but lets say by 2 or 3 at a time steps?
How would I increment the pointer in this fashion but lets say by 2 or 3 at a time steps?
The syntax for incrementing a pointer is just the same as for incrementing an integer (though how the compiler processes it 'behind the scenes' is different).
For example you could do ptr = ptr + 3;
or more concisely ptr += 3;
edit: I see you already did this at line 15 above.