c语言 10-1

1、

#include <stdio.h>

void adjust(int *x)  //声明指向int型的指针变量x  
{
    if(*x < 0)
        *x = 0;
    if(*x > 100)
        *x = 100;
}

int main(void)
{
    int a, b, c;
    puts("please input three integers. < 0; 0 <  && < 100; > 100.");
    printf("a = "); scanf("%d", &a);
    printf("b = "); scanf("%d", &b);
    printf("c = "); scanf("%d", &c);
    
    adjust(&a);   //指针作为实参传递给指针形参x,x为指向a的指针,*x为a的别名,对*x进行的修改,就相当于对a进行修改,因此调用函数adjust后,a的值发生变化。 
    adjust(&b);
    adjust(&c);
    
    printf("
adjusted a = %d
", a);
    printf("adjusted b = %d
", b);
    printf("adjusted c = %d
", c);
    
    return 0;
}

原文地址:https://www.cnblogs.com/liujiaxin2018/p/14824635.html