Home > Back-end >  Questions about the argument structure pointer to do
Questions about the argument structure pointer to do

Time:12-01

Why structure pointer argument can't do here, with its address by value,,,

CodePudding user response:

Because this parameter is to require a passing parameters, if it's just a incoming parameters, is not to need to pass its address, if you want to put the P application space of the chain to the rear, you need to pass the address of the rear, this will have the right to modify the Attach with rear function, is to ensure that Attach to modify the rear in the calling function, rather than the Attach the parameter in the function,

CodePudding user response:

This belongs to the common problems, lz if understand the value of the argument (structure parameters) and pass the address of the argument (pointer parameter), the difference between that should understand,
If by value, modify the parameter in a function is a function does not affect the outside of the argument (because the parameter is a copy of the argument, belongs to the different function of the stack memory space, both in addition to the same value without any connection), it should be the basic knowledge of the most basic, isn't it? So to modify function outside the argument? That is using a pointer passed argument addresses (such parameters and arguments to address is the same, that there was a link can change influence one another),
So, you want to be in the Attach revise pRear makes function outside rear argument also affected, that is about to pass the address of the rear (that is, to use a pointer type or a reference type)

CodePudding user response:

reference 1/f, confident boy reply:
because this parameter is to require a passing parameters, if it's just a incoming parameters, is not to need to pass its address, if you want to put the P application space of the chain to the rear, you need to pass the address of the rear, this will have the right to modify the Attach with rear function, is to ensure that Attach to modify the rear in the calling function, rather than the Attach the parameter in the function,

If the pointer is a structure that can only be made so that the value of the spread of a linked list area, if the structure pointer address, you can change to head node pointer to make it a point to other any address this operation to pass out
Excuse me, is this meaning?

CodePudding user response:

references to ensure that I don't learn reply: 3/f
Quote: reference 1/f, confident boy reply:
because this parameter is to require a passing parameters, if it's just a incoming parameters, is not to need to pass its address, if you want to put the P application space of the chain to the rear, you need to pass the address of the rear, this will have the right to modify the Attach with rear function, is to ensure that Attach to modify the rear in the calling function, rather than the Attach the parameter in the function,

If the pointer is a structure that can only be made so that the value of the spread of a linked list area, if the structure pointer address, you can change to head node pointer to make it a point to other any address this operation to pass out
Excuse me, is this meaning?

No matter what kind of a pointer, no matter how big is this structure, the structure pointer will only pass the sizeof (long) the size of a pointer to parameter, parameter can only receive this size,
So the pointer size is fixed, sizeof (long) size
  • Related