int(a)vs(int)a [英] int(a) vs (int)a

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

问题描述

嗯......


有时我会看到如下代码:

int a = int(13.5 + 17.2);

我用来写:

int a =(int)(13.5 + 17.2);


有什么区别?


-

-Gernot

int main(int argc,char ** argv){printf

(%silto%c%cf%cgl%ssic%ccom%c,ma,58,g,64,ba,46,10);}
< br $>
________________________________________

寻找一款好游戏?亲自动手吧!

GLBasic - 你可以这样做
www.GLBasic .com

Hmm...

sometime I see code like:
int a = int(13.5+17.2);

I use to write:
int a = (int)(13.5+17.2);

is there any difference?

--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, ''g'', 64, "ba", 46, 10);}

________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com

推荐答案

Gernot Frisch写道:
Gernot Frisch wrote:
嗯...
有时候我看到的代码如下:
int a = int(13.5 + 17.2);

我用来写:
int a =(int)(13.5 + 17.2);

有什么不同吗?
Hmm...

sometime I see code like:
int a = int(13.5+17.2);

I use to write:
int a = (int)(13.5+17.2);

is there any difference?




基本没什么区别。


int(x) - 是构造语法。


(int)(x) - 是(C like)类型转换语法,它可能应该给'

方式; static_cast< int>(x)"语法。



Essentially no difference.

int( x ) - is the construction syntax.

(int)( x ) - is the (C like) type-cast syntax which should probably give
way to the "static_cast<int>( x )" syntax.


>嗯...

有时我看到的代码如下:
int a = int(13.5 + 17.2);


在这种情况下,你取加法的整数部分:

13,5 + 17,2 = 30,7,结果可以是31或30.

我用来写:
int a =(int)(13.5 + 17.2);


但是在这种情况下,你修改了你在parenthèse中拥有的东西。如果您在=>中有

文字()和(int)在它前面,它用ASCII表转换你的文本数字

。所以在我看来,当你已经在=>中有数字时,没有理由做

(int)(13.5 + 17.2) ()。


我希望我的解释是可以理解的。稍后再见;)

有什么区别吗?

-Gernot
int main(int argc,char ** argv){ printf
(%silto%c%cf%cgl%ssic%ccom%c,ma,58,g,64,ba,46,10);}

________________________________________
寻找好游戏?亲自动手吧!
GLBasic - 你可以做
www.GLBasic.com



2005年6月1日星期三08:23:31 +0200,Robert ^^ < mo*@moi.com>写道:

comp.lang.c ++:
On Wed, 1 Jun 2005 08:23:31 +0200, "Robert ^^" <mo*@moi.com> wrote in
comp.lang.c++:
嗯...

有时我看代码如下:
int a = int(13.5 + 17.2);

在这种情况下,你取加法的整数部分,所以在这种情况下:
13,5 + 17,2 = 30,7,结果可以是31或30.
Hmm...

sometime I see code like:
int a = int(13.5+17.2);

In this case, you take the integer part of your addition so in this case :
13,5 + 17,2 = 30,7, the result can be 31 or 30.




你对C ++中的转换有什么了解吗?当30.7被转换为任何整数类型时,结果不能是
除了30之外的其他任何东西。



Do you know anything about conversions in C++? The result cannot be
anything other than 30 when 30.7 is converted to any integer type.

我用来写:
int a =(int)(13.5 + 17.2);
I use to write:
int a = (int)(13.5+17.2);



但在这种情况下,您可以修改parenthèse中的内容。当你在=>中有
文字时()和(int)在它前面,它用ASCII表转换你的文本数字
。所以在我看来,当你已经在=>中有数字时,没有理由做
(int)(13.5 + 17.2) ()。



But in this case, you modify what you have in the parenthèse. When you have
text in the => ( ), and (int) in front of, it transform your text in numeric
with the ASCII table. So in my opinion there are no reasons to do
(int)(13.5+17.2) when you already have number in the => ( ).




你对C ++中的运算符和强制类型有什么了解吗?这个

表达式将两个双精度值12.5和17.2相加,以产生

双精度值30.7。括号外的演员对评估其中的表达式绝对没有任何影响。演员

导致这个双倍值转换为int,降低分数

再次结果必须为30.

我希望我的解释是可以理解的。稍后再见;)


我建议你在回答问题之前先学习一些关于C ++的知识

这里。



Do you know anything about operators and casts in C++? This
expression adds the two double values 12.5 and 17.2 to produce the
double value 30.7. The cast outside the parentheses has absolutely no
effect on the evaluation of the expression inside them. The cast
causes this double value to be converted to int, dropping the fraction
and again the result must be 30.
I hope my explications are understandable. See you later ;)
I suggest you learn a little more about C++ before answering questions
here.

有什么不同吗?




-

Jack Klein

主页: http://JK-Technology.Com



comp.lang.c http:/ /www.eskimo.com/~scs/C-faq/top.html

comp.lang.c ++ http://www.parashift.com/c++-faq-lite/

alt.comp.lang .learn.c-c ++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html



--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html


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

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