Chapter 3
The C Programming Language
What You Will Learn In This Chapter:
- Holding data in variables and explaining variable scope and how it works in C
- Iterating through blocks of code using for, while and do … while loops
- Controlling execution of your programs by using the if and switch statements
- Breaking your code into logical units by using functions
- Explaining what pointers are and how you use them to reference data
Before you can begin writing full-featured games for iOS with graphics, animation, and sound, you need to know the basics. The most fundamental level of programming for iOS starts with the C programming language. In this chapter, you will learn the fundamental concepts of C while building a simple, command-line game. When you have finished, you will be ready to move on to the more advanced concepts of Objective-C. After you are comfortable with both languages, you will be ready for graphics, animation, and sound.
Introducing C
The C language is rooted in the PDP-7 assembler language that the creators of Unix used to write the first version of the operating system. Later, programmers developed a language called TMG to wrap PDP-7 assembler. TMG evolved into a higher-level language, B, which could accomplish tasks that required many lines of PDP-7 assembler in only a few lines. At Bell Labs, Dennis Ritchie enhanced the B language, which morphed into C. The developers of Unix then used C to write most of the components of the operating system.
C is a good language ...