CS
3050, Spring 2007
Programming Assignment 4
Due May 2, 2007
Lab 4: Pointers, array allocation and
argument passing
This lab will give you some an opportunity to review pointers, arrays,
and argument passing. It is based
on an assignment created by Lucia Moura at the
University of Ottawa.
- Topics you should review:
- Pointers
- Declaration
- The *(value of) and &(address of)
operators
- Example
- Array allocation
- Direct static allocation
- Static allocation with constant
- Dynamic
allocation with pointer and variable
- Arguments passing (the &(reference)
operator)
- passing by value
- passing by reference
YOUR TASK
Upload to
the submission system the two files described below (no hard copies need to be turned in):
- Create an ascii text file: write your guesses about the output
before running each section and your analysis of any guesses that
turned out not to be correct.
- A script that shows you ran the program.
- Download the following file.
Pointers
- Check out the procedure pointers()
- Look how the pointers are defined and used
- Try to guess the output
- Compile and run the program to see the output
Array allocation
- Delete the comment symbol (//) in the call arrays() in
the main()
procedure
- Check out the procedure arrays()
- Look how the arrays are defined
- Compile and run the program and see the dynamic allocation of array3
Argument passing
- Delete the comment symbol (//) in the call arguments() in
the main()
procedure
- Check out the procedure arguments()
- Look how the arguments are passed in functions swapV(int x,
int y)
and swapR(int& x, int& y)
- Try to guess the output
- Compile and run the program to see the output