swap - // passes by reference. void swap2( int & a, int...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
// swap.cpp / // demonstrates passing by value and passing by reference // by Mark Weiss, revised by Kip Irvine / #include <iostream> using namespace std; u // incorrect implementation of swap2 // passes parameters by value. void swap( int a, int b ) { int tmp = a; a = b; b = tmp; } // Correct implementation of swap2
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // passes by reference. void swap2( int & a, int & b ) { int tmp = a; a = b; b = tmp; } void swapExample( ) { int x = 37; int y = 52; i cout << "before: " << x << " " << y << endl; c swap2( x, y ); s cout << "after: " << x << " " << y << endl; c }...
View Full Document

This note was uploaded on 10/17/2010 for the course SCIS COP 4338 taught by Professor Kipirvine during the Spring '10 term at FIU.

Ask a homework question - tutors are online