当前位置:网站首页>全局变量、局部变量、静态变量和常量的地址分配
全局变量、局部变量、静态变量和常量的地址分配
2022-07-16 08:17:00 【anthony-36】
#include <iostream>
using namespace std;
//全局变量
int g_a = 10;
int g_b = 10;
const int c_g_a = 10;
const int c_g_b = 10;
int main()
{
//全局区
//全局变量、静态变量、常量
//创建普通局部变量
int a = 10;
int b = 10;
cout << "局部变量a的地址为:" << (int)&a << endl;
cout << "局部变量b的地址为:" << (int)&b << endl;
cout << "全局变量g_a的地址为:" << (int)&g_a << endl;
cout << "全局变量g_b的地址为:" << (int)&g_b << endl;
//静态变量
static int s_a = 10;
static int s_b = 10;
cout << "静态变量s_a的地址为:" << (int)&s_a << endl;
cout << "静态变量s_b的地址为:" << (int)&s_b << endl;
//常量
//字符串常量——字符串引起来的
cout << "字符串常量的地址为:" << (int)&"hello world" << endl;
//const修饰的变量
//const修饰的全局变量,const修饰的局部变量
cout << "全局变量c_g_a的地址为:" << (int)&c_g_a << endl;
cout << "全局变量c_g_b的地址为:" << (int)&c_g_b << endl;
const int c_l_a = 10;
const int c_l_b = 10;
cout << "局部变量c_l_a的地址为:" << (int)&c_l_a << endl;
cout << "局部变量c_l_b的地址为:" << (int)&c_l_b << endl;
return 0;
}

这里可以看到局部变量和局部常量都在一个区中,但不在全局区中。
而全局变量、静态变量、全局常量和字符串变量都在全局区中。
边栏推荐
- How to set up domain name resolution?
- PostgreSQL is now installed
- 基于poll实现聊天室
- 465-剑指offer(53-I、53-II、04、50)
- 1111111111111
- Introduction of some attention mechanisms in deep learning and implementation of pytorch code
- Error establishing connection between MySQL and idea
- 【前缀和和差分】
- Specify TLS 1.3 and ciphers to improve security and performance
- 新功能上线需要发版本,回归测试中总是出现之前没有的问题
猜你喜欢

JS Object. keys()

Rotation in ue4/5: three Euler angles picth, yaw, roll and frotator

VMware 虚拟机运行卡慢的解决办法

gradle

深度学习中一些注意力机制的介绍以及pytorch代码实现

The pits encountered using arcpy (3)

Metaltc5.0 implements webrtc version IPC

Free SSL certificate application and deployment practice
![[training Day2] sculpture [pressure DP]](/img/d9/6cfb1bf1d4d188993cbba4aa053e4b.png)
[training Day2] sculpture [pressure DP]

How to set up domain name resolution?
随机推荐
UE4/5中的旋转:三个欧拉角Picth、Yaw、Roll及FRotator
The pits encountered using arcpy (3)
Surmonter les défis de la transformation numérique en élaborant une vision
Principle analysis of Rex engine of osgearth (one, two, eight) Rex engine and layer projection and their relationship
High performance timer
iowait 理解
Class loader & parental delegation mechanism & breaking parental delegation mechanism
C语言求回文质数
What are the core technologies of okcc call center system
Enable remote rsyslog logging service
Implement chat room based on poll
cpu由什么组成
Lscale theme emlog background management panel theme source code
再次了解max_allowed_packet
R language - color selection and setting
. Net to publish the project to the server in the form of file
剑指offer 46:把数字翻译成字符串
AutoJs学习-TTS抢语音红包
Software testing interview: please talk about the most valuable bugs you found in your work?
gradle