------------------------------------------------------------------------------
MC logo
Swap Using Pointers
[^] CSc 220 Home
------------------------------------------------------------------------------
[Introduction] [Boolean and Control] [Functions] [Arrays and Pointers] [Dynamic Arrays] [Array Errors] [Command Array] [Standard Containers] [Structs and Classes] [Automatic Pointer] [Multi-File Programs] [Copying Objects] [Templates] [Inheritance] [Plain C I/O] [Type Odds And Ends] [Plain C Strings] [File I/O]
[Array Echo] [Basic Pointers] [Swap Using Pointers] [Arrays and Pointers] [Array Passing] [Integer Select Sort] [Integer Quick Sort] [Integer Library Sort] [Pointers and References]
swap.cpp
#include <iostream>

void swap(int *a, int *b)
{
        int t = *a;
        *a = *b;
        *b = t;
}

main()
{
        int x = 15, y = 74;
        std::cout << x << " " << y << std::endl;
        swap(&x, &y);
        std::cout << x << " " << y << std::endl;
}