November 2013
Beginner
325 pages
9h 47m
English
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:
#include <stdio.h>
#include <stdlib.h> // malloc(), free()
float averageFloats(float *data, int dataCount)
{
float sum = 0.0;
for (int i = 0; i < dataCount; i++) {
sum = sum + data[i];
}
return sum / dataCount;
} int main (int argc, const char * ...Read now
Unlock full access