我们从一个简单的程度開始:
// // main.cpp // Pointers // // // Copyright © 2016 GavinPSU. All rights reserved. // #include <iostream> using namespace std; int dog,cat,bird,fish; void f(int pet){ cout<<"pet id number: "<<pet<<endl; } int main(int argc, const char * argv[]) { // insert code here... int i,j,k; cout<<"f(): "<<(long)&f<<endl; cout<<"dog: "<<(long)&dog<<endl; cout<<"cat: "<<(long)&cat<<endl; cout<<"bird: "<<(long)&bird<<endl; cout<<"fish: "<<(long)&fish<<endl; cout<<"i: "<<(long)&i<<endl; cout<<"j: "<<(long)&j<<endl; cout<<"k: "<<(long)&k<<endl; return 0; } ///:~执行一次的结果例如以下:
f(): 4294971184 dog: 4294975680 cat: 4294975684 bird: 4294975688 fish: 4294975692 i: 140734799804284 j: 140734799804280 k: 140734799804276我们能够看到在main()内部和外部定义的变量存放在不同区域。
同一时候,在内存中代码和数据是一般分开存放的
。关于程序设计基石与实践很多其它讨论与交流,敬请关注本博客和新浪微博songzi_tea.