Design Element
Comment on "Intro to C Pointers and Dynamic Memory"
by Scott Stevenson — Jun 12
@Dharm: Now, I wanted to shift the array by one element i.e. typically in C we do (*p)++ as described in this tutorial, but this gives errors in Xcode and it fails to compile.

You can't manually increment the pointer, which is by design. Cocoa supports both NSArray objects and the regular C-style arrays (but Cocoa methods rarely create C-style arrays). NSArrays are much safer to use, partially because they don't let you do things like that.

If you want to create a C-style buffer from an NSArray, you can use NSArray's -getObjects: method. That said, I'd strongly encourage you to reconsider your design before doing that because it's generally bad practice for Cocoa and is not required in most cases. NSArray is incredibly fast, so you really shouldn't need to work about performance in most cases.
Back to "Intro to C Pointers and Dynamic Memory"
Design Element

Copyright © Scott Stevenson 2004-2015