Lab 3 - Function calls and memory

You will write 3 versions of a simple program in C using cygwin/gcc as your development environment. You may work together with a partner (or two) if you want, but make sure that each of you fully understands what is happening in the lab. THIS LAB SHOULD BE SUBMITTED.

Submit the final version of the C code (the .c file) and a simple text write up of the questions below. The typical answer (per question) should be a few sentences. You may include the writeup as comments in your source code.

To submit the lab, send an e-mail with the header "lab3 submission" to me at cdamon@vtc.edu. Be sure to attach your source code.

Some guidelines for using unix command line (like cygwin) can be found here. There is also a cheat sheet for compiling with gcc here.

1. Too many arguments.

Write a simple, initially empty main function.

Write a simple function called simple that takes a single int parameter and prints it. The function simple should not return anything (return type of void). Place this function below main.

Above main, add a declaration for simple that does not indicate any arguments, as in

     void simple();

Add a call to main that calls simple, but with the arguments 1,2,3....12

Your submission should answer the following questions about this program:

2. Too few parameters

Add a second call to printf in simple. Put 12 %d's in the format string, but provide no other arguments.

Your submission should answer the following questions about this program:

3. Too small array

Create a new function called arr. In arr, declare a variable that is a 5 element int array. Add a for loop that sets the first 20 elements of the array to 0.

Call this method from simple.

Your submission should answer the following questions about this program:

You may find it advantageous to try slight variations of the program to gain a better understanding. If you do, you may submit the modified program, but include in your writeup what you changed and what you learned from it.