函数实现两数交换:
指针需掌握点:
应用1:
应用2:
#include <stdio.h>
void cal(int x,int y,int *jia,int *jian,int *chen,float *chu){
*jia = x + y;
*jian = x - y;
*chen = x * y;
*chu = (float)x / y;
}
int main(int argc, const char * argv[]) {
int jia1;
int jian1;
int chen1;
float chu1;
cal(12, 4, &jia1, &jian1, &chen1, &chu1);
printf("jia = %d
",jia1);
printf("jian = %d
",jian1);
printf("chen = %d
",chen1);
printf("chu = %.2f
",chu1);
printf("Hello, World!
");
return 0;
}
Pointers to structures are so often used that the language has a special operator. The structure pointer operator ->, which is a hyphen followed by the greater-than sign, permits expressions that would otherwise be written as
(*x).y
to be more clearly expressed as
x–>y