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("\nadjusted a = %d\n", a);
    printf("adjusted b = %d\n", b);
    printf("adjusted c = %d\n", c);
    
    return 0;
}

 

posted @ 2021-05-29 10:25  小鲨鱼2018  阅读(64)  评论(0编辑  收藏  举报