unary-operator

In Java, is a++ a postfix operator or an unary operator?

点点圈 提交于 2020-05-17 07:25:12
问题 In Java, is a++ a postfix operator or an unary operator? In the Operator Precedence from Oracle, it is separated. Reference 回答1: It’s both. It’s a unary operator because it works solely on one term. If it’s x++ then it’s a postfix operator as it’s incremented after using the variable’s value. A prefix unary operator is ++x where it’s incremented before being used. Prefix operators have a higher precedence, but they’re both unary operators 来源: https://stackoverflow.com/questions/60014618/in

C: unary minus operator behavior with unsigned operands

落花浮王杯 提交于 2020-01-18 04:29:44
问题 I can't seem to find the relevant parts in the C standard fully defining the behavior of the unary minus operator with unsigned operands. The 2003 C++ standard (yes, C++, bear with me for a few lines) says in 5.3.1c7: The negative of an unsigned quantity is computed by subtracting its value from 2^n, where n is the number of bits in the promoted operand. The 1999 C standard, however, doesn't include such an explicit statement and does not clearly define the unary - behavior neither in 6.5.3

Difference of Unary operators ( += , =+ , ++x , x++ )

我只是一个虾纸丫 提交于 2020-01-11 06:21:15
问题 What is the difference between these unary operators in C# ? . Can you provide me with example? Please provide the name of each. :) += vs =+ ++x vs x++ 回答1: This has no doubt been answered before, but anyway... They differ in how they change the value and how they return the result. The first two += and =+ behave in the way that the first increments a variable, the other sets a variable. They are not related. Observe the following code: // += x = 1; printf( x += 1 ); // outputs 2, the same as

Expression evaluation in C++ involving unary operators [duplicate]

依然范特西╮ 提交于 2020-01-07 08:07:25
问题 This question already has answers here : Undefined behavior and sequence points (5 answers) Why are these constructs using pre and post-increment undefined behavior? (14 answers) Closed 5 years ago . Why does not C/C++ evaluates expression in order of left to right in these cases: Initially x=1 Evaluating x + ++x gives 4. If normal evaluation is carried out (precedence of ++ is higher than +) then the result should be 1 + 2 = 3 Similarly: x + ++x + x gives 6 x + x + ++x gives 4 Why are

c++ only: unary minus for 0x80000000

限于喜欢 提交于 2019-12-31 02:44:06
问题 This question is supposedly for language-lawyers. Suppose that signed and unsigned int are both 32 bits wide. As stated in the n3337.pdf draft, 5.3.1.8, (-(0x80000000u)) = 0x100000000u-0x80000000u = 0x80000000u But I can not find the answer to the question: what will be unary minus for signed 0x80000000? Is it UB, implementation defined, or ... ? The question is mostly about run-time calculation. Say signed int my_minus(signed int i) { return -i;} .... int main() { signed int a = -0x7FFFFFFF;

Unary operators in java vs c++ [duplicate]

删除回忆录丶 提交于 2019-12-24 13:07:42
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Could anyone explain these undefined behaviors (i = i++ + ++i , i = i++, etc…) Is there any difference between the Java and C++ operators? Why unary operators give different result in c++ and java? Check this out: int i = 1; i = i++ + ++i; print i (with cout or println) In java : prints 4 In c++ : prints 5 Why ? 回答1: In C++ the behavior of a statement such as i = i++ + ++i; is actually undefined so the fact that

Why can't I have a literal list slice right after a print in Perl?

折月煮酒 提交于 2019-12-23 19:12:29
问题 I see I can do something like this: print STDOUT (split /\./, 'www.stackoverflow.com')[1]; and "stackoverflow" is printed. However, this: print +(split /\./, 'www.stackoverflow.com')[1]; does the same, and this: print (split /\./, 'www.stackoverflow.com')[1]; is a syntax error. So what exactly is going on here? I've always understood the unary plus sign to do nothing whatsoever in any context. And if "print FILEHANDLE EXPR" works, I would have imagined that "print EXPR" would always work

unary minus for 0x80000000 (signed and unsigned)

怎甘沉沦 提交于 2019-12-22 18:26:21
问题 The n3337.pdf draft, 5.3.1.8, states that: The operand of the unary - operator shall have arithmetic or unscoped enumeration type and the result is the negation of its operand. Integral promotion is performed on integral or enumeration operands. The negative of an unsigned quantity is computed by subtracting its value from 2ⁿ, where n is the number of bits in the promoted operand. The type of the result is the type of the promoted operand. For some cases it is enough. Suppose unsigned int is

Multiple unary operators in an if statement [duplicate]

試著忘記壹切 提交于 2019-12-22 04:21:34
问题 This question already has an answer here : Using the && operator in an if statement (1 answer) Closed 9 months ago . Is it possible to have multiple unary operators in if statements.. Here is the code snippet which is giving me error. Please correct the code here. if [ -f $input_file ] -a [ -f $output_file ] -a [ -f $log_file ] ] then ### Some Code here fi 回答1: if [ -f "file1" -a -f "file2" -a "file3" ]; then #some code fi 回答2: If you use Bash's double-bracket, you can do this: if [[ -f "