YCP Logo Lab 27: Reverse a sequence using pointers

Due: Monday, Nov 17th by 11:59 PM

Getting started

If you have a solution open in Visual Studio, close it (File->Close Solution).

Download CS200_Lab27.zip. Import it into Visual Studio (File->Import...).

Add your code to the source file called Reverse.c.

Your Task

This lab is similar to Lab 17: you will implement a function to reverse the values stored in an array of ints.

However, the implementation of your reversal algorithm must use pointers to access and update elements in the array, rather than using the array subscript operator (square brackets).

You will need to add code to the reverse function. You won't need to modify the main function.

Example run (user input in bold):

Enter 10 int values:
1 2 3 4 5 6 7 8 9 10
Reversed sequence:
10 9 8 7 6 5 4 3 2 1


Use two pointer variables. One starts out pointing to the first element of the array, the other points to the last element of the array. Use a loop to repeatedly swap the values of elements pointed-to by the two pointers, using pointer arithmetic to move the pointers towards each other.

You may wish to write a function to swap the values of two int variables whose addresses are passed as pointers to the function: i.e.:

void swap(int *p1, int *p2) {
        /* swap contents of *p1 and *p2 ... */


When you are done, choose Tools->Submit to submit your completed lab to the server. You will need to enter your Marmoset username and password.

If the Tools->Submit option does not work, create a zip file containing the files in your project, and upload it to the submission server as lab27. The server URL is