#include<stdio.h>void f (int a,int b,int c){
a=a+1,b=b+2,c=c+3;}int main
{
int a,b=2,c=3;f(a,b,c);printf(“%d %d %d”,a,b,c);}
结果是123
因为形参无法改变实参的值,所以,a,b,c的值不变。
#include<stdio.h>void f (){
int x,y;int a=15,b=10;
x=a-b;
y=a+b;}int x,y;{
int a=7,b=5;
x=a-b;
y=a+b;f();printf("%d %d\n",x,y);}
结果是525
由于函数中的·形参有定义,所以会输出函数中的求解值。
#include<stdio.h>void f (){
int a =0;staticint b =0;printf("%d %d\n", a, b);
a++;
b++;}int main (void){
int i =3;int a=3,b=3;do{
f();
i--;}while(i >=2);}
结果是
0001
如果printf在函数中,那么不受主函数影响。