About function parameter passing-pointer passing and reference passing

Source: Internet
Author: User

About function parameter passing-pointer passing and reference passing

Today, I have discussed with my colleagues the issue of pointer and reference transfer. Some ideas are correct in terms of reasoning. However, because it is reasoning, it is not so confident to express your opinion, based on the principle that practice is the sole criterion of truth, I typed several pieces of code on the computer to verify the correctness of reasoning. First go to the code and then analyze it.

Code 1:

Void Swap0 (int a1, int b1) {int temp; temp = a1; a1 = b1; b1 = temp;} void Swap1 (int * a1, int * b1) {// exchange address int * temp; temp = a1; a1 = b1; b1 = a1;} void Swap2 (int * a1, int * b1) {int temp; temp = * a1; * a1 = * b1; * b1 = temp;} void Swap3 (int & a1, int & b1) {int temp; temp = a1; a1 = b1; b1 = temp;} int main () {int a = 1, B = 2; Swap0 (a, B); cout <"Swap0 :"
 <运行结果:

Examples/samples + samples/so6zL + samples/samples + 1xMr9vt29 + samples/ejrLDZtsiw2b/GveLKzbXju/e08r + qwbS906Opy/ yy2df3tcTKx9Xiv + nE2rTmo6zL + dLUy/weight + weight/weight + 1 xLHww/weight/0rvR + aOsy/weight + CjxwcmUgY2xhc3M9 "brush: java; "> typedef struct {int a;} A; void f1 (A * p) {p-> a = p-> a + 1 ;} void f2 (A * p) {(* p ). a = (* p ). a + 1 ;}int main () {A p; p. a = 1; f1 (& p); cout <"f1 p. a = "<

Related Article

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.