User`s manual

Dynamic C Users Manual digi.com 35
The program above calculates the sum of squares of two numbers, g and h, which are initialized to 10 and
12, respectively. The main function calls the init function to give values to the global variables g and h.
Then it uses the sumSquare function to perform the calculation and assign the result of the calculation to
the variable x. It prints the result using the library function printf, which includes a formatting string as
the first argument.
Notice that all functions have { and } enclosing their contents, and all variables are declared before use.
The functions init() and sumSquare() were defined before use, but there are alternatives to
this.This was explained in Section 4.11.
4.13 Aggregate Data Types
Simple data types can be grouped into more complex aggregate forms.
4.13.1 Array
A data type, whether it is simple or complex, can be replicated in an array. The declaration
represents a contiguous group of 10 integers. Array elements are referenced by their subscript.
Array subscripts count up from 0. Thus, item[7] above is the eighth item in the array. Notice the [ and
] enclosing both array dimensions and array subscripts. Arrays can be “nested.” The following doubly
dimensioned array, or “array of arrays.”
is referenced in a similar way.
The first dimension of an array does not have to be specified as long as an initialization list is specified.
int item[10]; // An array of 10 integers.
j = item[n]; // The nth element of the array.
int matrix[7][3];
scale = matrix[i][j];
int x[][2] = { {1, 2}, {3, 4}, {5, 6} };
char string[] = "abcdefg";