#include "stdio.h"
#include "stdlib.h"
void swap(int &, int &);
void swap(int &a, int &b)
{
int x;
x = a;
a = b;
b = x;
}
int main()
{
int m, n;
m = 5;
n = 7;
printf("[Before] m = %d <-> n = %d \n", m, n);->
swap(m, n);
printf("[After] m = %d <-> n = %d \n", m, n);->
return 0;
}
=====Result=====
[Before] m =5 <-> n = 7 ->
[After] m =7 <-> n = 5->
(ps: C無call by reference 所以 **.c檔是無法編譯,需使用cpp檔)
沒有留言:
張貼留言