3. Handling Data
This chapter is all about working with data in Objective-C. You’ll use arrays, pointers, strings, and more.
An array is a set of data items, called elements, that you can refer to with an array index. For example, if you store numbers in an array named array
, you can address each element with an index number like this: array[0]
, which refers to the first element; array[1]
, which refers to the second element; and so on. The following code creates an array of five elements, stores a value of 51 in array[0]
, and then displays that value:
#include <stdio.h>int main(){ int array[5]; array[0] = 51; printf("array[0] is %i.\n", array[0]); return 0;}
Pointers are special variables that hold the address in memory of data items. You ...
Get Objective-C: Visual QuickStart Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.