You are here


5 February, 2015 - 11:20

Everyone seeks of ways to be more efcient in what they do. A farmer uses a tractor instead of a horse. A construction worker uses an air powered nail gun instead of a hammer. Programmers are no different than others, in that they are constantly improving their ability to produce correctly working programs. Some aspect of this is the use of modular/structured programming, proper documentation and following industry rules for a specific programming language. One example of efcient coding is letting the computer count the number of elements in an array. If we define an array:

int ages[J = {33,32,l0,3}; 

We can use the following expression to calculate the number of members in the array:

sizeof ages 1 sizeof ages[0]

This type of fexible coding allows us to change the members of the array by adding or subtracting a values, like this:

int ages[J = {57,33,32,3,l}; 

Thus, we don't have to modify our code that uses the expression that calculates the number of member in the array.

One use of the typedef is to allow us to write code that can be quickly changed to handle different data types. There are several integer and floating-point data types that all store number values with different domains. If we write our code using some typedef statement, then our code becomes versatile. By changing only our typedef commands, our code can be used to process data of a different data type. This is demonstrated within the demo file provided, thus you need to study this material in conjunction with the demo program.