Week 3 Objectives


At the end of this week's classes you should

KNOW:

BE ABLE TO:

Sample Quiz Questions:

  1. Write a C function that will determine the sum of the numbers stored in an int array. The function is given the name of the array and the number of elements in the array. Here is the function heading:
    int sumElements (int theArray[], int size)
    

  2. Write the complete function definition (function heading and function body) for a C function called calculate with the following pre- and post-conditions:
    PRE:  num is a non-negative float
    POST: the function returns the square root of num, and the value of num squared
    

  3. In C, there is no way to pass an array by value. Give an example of a function in which this restriction is a liability (in other words, give an example of a function for which it would be preferable to be able to pass the array by value).

  4. (Read section 7.5 before trying this question.) Modify your function from the previous problem using the const qualifier so that the array gets the protection afforded by call-by-value.