Why don’t I declare NSInteger with a *

NSInteger is a primitive type, which means it can be stored locally on the stack. You don’t need to use a pointer to access it, but you can if you want to. The line:

NSInteger *processID = [[NSProcessInfo processInfo] processIdentifier];

returns an actual variable, not its address. To fix this, you need to remove the *:

NSInteger processID = [[NSProcessInfo processInfo] processIdentifier];

You can have a pointer to an NSInteger if you really want one:

NSInteger *pointerToProcessID = &processID;

The ampersand is the address of operator. It sets the pointer to the NSInteger equal to the address of the variable in memory, rather than to the integer in the variable.

Leave a Comment

tech