📄 p6_3.cpp
字号:
/**************************************
* p6_3.cpp *
* 显示各类变量的内存分配 *
***************************************/
#include <iostream>
using namespace std;
int k=300;
const int i=100;
#define n 10
const int j=200;
void fun(int i=1,int j=2)
{
int k=3;
static int l=0;
char *p=new char[n+1];
for(int m=0;m<n;m++)
p[m]='A'+m;
p[m]='\0';
cout<<"Adddress of parameter variable:"<<endl;
cout<<"&i="<<&i<<"\t"<<"&j="<<&j<<endl;
cout<<"Adddress of local variable:"<<endl;
cout<<"&k="<<&k<<"\t"<<"&p="<<&p<<"\t"<<"&m="<<&m<<endl;
cout<<"Adddress of static local variable:"<<endl;
cout<<"&l="<<&l<<endl;
cout<<"Address of heap: "<<(void *)p<<endl;
cout<<"before delete p="<<p<<endl;
delete [] p;
cout<<"after delete: "<<(void *)p<<endl;
cout<<"p="<<p<<endl;
}
void main()
{
L1: fun();
L2: cout<<"Adddress of global variable:"<<endl;
cout<<"&i="<<&i<<"\t"<<"&j="<<&j<<"\t"<<"&k="<<&k<<endl;
cout<<"Address of function:"<<endl;
cout<<"&fun="<<&fun<<"\t"<<"&main"<<&main<<endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -