The formal and actual parameters are in the function

  1. List item
#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);
}

结果是1 2 3 
因为形参无法改变实参的值,所以,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);
}
结果是5 25
由于函数中的·形参有定义,所以会输出函数中的求解值。

#include <stdio.h>

void f () 
{
    
    
	int a = 0;
	static int 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);
}
结果是
           0   0
           0   1
如果printf在函数中,那么不受主函数影响。

Guess you like

Origin blog.csdn.net/weixin_52045928/article/details/112381728