Code:
// More on pointers and functions#include <stdio.h>
void exchange (int * const pint1, int * const pint2)
{
int temp;
temp = *pint1;
*pint1 = *pint2;
*pint2 = temp;
}
int main (void)
{
void exchange (int * const pint1, int * const pint2);
int i1 = -5, i2 = 66, *p1 = &i1, *p2 = &i2;
printf ("i1 = %i, i2 = %i\n", i1, i2);
exchange (p1, p2);
printf ("i1 = %i, i2 = %i\n", i1, i2);
exchange (&i1, &i2);
printf ("i1 = %i, i2 = %i\n", i1, i2);
return 0;
}
I want to verify my understanding of the second call to the exchange function. Pasted below for convenience:
exchange (&i1, &i2);
printf ("i1 = %i, i2 = %i\n", i1, i2);
So when &i1 and &i2 are pased as arguments. is the following true and what goes on in the function:
temp = *i1
*i1 = **i2;
*i2 = temp;