Multiple choice technology

Which is correct way of string declaration in objective C

  1. String str =”cocoa”;

  2. NSString *str =@”cocoa”;

  3. NSString str= “cocoa”;

  4. NSString* str=@”cocoa”;

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

In Objective-C, strings are declared using NSString class with the @ symbol before the string literal to indicate it's an Objective-C string object (not a C string). The correct syntax is NSString *str = @"cocoa"; where the asterisk denotes a pointer to the object, and the @ symbol creates an NSString object from the literal.