Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
In modern operating systems, the program allocates memory, and the operating system complies by returning a pointer to the requested memory. In C and Objective-C, a pointer is declared by preceding the variable name with an asterisk (*), as shown in the following example:
char *theData;
NSString *theString;
Don't confused the asterisk here with the dereference operator. Only when declaring a variable does the asterisk identify the variable as a pointer.
Here are some more examples of requesting memory:
1. char data1[100];
2. char *data2 = malloc(100);
3. NSString *myString = [[NSString alloc] init];
In example 1, memory is allocated in the form of an array declaration. The program now has an array (data1) that points to 100 bytes of memory. In C, it's easier to just remember that any variable that is declared as an array is referenced as a pointer even though it's not declared as one.