Question: Part 2 : Pointers ( 3 0 marks ) Create a program and set up the variables as shown in the diagram. Complete the following

Part 2: Pointers (30 marks)
Create a program and set up the variables as shown in the diagram. Complete the following steps for the program:
Part 2A:
1. Create a function 'setter' with parameters P and a new value k (integer). The function should follow the pointer and change the integer at the end of the chain to the new value. [8 marks]
2. Call 'setter' in main with \(\mathrm{k}=2\). When it returns, demonstrate that the new value of i was changed (hint: print \( i \)).[2 marks]
3. Create a swap function with parameters A2 and B2. The function should swap them such that A2 now points at B and B2 now points to A. Call this function with A2/B2 in main. [8 marks]
4. Call 'setter' with \(\mathrm{k}=8\).
5. Now print all variables (dereferenced to i or j ) in the following format: [2 marks]
Part 2 B: Finally, draw the new diagram for the new variable setup. [10 marks]
Part 2 : Pointers ( 3 0 marks ) Create a program

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!