English 中文(简体)
因此,您知道操作者在++中的优先地位? [闭门]
原标题:So you think you know the priority of operators in c++? [closed]

我只读了一部法典,它不仅汇编了,而且带来了预期结果(X是分类值):

int y = (int)(0.5 * x * x + + + 0.6 * x + 1.2);

我只想说什么发生,我必须说这是一个有趣的经营者问题。 如果不汇编该方案,以下业务的结果是什么?

int a = 1;
int b = 2;
int z = a + + + b;
int z1 = a + - + b;
int z2 = a + - - b;
int z3 = a - - + b;
int z4 = a - - - b;
int z5 = a +- b;

我仍然有一个问题,尽管:标准是否提供这种结果,还是具体汇编?


Explanation: Because the + and - operators have spaces between them, the "+ + +" sequence is not compiled as "++ +", but as unary operators on the right member. So

int y = (int)(0.5 * x * x + + + 0.6 * x + 1.2);

实际:

int y = (int)(0.5 * x * x + 0.6 * x + 1.2);

这是预期的结果。

因此,

z  = a + + + b = a + + (+b) = a + (+b) = a + b = 3;
z1 = a + - + b = a + - (+b) = a + (-b) = a - b = -1;
z2 = a + - - b = a + - (-b) = a + (+b) = a + b = 3;
z3 = a - - + b = a - - (+b) = a - (-b) = a + b = 3;
z4 = a - - - b = a - - (-b) = a - (+b) = a - b = -1;
z5 = a +- b = a + (-b) = a - b = -1;
最佳回答

z = 3
z1 = -1
z2 = 3
z4 = 3
z5 = -1

Without compiling, i d say it s a simple math operator combining
I ve learned it with this phrase (translated from Brazilian portuguese):

Different signs = subtract
Equal signs = add

So

int z = a + + + b; //  +  +  +  =  +  , the resulting  +  +  +  = + again.
int z1 = a + - + b; //  +  +  -  =  -  , the resulting  -  +  +  = - again.
int z2 = a + - - b; //  +  +  -  =  -  , the resulting  -  +  -  = +.
int z3 = a - - + b; //  -  +  -  =  +  , the resulting  +  +  +  = + again.
int z4 = a - - - b; //  -  +  -  =  +  , the resulting  +  +  -  = -.
int z5 = a +- b; //simple "different signals = subtract" :)
问题回答

回答标题中提出的问题:

So you think you know the priority of operators in c++?

我认为,没有人会这样做,更重要的是,我无意学习。 在读书时,每当文件没有保证时,我将使用括号。 我需要记住更多的重要事情。

为了回答你的问题,答案并不具体。 它既未界定实施,也未界定明确的行为。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签