是int a; int a(); int a = 0;相同? [英] Are int a; int a(); int a=0; the same?

查看:121
本文介绍了是int a; int a(); int a = 0;相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我想知道以下三个陈述是否相同或只是

后两个是否相同?


int a;

int a();

int a = 0;


谢谢,


Hi,

I''m wondering if the following three statements are the same or only
the last two are the same?

int a;
int a();
int a=0;

Thanks,
Peng

推荐答案

" Pe ******* @ gmail.com" < Pe ******* @ gmail.comwrote:
"Pe*******@gmail.com" <Pe*******@gmail.comwrote:

我想知道以下三个陈述是否相同或只是

最后两个是一样的吗?


int a;

int a();

int a = 0;
I''m wondering if the following three statements are the same or only
the last two are the same?

int a;
int a();
int a=0;



No.这听起来非常像家庭作业/测试问题。问问自己,

第一种情况下a的价值是多少?什么是它的价值

在最后一种情况下?


至于中间行,将函数声明与变量进行比较

定义...

No. This sounds remarkably like a homework/test question. Ask yourself,
what will be the value of ''a'' in the first case? What will be it''s value
in the last case?

As for the middle line, compare a function declaration to a variable
definition...


< Pe ******* @ gmail.comwrote in message

news:fa ********************************** @ a28g2000 hsc.googlegroups.com ...
<Pe*******@gmail.comwrote in message
news:fa**********************************@a28g2000 hsc.googlegroups.com...




我想知道以下三个陈述是否相同或只是

最后两个是一样的吗?


int a;

int a();

int a = 0;
Hi,

I''m wondering if the following three statements are the same or only
the last two are the same?

int a;
int a();
int a=0;



你错过了一个

int a(0);


你展示的三个不同的东西。


第一个宣称a是一个整体的整数。可以包含

任何值。注意,一些编译器会在

调试模式下将变量初始化为0但不会释放模式有时会导致很难找到错误。


第二个声明一个函数叫做接受没有参数和

重新调整整数。


第三个声明一个整数,并将其初始化为零。


第四个也声明一个整数并将其初始化为零。


注意:

int a;

a = 0;


不同于

int a = 0;


第一个案例使用赋值运算符。第二种情况使用

构造函数。

You missed one
int a(0);

The three you show do different things.

The first one declares a as an interger which is unitialized. Can contain
any value. Be careful, some compilers will initialize variables to 0 in
debug mode but not release mode sometimes causing hard to find errors.

The second one declares a function called a accepting no parameters and
retuning an integer.

The third one declares a as in integer and initializes it to zero.

The fourth one also declares a as an integer and initializes it to zero.

Note:
int a;
a = 0;

is different than
int a = 0;

The first case uses the assignment operator. The second case uses the
constructor.


11月18日上午5:03,Jim Langston < tazmas ... @ rocketmail.comwrote:
On Nov 18, 5:03 am, "Jim Langston" <tazmas...@rocketmail.comwrote:

< PengYu ... @ gmail.comwrote in message

news:fa ********************************** @ a28g2000 hsc.googlegroups.com ...
<PengYu...@gmail.comwrote in message
news:fa**********************************@a28g2000 hsc.googlegroups.com...

我想知道以下三个陈述是否相同或只是

后两个是否相同?
I''m wondering if the following three statements are the same or only
the last two are the same?


int a;

int a();

int a = 0;
int a;
int a();
int a=0;


你错过了一个

int a(0);
You missed one
int a(0);


你展示的三个做不同的事情。
The three you show do different things.


第一个声明a为整数的整数。

可以包含任何值。小心,一些编译器会在调试模式下将变量初始化为0而不是释放模式

有时会导致很难找到错误。
The first one declares a as an interger which is unitialized.
Can contain any value. Be careful, some compilers will
initialize variables to 0 in debug mode but not release mode
sometimes causing hard to find errors.



在调试模式下,我会期待像0xdeadbeef这样的东西。


当然,这取决于声明的位置摆放在。如果

它们在命名空间范围内,则第一个为零

初始化。

In debug mode, I''d expect something like 0xdeadbeef.

And of course, it depends where the declarations are placed. If
they are at namespace scope, then the first one is zero
initialized.


第二个声明一个函数,称为接受no

参数并重新调整整数。
The second one declares a function called a accepting no
parameters and retuning an integer.


第三个声明一个整数,并将其初始化为

零。
The third one declares a as in integer and initializes it to
zero.


第四个也声明一个整数并初始化

它为零。
The fourth one also declares a as an integer and initializes
it to zero.


注:

int a;

a = 0;
Note:
int a;
a = 0;


不同于

int a = 0;
is different than
int a = 0;


第一种情况使用赋值运算符。第二种情况

使用构造函数。
The first case uses the assignment operator. The second case
uses the constructor.



如果你将构造函数抛入其中,那么int a(a);和int

a = 0;也有所不同:-)。仍然,第一个是赋值,

和第二个初始化,有些情况下,即使是

int,这也是有区别的:

开关(某物)

{

案例0:

int a = 0; //非法......

休息;


案例1:

int b; //法律......

b = 0;

休息;

}


(如何这是为了增加混乱:-)?)


-

James Kanze(GABI Software)电子邮件:ja ***** **** @ gmail.com

Conseils eninformatiqueorientéeobjet/

Beratung in objektorientierter Datenverarbeitung

9placeSémard,78210 St.- Cyr-l''école,法国,+ 33(0)1 30 23 00 34

If you throw constructors into it, then "int a(a);" and "int
a=0;" are different as well:-). Still, the first is assignment,
and the second initialization, and there are cases, even with
int, where this makes a difference:

switch ( something )
{
case 0 :
int a = 0 ; // Illegal...
break ;

case 1:
int b ; // Legal...
b = 0 ;
break ;
}

(How''s that for adding to the confusion:-)?)

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l''école, France, +33 (0)1 30 23 00 34


这篇关于是int a; int a(); int a = 0;相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆