unary-operator

What does the unary plus operator do?

What does the unary plus operator do? There are several definitions that I have found (here and here) but I still have no idea what it would be used for. It seems like it doesn't do anything but there has be a reason for it, right? ...

Usefullness of the unary plus operator

Duplicate What does the unary plus operator do? Is there any good use for the unary plus operator? For numbers it does nothing. I suppose you could overload it for custom types, but that would be non-standard operator behaviour (bad). It also makes parsing code somewhat harder. So, are there any cases where it makes sense to overl...

C# Compiler Behavior Question?

Hey everyone, in the following code, what should the result of d be after the second expression? int d = 1; d += d++; One would assume d is 3 afterwards but the unary increment d++ doesn't seem to take effect and d retains a value of 2. Is there a name for this bug? Does it exist for other compilers that support unary increment...

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

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 under...

Unary operator result

In K&R ANSI C book, section A.7.4.5 (Unary Minus Operator) it is stated: ... The negative of an unsigned quantity is computed by subtracting the promoted value from the largest value of the promoted type and adding one; ... How exactly is this calculated? Could you give a short C example? I don't see how this could yield the negati...

unary pointer increment in function call vs increment before/after function call

I am trying to understand a code, here is fragment which is causing confusion: typedef map<int, Person, less<int> > people_map; people_map people; . . . cout << "Erasing people of age 100" << endl; for (people_map::iterator j = people.begin(); j != people.end();) { if (j->second.GetAge() == 100) { peopl...

bash : Multiple Unary operators in if statement

hello, 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 Thanks Kiran ...

What is the purpose of Java's unary plus operator?

Java's unary plus operator appears to have come over from C, via C++. As near as I can tell, it has the following effects: unboxes its operand, if it's a wrapper object promotes its operand to int, if it's not already an int or wider complicates slightly the parsing of evil expressions containing large numbers of consecutive plus signs...

What is the difference between += and =+?

What is the difference between += and =+? Specifically, in java, but in general also. ...

Prefix form of unary operator in Haskell

In GHCi: Prelude> (+3) 2 5 Prelude> (*3) 2 6 Prelude> (/3) 2 0.6666666666666666 Prelude> (-3) 2 No instance for (Num (t -> t1)) arising from the literal 3' at <interactive>:1:2 Possible fix: add an instance declaration for (Num (t -> t1)) In the expression: 3 In the expression: (- 3) 2 In the definit...

++someVariable Vs. someVariable++ in Javascript

In Javascript you can use ++ operator before or after the variable name. What, if any, are the differences between these ways of incrementing a variable? ...

Input Puzzler in C

Possible Duplicate: Could anyone explain these undefined behaviors (i = i++ + ++i , i = i++, etc) int main() { int a=5,s; s=++a + ++a; printf("%d",a); printf("%d",s); } output is 7 and 14 BUT int main() { int a, s; printf("Enter value of a"); scanf ("%d",&a); s=++a + ++a; printf("%d",a); printf("%d",s); } input user give...

Scala - Prefix Unary Operators

I've recently given Scala a second chance, and started with the project I always implement (in functional or pseudo-functional languages): an automated reasoner for propositional logic (and later predicate logic). Now, I've tried to get the notation of propositional logic in the language itself as pretty as possible, and I've gotten thi...

operator overloading in c++ ( with and without friend )

Hey, I would like to know the difference between these 2 operator definitions: 1: class Rational{ //... public: //... Rational operator -() const{ return Rational(-t,b);} //... }; 2: class Rational{ //... public: //... friend Rational operator -(const Rational& v) {return Rational(-t,b);} //... }; as far as i understand, for the u...

Unary Operator-() on zero values - c++

I wrote this code to overload the unary operator- on a matrix class: const RegMatrix RegMatrix::operator-()const{ RegMatrix result(numRow,numCol); int i,j; for(i=0;i<numRow;++i) for(j=0;j<numCol;++j){ result.setElement(i,j,(-_matrix[i][j])); } return result; } When i ran my program with...