C/C++中的 形参,实参,传值,传地址,传引用 的问题,
- package com.itheima.net;
- public class Test
- {
- public static void main(String[] args)
- {
- Long l = new Long(0);
- Integer i = new Integer(0);
- change(l, i);
- System.out.println(l);
- System.out.println(i);
- //---------------------------------
- Long[] arrL = { (long) 0 };
- Integer[] arrI = { 0 };
- change(arrL, arrI);
- System.out.println(arrL[0]);
- System.out.println(arrI[0]);
- }
- private static void change(Long ll, Integer ii) //传值 :是把是实参的值赋给形参,形参的更改不会影响实参的值
- {
- for (int j = 0; j < 10; j++)
- {
- ll++;
- ii++;
- System.out.println(ll + "," + ii);
- }
- }
- private static void change(Long[] arrL, Integer[] arrI) //传地址: 传递地址以后,系统在栈中开辟空间存放地址,
- //实参和形参都指向同一个对象,形参的更改将 影响实参的值
- {
- for (int j = 0; j < 10; j++)
- {
- arrL[0]++;
- arrI[0]++;
- System.out.println(arrL[0] + "," + arrI[0]);
- }
- }
- }
复制代码 |