40 C Arrays

In the last chapter, you worked with C strings. A C string turned out to be a list of characters packed one next to the other in memory. C arrays are lists of other data types packed one next to the other in memory. Just as with strings, you deal with the list by holding onto the address of the first one.

Imagine that you wanted to write a program that would calculate the average of 3 grades. Create a new C Command Line Tool project and name it gradeInTheShade.

Edit main.c:

#​i​n​c​l​u​d​e​ ​<​s​t​d​i​o​.​h​>​
#​i​n​c​l​u​d​e​ ​<​s​t​d​l​i​b​.​h​>​ ​/​/​ ​m​a​l​l​o​c​(​)​,​ ​f​r​e​e​(​)​

f​l​o​a​t​ ​a​v​e​r​a​g​e​F​l​o​a​t​s​(​f​l​o​a​t​ ​*​d​a​t​a​,​ ​i​n​t​ ​d​a​t​a​C​o​u​n​t​)​ {​ ​ ​ ​ ​f​l​o​a​t​ ​s​u​m​ ​=​ ​0​.​0​;​ ...

Get Objective-C Programming: The Big Nerd Ranch 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.