0027 C指针应用

函数实现两数交换:
函数实现两数交换

指针需掌握点:
指针需掌握点:

应用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\n",jia1);
    printf("jian = %d\n",jian1);
    printf("chen = %d\n",chen1);
    printf("chu = %.2f\n",chu1);
    
    printf("Hello, World!\n");
    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

posted @ 2015-07-11 09:27  挨踢控  阅读(111)  评论(0编辑  收藏  举报