Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F102872182
ch-05-ex-03-solution.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Feb 25, 01:55
Size
677 B
Mime Type
text/x-c
Expires
Thu, Feb 27, 01:55 (2 d)
Engine
blob
Format
Raw Data
Handle
24446235
Attached To
R1106 Programming Concept Rouaze
ch-05-ex-03-solution.cpp
View Options
/*
* chapter-05-exercise-03.cpp
*
* Swap functions
*
* Created on: Oct 8, 2012
* Author: Radu Popescu <radu.popescu@epfl.ch>
*/
#include <iostream>
void swap1(double* const x, double* const y)
{
const double temp = *x;
*x = *y;
*y = temp;
}
void swap2(double& x, double& y)
{
const double temp = x;
x = y;
y = temp;
}
int main(int argc, char* argv[])
{
double x = 2.73;
double y = -3.141592;
std::cout << "The numbers are: " << x << " " << y << std::endl;
swap1(&x, &y);
std::cout << "We've swapped the numbers: " << x << " " << y << std::endl;
swap2(x, y);
std::cout << "And swapped them back: " << x << " " << y << std::endl;
return 0;
}
Event Timeline
Log In to Comment