Analysis of function parameter passing features in C, java, and php

Source: Internet
Author: User
I have never had time to write my own understanding of pointers in C. Although this article has little to do with pointers, but for some people who want to have a deep understanding of the pointer, it is really necessary to take a look. I was particularly disgusted with the comparison between "transfer" and "reference transfer? I really want to say, who is defining "transfer" and "Introduction "?

I have never had time to write my own understanding of pointers in C. Although this article has little to do with pointers, but for some people who want to have a deep understanding of the pointer, it is really necessary to take a look. I was particularly disgusted with the comparison between "transfer" and "reference transfer? I really want to say, who is defining "transfer" and "Introduction "?

Zookeeper

I have never had time to write my own understanding of pointers in C. Although this article has little to do with pointers, but for some people who want to have a deep understanding of the pointer, it is really necessary to take a look.

I was particularly disgusted with the comparison between "value transfer" and "reference transfer?

I really want to say, who is defining the meaning of "value transfer" and "reference transfer?

However, most people in today's education have said this, and I have not proposed it to the teacher. I have contributed to my understanding and hope to help new friends.

First of all, I would like to advise those friends who are still struggling with the difference between "value transfer" and "reference transfer". Please do not worry about it. I will give you some advice here, in the traditional sense, the "value transfer" and "reference transfer" in the instructor's mouth actually refer to "passing when a parameter is not a pointer type" and "passing when a parameter is a pointer type "...


/*********************************
* About parameter transfer.
* In C, all parameters are transmitted using the value transfer method.
* Similar situations such as int a and Person p...
* (Note that I don't want to pay too much for it. Please note the meaning of direct modification that I want to express)
* 1: directly modifying the form parameter will not affect the actual parameter in any case.
* 2: directly modifying the members of the form parameter cannot affect the members of the actual parameter.
* 3: modifying the content pointed to by the pointer type member of a form parameter can affect the content pointed to by the pointer type member corresponding to the actual parameter...
* In C, there is also a parameter form called reference. I hope you can automatically understand the term 'quot' in different places...
* Person & p, int &
* 1: You can modify the members of an actual parameter by modifying the form parameter.
* 2: You can directly modify parameters to modify the actual parameters.
* (Note the second point is that neither java nor php can do it completely) ==> note: the reason for bringing a 'complete' is that php is barely able to do part of it...
*
* Java
* For java, everything is referenced.
* 1: The actual parameter itself cannot be changed by changing the form parameter.
* 2: You can change the members of the actual parameter by changing the members of the formal parameter.
* 3: in short, formal parameters and actual parameters actually reference the same object.
* To achieve the effect of not referencing the same object, you need to use the clone method. However, note that the clone method is displayed and called automatically.
* The clone method will never be related to parameter passing.
* (It doesn't matter how you understand common type data. Even if you understand it by reference, normal type variables do not have members.
* The formal parameters do not have any influence on the actual parameters.
*)
*
* Php is more similar to java
* For php. Similar to java.
* 1: first of all, for common data types, there is no such thing as a member. Therefore, formal parameters do not have any influence on actual parameters.
* 2: similar to java, a class object is a reference value by default.
* Similar to java
* 1: The actual parameter itself cannot be changed by changing the form parameter.
* 2: You can change the members of the actual parameter by changing the members of the formal parameter.
* 3: in short, formal parameters and actual parameters actually reference the same object.
*
* Difference. The above features of php are similar to those of java, but one thing is that java does not, that is &.
* First, compare the functions of C and php with those of C.
* Achieved the goal :{
* 1: You can modify the members of an actual parameter by modifying the form parameter.
* 2: You can directly modify parameters to modify the actual parameters.
*}
* However, php is not completely the same as c...
* Here we will explain that the so-called 'incompleteness 'is actually an incomplete implementation mechanism, and it is almost the same in actual use...
*
* Why is the implementation different?
* C references. The actual format parameter and actual parameter can be understood as one thing.
* Php cannot understand this.
* It can be considered that php is constantly maintaining the relationship between the two, resulting in consistency between the two at all times.
* That is, the two are not the same memory. When one is to be destroyed, the other is not destroyed.
* That is, when the unset function is used, only the association between the two is canceled.
*
*/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.