Datasheet
12
Part I: Getting to the Starting Line
This is what you do to get that output.
1. You write instructions for the computer to follow.
Unfortunately, the computer can’t speak English, or read for that matter,
so you use something called a compiler to take the instructions you have
written in the Objective-C language and translate it into something the
computer can understand.
2. You provide data for the computer to use.
In this case, you write, “I hate peanut butter and jelly,” and then the
computer follows the instructions you have given it on what to do with
that data.
Voilà, you see “I hate peanut butter and jelly” displayed on your com-
puter screen.
Fundamentally, programs manipulate numbers and text, and all things consid-
ered, a computer program has only two parts: variables (and other structures),
which “hold” data, and instructions, which perform operations on that data.
Examining a simple computer program
Is there really any difference between a chef reading a recipe and creating a
peanut butter and jelly sandwich and a computer following some instructions
to display something on a monitor? Quite frankly, no.
Here is the simple Objective-C program that displays I hate peanut
butter and jelly on the computer screen:
int main(int argc, char *argv[]) {
char* theSandwich = “I hate peanut butter and jelly”;
printf (theSandwich);
return 0;
}
This program shows you how to display a line of text on your computer
screen. The best way to understand programming code is to take it apart line
by line:
int main(int argc, char *argv[]) {
05_522752-ch01.indd 1205_522752-ch01.indd 12 8/27/09 9:45:02 PM8/27/09 9:45:02 PM