05-13 07:28
Notice
Recent Posts
Recent Comments
관리 메뉴

Scientific Computing & Data Science

[C/C++] Example / swap: call by reference 본문

Programming/C&C++

[C/C++] Example / swap: call by reference

cinema4dr12 2014. 6. 12. 10:11


// Test-002.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <iomanip>

using namespace std;

// fucntions prototype
int factorial( int x);
void swap( int & x, int & y);

int _tmain( int argc , _TCHAR * argv [])
{
    int a = 4;
    int b = 3;
    cout << a << " , " << b << endl;
    swap(a ,b);
    cout << a << " , " << b << endl;
   
   
    int c = 25;
    cout << hex << c << endl;
   
   
    return 0 ;
}

int factorial( int x ) {
    int fact = 1;
    while ( x > 1) {
        fact *= x;
        x--;
    }
   
     return fact ;
}

void swap( int & x, int & y) {
    int tmp = x;
    x = y;
    y = tmp;
}

'Programming > C&C++' 카테고리의 다른 글

[C/C++] Example / Class  (0) 2014.06.12
[C/C++] Example / Pointer of Structure  (0) 2014.06.12
[C/C++] Example / Structure  (0) 2014.06.12
[C/C++] Example / Dynamic Array  (0) 2014.06.12
[C/C++] Example / swap: call by pointer  (0) 2014.06.12
Comments