Ax_Terminology
xa_pointer
pointer is the address used to store the variable;A variable (or data object) whose value is a memory address
Bx_Operator
xa_indirection operator(*)
xb_address operator(&)
Cx_Program
xa_not use pointer
#include <stdio.h>
void verse(int u,int k);
//// main function ////
int main(void)
{
int a = 1, b = 10;
printf("one : %d %d\n",a ,b);
verse(a, b);
printf("one : %d %d\n",a ,b);
return 0;
}
//// exchange function ////
void verse(int u,int k)
{
int o;
printf("%d %d\n", u, k);
o = u;
u = k;
k = o;
printf("%d %d\n", u, k);
}
//one do not exchange
xb_use pointer
#include <stdio.h>
void verse(int * u, int * y);
//// main ////
int main(void)
{
int x = 5, y = 10;
printf("before x >> %d y >> %d\n", x, y);
verse(&x, &y);
printf("now x >> %d y >> %d\n", x, y);
return 0;
}
//// exchange /////
void verse(int * u, int * y)
{
int odd;
odd = *u;
*u = *y;
*y = odd;
}