DaidalosCheung / C

0 stars 0 forks source link

9 Function #3

Open DaidalosCheung opened 4 years ago

DaidalosCheung commented 4 years ago

include

void alter( int a, int b);

The first pointer

  int a, b;

  scanf("%d, %d", &a, &b);
  alter(&a, &b);
  printf("The difference between %d & %d is: %d\n", a, b, *&a);
  printf("And the sum is %d \n", *&b);

  return 0;
}

void alter( int *a, int *b)  {
  int temp = 0;

  temp = *a;
  *a = *a - *b;
  *b = temp + *b;
}
DaidalosCheung commented 4 years ago

a = 20, b = 18 The difference between 2 & 38 is: 2 And the sum is 38

After execute the alter function, a & b no longer have their previous value.