05-13 01:49
Notice
Recent Posts
Recent Comments
관리 메뉴

Scientific Computing & Data Science

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

Programming/C&C++

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

cinema4dr12 2014. 6. 12. 10:13

//
//  main.cpp
//  Test-001
//
//  Created by gchoi on 2014. 4. 30..
//  Copyright (c) 2014년 gchoi. All rights reserved.
//

#include <iostream>
#include <string>

using namespace std;

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


int main( int argc , const char * argv [])
{
    int a = 4;
    int b = 3;
    int * pa;
    int * pb;
    pa = &a ;
    pb = &b ;
   
    cout << "a: " << a << " , " << "b: " << b << endl;
    swap(pa , pb );
    cout << "a: " << a << " , " << "b: " << b << endl;
   
    return 0 ;
}

void swap(int* x, int* y) {
    int tmp ;
    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 reference  (0) 2014.06.12
Comments