DevPrep

All topics › Objective-C

Pointer and reference

Middle PRO

Essence

In Objective-C (as in C) there are no references as a language construct — only values and pointers. A "reference to an object" in casual speech means a pointer NSString *s: the variable holds the address of a heap object, not the object itself. Assigning a pointer copies the address, so both variables point to the same object; under ARC the assignment also does a retain.

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store