Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F85750955
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, Oct 1, 21:14
Size
689 B
Mime Type
text/x-c
Expires
Thu, Oct 3, 21:14 (1 d, 20 h)
Engine
blob
Format
Raw Data
Handle
21261612
Attached To
R9360 PCSC_git
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