生活资讯
declarations 、declarations翻译
2023-04-12 00:24  浏览:26

变量的声明和定义区别

典型的C++程序通常会由好多文件组成。为了使不同的文件都可以访问同一个变量,C++会区分变量的声明(declarations)和定义(definitions)。

变量的定义(definitions)会为这个变量分配存储空间,并且可能会为其指定一个初始化的值。在程序里,一个变量必须有一个,也只能有一处定义(definitions)。

变量的声明(declarations)会将变量的类型和名称传达给程序。当然,定义(definitions)也是一种声明:当我们定义一个变量的时候,我们当然也声明了他的名称和类型。我们可以通过使用“extern”关键字来声明(declarations)一个变量,而不用定义(definitions)它。声明(declarations)的形式就是在对象(变量)的名字和类型前面,加上关键字“extern”:

带“extern”关键字的语句属于声明(declarations),不是定义(definitions),他不会给变量分配内存。实际上,它是说明程序中的某处包含这个变量的定义。一个变量可以在程序中被声明(declarations)多次,但是只能被定义(definitions)一次。

声明(declarations)时你可以给变量初始化。但是一旦你这样做,那么这句话也就变成了定义(definitions),因为只有在定义(definitions)的时候才会为变量分配内存。初始化的时候必然要为初始值分配存储空间。如果你在声明(declarations)的时候同时初始化了变量,即便“extern”关键字存在,这个语句也会认为是定义(definitions)。

不管有没有“extern”关键字存在,这条语句的作用也是定义(definitions)“pi”。变量已经被分配了内存,并且赋予了初始值。声明(declarations)只有在一种情况下可以被初始化,那就是当他被放置在函数外部的时候。

由于包含初始化的声明(declarations)语句会被认为是定义(definitions),所以如下的用法会被认为是错误的:

同样的,定义(definitions)后再使用同样的声明(declarations)也是错误的:

声明(declarations)和定义(definitions)之间的区别看似有些卖弄学问的嫌疑,但是其实是非常重要的。

笔记

在C++里,变量必须被定义一次,最多一次,至少一次,而且必须在使用前定义(definitions)或者声明(declarations)。

任何一个在多个文件中都要用到的变量都需要在没有其定义(definitions)的文件里对其进行声明(declarations)。在这样的情况下,一般一个文件会包含该变量的定义(definitions)。其他用到该变量的文件就会包含该变量的声明(declarations),而不是定义(definitions)。

declarations section怎么写

declarations section

声明段

例句:

1

With this overview of how the program works, let's begin at the beginning with the declarations section.

大致了解了程序的运行原理后,让我们从带有声明部分的开头位置开始学习。

2

The declarations section is also optional; you can omit it entirely if you don't invoke gperf with the-t option.  

声明部分也是可选的;如果没有使用-t选项调用gperf,则完全可以忽略声明部分。

declaration是什么意思

declaration

[英][ˌdekləˈreɪʃn][美][ˌdɛkləˈreʃən]

n.宣言,布告,公告,声明; (纳税品在海关的)申报; [法](原告的)申诉,(证人的)陈述,口供; [牌]摊牌,叫牌;

复数:declarations

例句:

1.

Mr obama linked the summit's declaration with the prosperity of ordinary americans.

奥巴马把峰会宣言与美国普通民众的繁荣联系在一起。

2.

Using every declaration just once means making strict use of selector grouping.

每种声明只使用一次意味着对选择器进行更加严格的分组。

declaration和statement有什么区别

一、词语辨析不一样

1、declaration 指官方或正式的公告、宣告、宣言、声明:

They will sign the declaration tomorrow

他们明天将签署这份公告。

2、statement 通常指正式的说明、声明、陈述、报告:

A government spokesperson made a statement to the press.

政府发言人向新闻界发表了一份声明。

二、词义广泛性不一样

declaration

英 [ˌdekləˈreɪʃn]   美 [ˌdɛkləˈreʃən]

n.宣言,布告,公告,声明;(纳税品在海关的)申报

statement

英 ['steɪtm(ə)nt]  美 ['stetmənt]

1、n. 声明;陈述,叙述;报表,清单

2、vi.(英国)对儿童进行特殊教育评估认定

3、vt.申请(小孩)有特殊教育需要

三、变形词不一样

declaration

只有复数变形词: declarations

statement

第三人称单数: statements 复数: statements 现在分词: statementing 过去式: statemented 过去分词: statemented

declaration怎么读

declaration[英][ˌdekləˈreɪʃn][美][ˌdɛkləˈreʃən]n.宣言,布告,公告,声明;(纳税品在海关的)申报;[法](原告的)申诉,(证人的)陈述,口供;[牌]摊牌,叫牌;复数:declarations双语例句1Itwa***eanttosoundlikeanepoch-makingdeclaration.有意让它听起来像是一个划时代的宣言。2NowthislatestdeclarationfromCEODanakerson.现在又是CEO丹•阿克森出面声明。

Declarations是什么意思

声明(declaration的复数);宣言;(纳税品在海关的)申报;【法】(原告的)申诉

宣告;宣告类;宣布

N-COUNT A declaration is an official announcement or statement. 官方声明

例:

The opening speeches sounded more like declarations of war than offerings of peace.

那些开幕辞听起来更像宣战书而不是和平倡议。

N-COUNT A declaration is a firm, emphatic statement which shows that you have no doubts about what you are s***ing. 宣言

例:

...declarations of undying love.

…永恒爱情的宣言。

N-COUNT A declaration is a written statement about something which you have signed and which can be used as evidence in a court of law. 书面声明

例:

On the customs declaration, the sender labelled the freight as agricultural machinery.

在报关单上,发货方将货物列为农业机械。

短语

customs declaration报关单;申报关税

declaration of independence独立宣言

declaration formn. 申报单

declarations的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于declarations翻译、declarations的信息别忘了在本站进行查找喔。

发表评论
0评