CS174: Module 8: Pointers Continued: Exercise 0 (1 Points)

C++ frontend developed by, Professor Tralie, adopted from code by Todd Fleming. Canvas Autograder Developed by Professor Tralie and Professor Mongan.


Exercise Goals

The goals of this exercise are:
  1. Work with pointers in C++
  2. Pass values by reference to methods in C++
This exercise relies on things that we have already gone over. If you need to, please review the last module. Your job is to fill in a method that swaps the values of two elements in memory, which is a very useful operation in sorting.

Student Code

#include <stdio.h> void swap(int* x, int* y) { // TODO: Fill this in }

Main Area

int main() { printf("\n"); int x = 5; int y = 6; swap(&x, &y); printf("%i %i.", x, y); x = 10; y = 4; swap(&x, &y); printf("%i %i\n", x, y); }

Compiler Feedback

Program Output

Click compile to compile your code. If it succeeds with no syntax errors, then click run to run your code. If it passes the tests, it will automatically submit to Canvas and send you an e-mail. You must be connected to the VPN for submission to be successful! You will receive a copy of your code via e-mail, so you'll know that it was submitted if you receive that e-mail!
Please Enter your Ursinus netid before clicking run. This is not your ID number or your email. For example, my netid is ctralie (non Ursinus students can simply enter their name to get this to run, but they won't get an e-mail record or any form of credit)

Netid