当前位置:网站首页>什麼是定義?什麼是聲明?它們有何區別?
什麼是定義?什麼是聲明?它們有何區別?
2022-07-03 07:48:00 【是北豼不太皮吖】
什麼是定義?
什麼是定義:所謂的定義就是(編譯器)創建一個對象,為這個對象分配一塊內存並給它取上一個名字,這個名字就是我們經常所說的變量名或對象名。但注意,這個名字一旦和這塊內存匹配起來,它們就同生共死,終生不離不弃。並且這塊內存的比特置也不能被改變。一個變量或對象在一定的區域內(比如函數內,全局等)只能被定義一次,如果定義多次,編譯器會提示你重複定義同一個變量或對象。
int i;
什麼是聲明?
什麼是聲明:有兩重含義,如下:
第一重含義:告訴編譯器,這個名字已經匹配到一塊內存上了,下面的代碼用到變量或對象是在別的地方定義的。聲明可以出現多次。
extern int i;
第二重含義:告訴編譯器,我這個名字我先預定了,別的地方再也不能用它來作為變量名或對象名。比如你在圖書館自習室的某個座比特上放了一本書,錶明這個座比特已經有人預訂,別人再也不允許使用這個座比特。其實這個時候你本人並沒有坐在這個座比特上。這種聲明最典型的例子就是函數參數的聲明,例如:
void fun(int i, char c);
它們有什麼區別?
定義是需要分配內存空間的。
聲明是不需要分配內存空間的。
边栏推荐
- [mindspire paper presentation] summary of training skills in AAAI long tail problem
- Static keyword
- register关键字
- Go language foundation ------ 14 ------ gotest
- 技术干货|昇思MindSpore初级课程上线:从基本概念到实操,1小时上手!
- PAT甲级 1031 Hello World for U
- Go language foundation ----- 06 ----- anonymous fields, fields with the same name
- Analysis of the problems of the 12th Blue Bridge Cup single chip microcomputer provincial competition
- 【MySQL 12】MySQL 8.0.18 重新初始化
- Go language foundation ----- 15 ----- reflection
猜你喜欢
技术干货|昇思MindSpore Lite1.5 特性发布,带来全新端侧AI体验
Pat class a 1031 Hello world for u
Analysis of the ninth Blue Bridge Cup single chip microcomputer provincial competition
Unity XR实现交互(抓取,移动旋转,传送,射击)-Pico
在浏览器输入url后执行什么
UA camouflage, get and post in requests carry parameters to obtain JSON format content
Project experience sharing: handwritten Chinese character recognition based on Shengsi mindspire
An article for you to understand - Manchester code
Technical dry goods Shengsi mindspire lite1.5 feature release, bringing a new end-to-end AI experience
【LeetCode】3. Merge two sorted lists · merge two ordered linked lists
随机推荐
[at] ABC 258g - Triangle triples reachable - violence
PAT甲级 1031 Hello World for U
yarn link 是如何帮助开发者对 NPM 包进行 debug 的?
Technical dry goods | hundred lines of code to write Bert, Shengsi mindspire ability reward
Paper learning -- Study on the similarity of water level time series of Xingzi station in Poyang Lake
优质博客——
Traversal in Lucene
Go language foundation ----- 19 ----- context usage principle, interface, derived context (the multiplexing of select can be better understood here)
Go language foundation ----- 13 ----- file
Go language foundation ----- 06 ----- anonymous fields, fields with the same name
Leetcode 198: house raiding
什么是数据类型?数据类型有什么用?
Technical dry goods Shengsi mindspire innovation model EPP mvsnet high-precision and efficient 3D reconstruction
HarmonyOS第三次培训笔记
Go language foundation ------ 12 ------ JSON
Implementation of breadth first in aggregation in ES
【LeetCode】4. Best Time to Buy and Sell Stock·股票买卖最佳时机
Huawei switch console password reset, device initialization, default password
华为交换机基础配置(telnet/ssh登录)
Go language foundation ----- 05 ----- structure