如果我们有这个代码:
int foo=100;
int& reference = foo;
int* pointer = &reference;
Run Code Online (Sandbox Code Playgroud)
参考数据和指针数据之间没有实际的二进制差异.(它们都包含记忆中的位置foo)
第2部分
那么指针和引用之间的所有其他差异(这里讨论)会在哪里出现?编译器是执行它们还是它们在可组合级别上实际上是不同类型的变量?换句话说,下面是否生成相同的汇编语言?
foo=100;
int& reference=foo;
reference=5;
foo=100;
int* pointer=&foo;
*pointer=5;
Run Code Online (Sandbox Code Playgroud) 假设我有这样的代码;
public void insert(Student[] stus)
{
int count = 0;
for(Student s: stus)
{
s.setId( bla bla);
stus[count].setId(bla bla) // is this line needed?
count++;
}
}
Run Code Online (Sandbox Code Playgroud)
因此,如果我从增强的for循环更改s上的任何内容,我是否也可以看到stus数组中的更改?循环复制的增强如何在参数或其他东西中起作用?