#include<iostream>
using namespace std;
int a = 10;//全局变量
const int c_a = 10; //全局常量
static int s_a = 10; //静态变量
int* func()
{
int *p=new int(10);
int *arr = new int[10];
return arr;
}
int main()
{
int a1 = 10;//局部变量
const int c_a1 = 10;//局部常量
static int s_a1 = 10; //静态变量
cout << (int)&a <<" "<< (int)&a1<< endl;
cout << (int)&c_a << " " << (int)&c_a1 << endl;
cout << (int)&s_a << " " << (int)&s_a1 << endl;
int *arr = func();
//cout << *p << endl;
//cout << *p << endl;
for (int i = 0; i < 10; i++)
{
arr[i] =i+ 10;
}
for (int i = 0; i < 10; i++)
{
cout << arr[i] << endl;
}
delete[] arr;
return 0;
}
c++ 几种变量和常量的区分
最新推荐文章于 2023-12-19 12:28:39 发布