CS
3050, Spring 2006
Programming Assignment 4
Due April 24, 2006
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 (There is nothing to turn in, but it will be assumed
that you understand the contents of the lab.)
- 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