PHYCS 3730/6720 Lab Exercise

Reading and references: This exercise provides more practice with pointers and references.

The answer file for this exercise is lab09.


Exercise 1. Data types

Copy the example code in ~p6720/exercises/refs_ptrs/pointers_refs.cc to a working directory. Look at it. Compile it and run it. Then in your answer file, answer these questions:

Exercise 2. Declarations that initialize

Modify the code to do the following and check your modifications. (It should give the same result as before.) Copy your declarations to the answer file.

Exercise 3. Subprogram Linkage

Please refer to the code from lab exercise lab08, found in ~p6720/exercises/refs_functions. The main program call_f.cc calls the subprogram f. The arguments in the calling statement match the arguments in the definition of the subprogram. When the call is made, the subprogram variables are initialized (get their initial values) with values coming from the main program.

In your answer file write the equivalent declarations of the subprogram variables x, y_ptr, dydx including initialization (initial assignments) for the call f(x,&y,dydx);. Here is the answer for the first argument:

    double x /*in subprogram f*/ = x /*from main program*/ ;
(Note that we chose to enclose comments here in /* */). Give the answer for the second and third arguments. You need only three lines for the whole answer.

For more details and an example, please see the section "Subprogram Linkage" in the online notes referenced above. In your answer be careful to distinguish variable names that have scope only in the subprogram from names that have scope only in the calling program.

Suppose later in the main program the function was called using f(sqrt(5*x), &ysq5x, dydxsq5x) . Write the equivalent declarations with initialization for this case.