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; }
标签:10,语言,int,scanf,adjust,printf,100,指针 来源: https://www.cnblogs.com/liujiaxin2018/p/14824635.html