CS12, Lab 5
Topics:
·
pointers and dereferencing
·
using pointer arithmetic to access array elements
·
passing pointers as parameters to functions
To do:
·
Copy
the files array.cpp and param.cpp
·
save them into
two new files, p_array.cpp and p_param.cpp.
·
rewrite the code in each using pointers
·
in p_array.cpp:
·
instead of the array declaration, declare a pointer to int and allocate
space for an array of ints accessed by your pointer.
·
convert the rest of the code using pointer notation. Square brackets may not
appear anywhere in your code except when allocating space for the array.
·
compile and run array.cpp and p_array.cpp and verify that the output is the same.
·
in p_param.cpp:
·
declare two pointers to double and assign them to the variables pi and e.
·
pass the pointers (instead of the variables) into the function power()
·
convert the code of the function using pointers. Do not change the cout
statement at the end of the main program.
·
compile and run param.cpp and p_param.cpp and verify that the output is the same.
Extra Credit:
·
Do all the works in the Linux environment. Use the
makefile
for compiling.