Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the differences between passing values and passing addresses in programming techniques

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article is about the differences between passing values and passing addresses in programming techniques. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The difference between passing value and address: 1, in the value of the function parameter stack is the copy of the parameter, any modification is the role of the copy, no effect on the original variable; 2, the address of the stack is the copy of the pointer variable, when you solve the pointer operation on the pointer, its value is to point to the original variable.

The difference between passing values and passing addresses:

1, in the value of the function parameter stack is the copy of the parameter, any modification is on the copy, not on the original variable.

2, the stack in the address is the copy of the pointer variable, when you unpointer operation to the pointer, its value is to point to the original variable, so operate on the original variable.

Extended data

There are three ways to pass parameters of a function: value, address and reference.

1. Pass by value

The main results are as follows: (1) formal parameters and actual parameters occupy an independent storage space.

(2) the storage space of the parameter is allocated only when the function is called. At the beginning of the call, the system opens up a temporary storage area for the parameter, and then passes each parameter to the parameter, which gets the value of the parameter.

2. Address delivery

Address passing differs from value passing in that it passes the storage address of the argument to the parameter so that the parameter pointer and the argument pointer point to the same address. Therefore, any change in the content of the address pointed to by the parameter pointer in the called function will affect the argument.

3. Citation transfer

The reference passing takes the reference as a parameter, which can not only change the corresponding data in any operation on the parameter, but also make the function call convenient. Reference passing is to add the reference operator "&" before the formal parameter call.

If the reference is an alias for the argument, and the argument is the same variable, their values are the same, and if the reference changes, so does its argument.

Thank you for reading! This is the end of the article on "what is the difference between passing values and addresses in programming technology". I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report