views:

76

answers:

1

I've been going through some open-source code for a Twitter app, and came across this:

(in the OADataFetcher.h) file:

OAMutableURLRequest *request;
NSURLResponse *response;
NSError *error;
NSData *responseData;

(inside the 'fetchDataWithRequest:delegate:didFinishSelector:didFailSelector:' method) in OADataFetcher.m:

responseData = [NSURLConnection sendSynchronousRequest:request
                                         returningResponse:&response
                                                     error:&error];

I was wondering if someone can please explain to me what the '&' symbol does in front of the returningResponse and error variables. How is it different then simply using the variables without the ampersand?

+1  A: 

The & is the "address-of" operator. It returns the address of (pointer to) the variable it precedes.

highlycaffeinated
would i have gotten the same result if i just passed in 'response' and 'error'?
dpigera
@dpigera - No, because then you're passing the value of the variable instead of the memory address. The compiler should at least give a warning if you try it.
kirk.burleson
cool. thanks for the response guys.. appreciate it! :)
dpigera