Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the @ operator in Objective-C same as the & operator in C?

New to objective C. Trying to understand pointers in Objective C.

my code

#import <Foundation/Foundation.h>

 int main (int argc, const char * argv[]) {

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

NSString *msg = @"Hello Bhai";
NSLog(@" address is %i for msg", msg);
NSLog(@" which is same address  %i for Hello Bhai", @"Hello Bhai");
NSLog(@" which is different address  %i for Hello mere Bhai", @"Hello mere Bhai");
NSLog(@" value is %@ at the address for msg", msg);


[pool drain];
    return 0;
}

output is

[Session started at 2011-04-26 16:31:11 -0400.]
2011-04-26 16:31:11.656 BasicObjC[1523:10b]  address is 8240 for msg
2011-04-26 16:31:11.658 BasicObjC[1523:10b]  which is same address  8240 for Hello Bhai
2011-04-26 16:31:11.659 BasicObjC[1523:10b]  which is different address  8288 for Hello mere Bhai
2011-04-26 16:31:11.660 BasicObjC[1523:10b]  value is Hello Bhai at the address for msg

Does this mean @ in Objective C is the same as & in C

like image 565
user726102 Avatar asked Dec 07 '25 10:12

user726102


1 Answers

@ is used to denote that string is a NSString literal so you can assign it to NSString object.

If you want to print some address then you should use %p format specifier, not %i, e.g.

NSLog(@" address is %p for msg", msg);
like image 155
Vladimir Avatar answered Dec 10 '25 01:12

Vladimir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!