Just a silly question:
I have a simple counter, but it seems that it gives the double value of what I expect.
short int *new = 0;
++new;
NSLog(@"Items: %hi", new);
And this returns:
Items: 2
Relatively new to Cocoa, and still working out the little details as is clear form above…
You don’t have an integer variable, you have a pointer to an integer variable (a short integer, to be specific). It increments by 2 because short integers are two bytes long. A pointer variable holds a memory address of another value. Incrementing a pointer means, “make this pointer point to the next thing in memory”, where “thing” is the type of value the pointer was declared to point at. A pointer to
doublewould increment by 8 each time.The “*” in the declaration makes it a pointer. If you just want an int, you’d just write