想请教各路大神这个V1,V2地址不同什么机制导致的
链接:https://www.nowcoder.com/questionTerminal/9fd169364f4a42599aa7ade7f1c9bbd9?toCommentId=1860979
来源:牛客网
来源:牛客网
函数func的定义如下:
1
2
3
4
5
|
voidfunc(constint& v1,constint& v2)
{
std::cout << v1 <<' ';
std::cout << v2 <<' ';
}
|
以下代码在vs中输出结果为____。
1
2
3
4
5
6
|
intmain (intargc,char* argv[])
{
int i=0;
func(++i,i++);
return0;
}
|
以上为题干
以下为测试demo
#include "stdafx.h"
#include <iostream>
using namespace std;
void func(const int& v1, const int & v2)
{
cout << "&v1 = "<< &v1 << endl;
cout << "&v2 = " << &v2 << endl;
std::cout <<"v1 = "<< v1 << ' ';
std::cout <<"v2 = "<< v2 << ' ';
}
int _tmain(int argc, _TCHAR* argv[])
{
int i = 0;
cout <<"&i = "<< &i << endl;
func(++i, i++);
system("pause");
return 0;
}
#include <iostream>
using namespace std;
void func(const int& v1, const int & v2)
{
cout << "&v1 = "<< &v1 << endl;
cout << "&v2 = " << &v2 << endl;
std::cout <<"v1 = "<< v1 << ' ';
std::cout <<"v2 = "<< v2 << ' ';
}
int _tmain(int argc, _TCHAR* argv[])
{
int i = 0;
cout <<"&i = "<< &i << endl;
func(++i, i++);
system("pause");
return 0;
}
以下为VS2013测试结果
&i = 004FFA04
&v1 = 004FFA04
&v2 = 004FF938
v1 = 2 v2 = 0 请按任意键继续. . .
&v1 = 004FFA04
&v2 = 004FF938
v1 = 2 v2 = 0 请按任意键继续. . .