当前位置:网站首页>什么是定义?什么是声明?它们有何区别?
什么是定义?什么是声明?它们有何区别?
2022-07-03 07:42:00 【是北豼不太皮吖】
什么是定义?
什么是定义:所谓的定义就是(编译器)创建一个对象,为这个对象分配一块内存并给它取上一个名字,这个名字就是我们经常所说的变量名或对象名。但注意,这个名字一旦和这块内存匹配起来,它们就同生共死,终生不离不弃。并且这块内存的位置也不能被改变。一个变量或对象在一定的区域内(比如函数内,全局等)只能被定义一次,如果定义多次,编译器会提示你重复定义同一个变量或对象。
int i;
什么是声明?
什么是声明:有两重含义,如下:
第一重含义:告诉编译器,这个名字已经匹配到一块内存上了,下面的代码用到变量或对象是在别的地方定义的。声明可以出现多次。
extern int i;
第二重含义:告诉编译器,我这个名字我先预定了,别的地方再也不能用它来作为变量名或对象名。比如你在图书馆自习室的某个座位上放了一本书,表明这个座位已经有人预订,别人再也不允许使用这个座位。其实这个时候你本人并没有坐在这个座位上。这种声明最典型的例子就是函数参数的声明,例如:
void fun(int i, char c);
它们有什么区别?
定义是需要分配内存空间的。
声明是不需要分配内存空间的。
边栏推荐
- Industrial resilience
- [coppeliasim4.3] C calls UR5 in the remoteapi control scenario
- Hnsw introduction and some reference articles in lucene9
- Epoll related references
- TypeScript let与var的区别
- Technology dry goods | luxe model for the migration of mindspore NLP model -- reading comprehension task
- 项目经验分享:基于昇思MindSpore,使用DFCNN和CTC损失函数的声学模型实现
- Go language foundation ----- 15 ----- reflection
- 优质博客——
- Robots protocol
猜你喜欢
技术干货|昇思MindSpore创新模型EPP-MVSNet-高精高效的三维重建
Robots protocol
VMware network mode - bridge, host only, NAT network
Hnsw introduction and some reference articles in lucene9
Inverted chain disk storage in Lucene (pfordelta)
Technical dry goods | reproduce iccv2021 best paper swing transformer with Shengsi mindspire
Iterm2设置
項目經驗分享:實現一個昇思MindSpore 圖層 IR 融合優化 pass
The concept of C language pointer
Go language foundation ----- 01 ----- go language features
随机推荐
【踩坑系列】mysql 修改root密码失败
Go language foundation ------17 ----- channel creation, read-write, security shutdown, multiplexing select
技术干货 | AlphaFold/ RoseTTAFold开源复现(2)—AlphaFold流程分析和训练构建
Harmonyos third training notes
Industrial resilience
Structure of golang
Go language foundation ----- 05 ----- structure
The babbage industrial policy forum
GoLang之结构体
哪一刻你才发现青春结束了
Hisat2 - stringtie - deseq2 pipeline for bulk RNA seq
Iterm2设置
c语言指针的概念
技术干货|昇思MindSpore Lite1.5 特性发布,带来全新端侧AI体验
Qtip2 solves the problem of too many texts
Project experience sharing: Based on mindspore, the acoustic model is realized by using dfcnn and CTC loss function
PAT甲级 1027 Colors in Mars
pgAdmin 4 v6.11 发布,PostgreSQL 开源图形化管理工具
Unified handling and interception of exception exceptions of vertx
图像识别与检测--笔记