当前位置:网站首页>什麼是定義?什麼是聲明?它們有何區別?
什麼是定義?什麼是聲明?它們有何區別?
2022-07-03 07:48:00 【是北豼不太皮吖】
什麼是定義?
什麼是定義:所謂的定義就是(編譯器)創建一個對象,為這個對象分配一塊內存並給它取上一個名字,這個名字就是我們經常所說的變量名或對象名。但注意,這個名字一旦和這塊內存匹配起來,它們就同生共死,終生不離不弃。並且這塊內存的比特置也不能被改變。一個變量或對象在一定的區域內(比如函數內,全局等)只能被定義一次,如果定義多次,編譯器會提示你重複定義同一個變量或對象。
int i;
什麼是聲明?
什麼是聲明:有兩重含義,如下:
第一重含義:告訴編譯器,這個名字已經匹配到一塊內存上了,下面的代碼用到變量或對象是在別的地方定義的。聲明可以出現多次。
extern int i;
第二重含義:告訴編譯器,我這個名字我先預定了,別的地方再也不能用它來作為變量名或對象名。比如你在圖書館自習室的某個座比特上放了一本書,錶明這個座比特已經有人預訂,別人再也不允許使用這個座比特。其實這個時候你本人並沒有坐在這個座比特上。這種聲明最典型的例子就是函數參數的聲明,例如:
void fun(int i, char c);
它們有什麼區別?
定義是需要分配內存空間的。
聲明是不需要分配內存空間的。
边栏推荐
- Go language foundation ----- 10 ----- string related operations (operation function, string conversion)
- 优质博客——
- 截图工具Snipaste
- Go language foundation ------ 12 ------ JSON
- Redis profile
- Go language foundation ------17 ----- channel creation, read-write, security shutdown, multiplexing select
- Go language foundation ----- 09 ----- exception handling (error, panic, recover)
- 【LeetCode】2. Valid parentheses · valid parentheses
- What did the DFS phase do
- Technical dry goods Shengsi mindspire elementary course online: from basic concepts to practical operation, 1 hour to start!
猜你喜欢

技术干货|昇思MindSpore NLP模型迁移之Bert模型—文本匹配任务(二):训练和评估

【踩坑系列】mysql 修改root密码失败

【MindSpore论文精讲】AAAI长尾问题中训练技巧的总结

Go language foundation ----- 01 ----- go language features

Technical dry goods | reproduce iccv2021 best paper swing transformer with Shengsi mindspire

在浏览器输入url后执行什么

Project experience sharing: handwritten Chinese character recognition based on Shengsi mindspire
![[MySQL 11] how to solve the case sensitive problem of MySQL 8.0.18](/img/9b/db5fe1a37e0de5ba363f9e108310a5.png)
[MySQL 11] how to solve the case sensitive problem of MySQL 8.0.18

Iterm2设置

技术干货 | AlphaFold/ RoseTTAFold开源复现(2)—AlphaFold流程分析和训练构建
随机推荐
What did the DFS phase do
Redis batch startup and shutdown script
Microsoft Security Response Center
【LeetCode】2. Valid parentheses · valid parentheses
华为交换机配置ssh登录远程管理交换机
Analysis of the problems of the 7th Blue Bridge Cup single chip microcomputer provincial competition
技术干货|昇思MindSpore初级课程上线:从基本概念到实操,1小时上手!
Redis profile
[at] abc 258G - Triangle 三元组可达-暴力
什么是数据类型?数据类型有什么用?
Go language foundation ----- 16 ----- goroutine, GPM model
华为S5700交换机初始化和配置telnet,ssh用户方法
Go language foundation ----- 11 ----- regular expression
LwIP learning socket (API)
Analysis of the problems of the 10th Blue Bridge Cup single chip microcomputer provincial competition
【MySQL 11】怎么解决MySQL 8.0.18 大小写敏感问题
Technology dry goods | Roberta of the migration of mindspore NLP model - emotion analysis task
优质博客——
HDMI2.1与HDMI2.0的区别以及转换PD信号。
PHP common sorting algorithm