Swapping two integers

#include <stdio.h>
 
void swap(int *p, int *q);
 
int main(void)
{
   int   a = 2, b = 5;
 
   printf("%d  %d\n", a, b);     /* 2  5 is printed */
   swap(&a, &b);
   printf("%d  %d\n", a, b);     /* 5  2 is printed */
   return 0;
}
 
void swap(int *p, int *q)
{
   int   tmp;
 
   tmp = *p;
   *p = *q;
   *q = tmp;
}
 
 
Creative Commons License Valid CSS Valid XHTML 1.0 Driven by DokuWiki Powered by PHP Powered by Apache get firefox!! kgareth.com Recent changes RSS feed