Character Arrays
Program 13.2 illustrates how you can use a character array. However, one point is worthy of discussion. Can you spot it?
Program 13.2.
#import <Foundation/Foundation.h>int main (int argc, char * argv[]){ @autoreleasepool { char word[] = { 'H', 'e', 'l', 'l', 'o', '!' } ; int i; for ( i = 0; i < 6; ++i ) NSLog (@"%c", word[i]); } return 0;}
Program 13.2. Output
Hello!
In this case, the size of the array is determined automatically based on the number of initialization elements. Because Program 13.2 has six initial values listed for the array word, the Objective-C language implicitly dimensions the array to six elements.
This approach works fine as long as you initialize every element in the array ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access