List of all available Websheets
Viewing cpp/pointers/swap by daveagp@gmail.com. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
Property | Value |
---|---|
Description html markup shown to student | Define a function <tt>exchange</tt> that takes two <tt>int</tt> pointers as inputs. It should exchange the values held at the locations pointed to by its arguments. |
Public permissions | |
Engine | |
Template / Reference solution |
using namespace std; void exchange(int* a, \[int* b]\) { \[ int tmp = *a; *a = *b; *b = tmp; ]\ } int main() { int x = 4, y = 5; cout << "Before exchange, x is " << x << " and y is " << y << endl; exchange(&x, &y); cout << "After exchange, x is " << x << " and y is " << y << endl; return 0; } |
C++ test suite json list of stdin/args tests e.g. [{"stdin":"hi", "args":["4", "5"]}, {"stdin":"noargs"}] to just run once with no input use [{}] | [ {} ] |
Solution visibility |
Note: problems are open-source by default (see 'Public permissions'). Assumed license for open problems is Creative Commons 4.0 Attribution-ShareAlike unless specified in 'Remarks'.