变量声明顺序和指针偏移问题示例
#include<iostream>
using namespace std;
void run();
int main() {
run();
}
void run() {
//int i2 = 555, i1 = 666; //if opened, the result will be 1, which is the space not allocated
int i1= 555 , i2 = 666; //跟声明顺序有关,先声明的变量会先被分配到内存空间
int* ptr = &i1;
cout << &i1 << " : " << &i2 << endl;
ptr--;
int i3 = *ptr;
cout << i3 << endl;//666
}
本文来自博客园,作者:艾孜尔江,转载请注明原文链接:https://www.cnblogs.com/ezhar/p/13745393.html