View Single Post
Old Feb 6th, 2007, 4:02 PM   #5
jim mcnamara
Hobbyist Programmer
 
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4 jim mcnamara is on a distinguished road
void swap( int *a, int *b)
{
        int t=*a;
        *a=*b;
        *b=t;
}

int main()
{
        int x=1;
        int y=2;
        int *a=&x;
        int *b=&y;
        printf("%d %d\n", *a, *b);
        swap(a,b);
        printf("%d %d\n", *a, *b);
        return 0;

}
kcsdev:/home/jmcnama> cc t.c
kcsdev:/home/jmcnama> ./a.out
1 2
2 1

FWIW. I think he meant to swap what the pointers were "aimed" at. Not the actual pointers themselves. But it doesn't matter....
jim mcnamara is offline   Reply With Quote