So, what is a program?

Now that you have built and run your first program, let’s take a quick look inside to see how it works.

A program is a collection of functions. A function is a list of operations for the processor to execute. Every function has a name, and the function that you just wrote is named main.

When programmers talk about functions, we usually include a pair of empty parentheses. Thus, the main function is referred to as main().

There was another function in your program – printf(). You did not write this function, but you did use it.

To a programmer, writing a function is a lot like writing a recipe card. Like a function, a recipe card has a name and a set of instructions. The difference is that you execute a recipe, and the computer executes a function.

Figure 2.7  A recipe card named Easy Broiled Chicken

A recipe card named Easy Broiled Chicken

These cooking instructions are in English. In the first part of this book, your functions will be written in the C programming language. However, a computer processor expects its instructions in machine code. How do you get there?

When you write a program in C (which is relatively pleasant for you), the compiler converts your program’s functions into machine code (which is pleasant and efficient for the processor). The compiler is itself a program that is run by Xcode when you press the Run button. Compiling a program is the same as building a program, and we will use these terms interchangeably.

When you run a program, the compiled functions are copied from the hard drive into memory, and the function named main is executed by the processor. The main function usually calls other functions. For example, your main function called the printf function. You will learn more about how functions work in Chapter 5.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset