Reference distance of pointer variables in C language

In this code, test, in C function parameters, the formal parameters are basic type parameters and address parameters, which affect the value of the actual parameters.

#include <stdio.h>
add(int a,int b){
    
    
	a++;
	b++;
		printf("add副本a=%d\n",a);
		printf("add副本b=%d\n",b);
		printf("副本c=a+b=%d\n",a+b);
}

int padd(int *pa,int *pb){
    
    
	*pa=*pa+1;
	*pb=*pb+1;
	return *pa+*pb;	
}


main(){
    
    
	
	int a,b,c;
	a=3;
	b=4;	
	printf("a=%d\n",a);
	printf("b=%d\n",b);	
	add(a,b);
	
	
	printf("==============\n");
	printf("a=%d\n",a);
	printf("b=%d\n",b);
		
    printf("===调用c=padd(&a,&b);==\n");
	c=padd(&a,&b);
	
	printf("a=%d\n",a);
	printf("b=%d\n",b);
	printf("c=a+b=%d\n",c);
	
	
	
	
	
	
}

Insert image description here

Supongo que te gusta

Origin blog.csdn.net/Climbman/article/details/133200804
Recomendado
Clasificación