这个简单代码的执行:
int foo(int* a){
cout <<"a="<<a;
*a=1;
cout <<", *a="<<*a<<endl;
return 0;}
int main () {
int* ptr;
ptr=new int[2];
ptr[0]=0;
ptr[1]=0;
cout<< foo(ptr) <<" "<< ptr <<" *ptr="<< *ptr <<endl;
cout<< foo(ptr) <<" "<< ptr <<" *ptr="<< *ptr <<endl;
return 0;}
导致(Linux):
a=0x939f008, *a=1
0 0x939f008 *ptr=0
a=0x939f008, *a=1
0 0x939f008 *ptr=1
请解释为什么*ptr=0在第二行,而在第四行没有;可能是“东西”从右到左“提取”到 cout
吗?比 - 它是如何工作的(在运行时一步一步)?
最佳答案
关于c++ - 我在这里遗漏了一些简单的东西(运行时执行优先级?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9461859/