summaryrefslogtreecommitdiff
path: root/reference/C/EXAMPLES/swap.c
blob: 63ac18b26c97df388e38504fa69d1da0d8e59dec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/******************************************************************
 *
 * Purpose: Program to demonstrate the use of ^ (XOR).
 * Date:    03-Dec-96
 * Author:  M J Leslie.
 * Descrip: The contents of two variables are swapped without
 *          the use of a temorary variable  
 *
 ******************************************************************/

#include <stdio.h>

main()
{

  int    	One = 20;
  int		Two = 12;

  printf("One = %d Two = %d\n", One, Two);

  One ^= Two;
  Two ^= One;
  One ^= Two;

  printf("One = %d Two = %d\n", One, Two);
}