O'Reilly logo

Objective-C Programming: The Big Nerd Ranch Guide by Mikey Ward, Aaron Hillegass

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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​;​ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required