Previous      Next

//  Bad Mistake!!
//  Forgot to use pointers in parameters

void swap (int *x, int *y)
{
   int t;
   
   t = *x;
   *x = *y;
   *y = t;
}

void main()
{
   int a = 10, b = 20;
   
   printf("\nValue of a: %d  Value of b: %d\n", a, b);
   swap (a, b);
   printf("Value of a: %d  Value of b: %d\n", a, b);   
}

// Sample Output:
//   Value of a: 10  Value of b: 20
//   Segmentation fault (core dumped)