Pointer function parameter

 By value, then the data can only be changed in the function domain

Pass pointers: in the main function, so that call funcA (& a, b); the function is called, by taking the address indicated by the pointer operator pass values

              Defining a function, void funcA (int * p_int_a, int int_b), by the symbol * pointer, indicating the address

* After adding the pointer, the pointer corresponding to the contents stored in the address which points represented,

#include <stdio.h>


void funcA(int *p_int_a, int int_b)
{
	*p_int_a = 100;
	int_b = 200;
	printf("funcA: *p_int_a=%d,int_b=%d\n", *p_int_a, int_b);
}
int main(int argc, char **argv)
{
	int a, b;
	a = 20;
	b = 30;
	printf("main a=%d,b=%d\n", a, b);
	funcA(&a, b);
	printf("main a=%d,b=%d\n", a, b);
	system("pause");
}

Published 29 original articles · won praise 3 · Views 3174

Guess you like

Origin blog.csdn.net/qq_38436175/article/details/104043241