Laboratory 4: Pointers, array allocation and argument passing
-
Topics to be explained by your TA.
-
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
-
Download the following file.
-
Create an empty project (Lab4) and include the downloaded file Lab4.cpp
in it.
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()
-
Loook 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