The benefits of using pointers for function parameters,
The first step is to understand the process of function parameter transfer, which is a copy type, for example
void Modify (int a)
{
a++;
}
void Main ()
{
int a=5;
Modify (a);
printf ("%d", a);
}
After the execution of the program, the value of a is still 5, for what, because in the execution of the Modify function, is another open storage space, the value of a copy of the past, and then the Modify function to do all the operation is for this newly opened space, so after the execution of the program, The value of a does not change,
If we use pointers to pass parameters, it's a whole different time,
void Modify (int * a)
{
(*a) + +;
}
void Main ()
{
int a=5;
Modify (&a);
printf ("%d", a);
}
The execution of the program is of course 6, because you pass the address of a, so the Modify function is a address above the contents of the operation, with the pointer as a function parameter, when the parameter is actually also opened up a storage space, and then the value of the pointer copied past, The function then operates on this pointer variable inside the newly opened storage space.
When to use the pointer, when the normal copy of the way to pass the parameters, when the parameters passed is a structure, and the structure is relatively large, this time it is best to use a pointer, if the copy, the only time spent in the copy will be wasted,
The benefits of using pointers for function parameters,