I've just started with C#. I was reading about operator precedence and there was a part about precedence of unary operator. I've tried to imagine the situation where I can see such stuff. And for example:  int a = 5; a = -a++;   Example is stupid but still... "Unaries" are right-associative. I expected a result of -6 but it's -5. I understand that "++" returns first then increments. But WHAT it increments if not "a"? Why "a" is not affected?  Thanks =]
58615
Have you ever tried this before?  static void Main(string[] args) {     int x = 10;     x = x++;     Console.WriteLine(x); }   Output: 10.  but for   static void Main(string[] args) {     int x = 10;     x++;     Console.WriteLine(x); }   Output: 11.  Could anyone explain why this?
88095
Possible Duplicate:          Sorry if this has already been asked, my searches were fruitless...  There's been a buzz lately about the different results given by two different Casio brand calculators .  It would seem that there's debate on this issue.  The expression is thus:     6 ${\div}$ 2 (1 + 2)   It would appear that the debate is between the scope of the division operator in the equation.  Now, as a software developer, I'm accustomed to well-defined operator precedence.  The compiler knows exactly in what order terms will be evaluated.  Thus, above, the answer is 9.  However, it would appear that the two calculators differ because there's debate about that division operator regarding whether it divides the entire expression or only the first two terms.  Rather, is it:     (6 ${\div}$ 2) (1 + 2)   or is it:     (6) ${\div}$ (2 (1 + 2))   Is there an official answer regarding the operator precedence for mathematics in general, outside the realm of computer programming and compilers?
610
I've always wondered how to write the "A ? B : C" syntax in a C++ compatible language.  I think it works something like: (Pseudo code)  If A &gt; B    C = A Else    C = B   Will any veteran C++ programmer please help me out?
21218
I've been in a lengthy discussion today about how to interpret the division symbol. There seem to be two views on what it means.  • Everything on the left hand symbol is divided by everything on the right hand of the symbol. or  • The operator only deals with the term to its immediate left and right.  Which is correct? I tried to find a specific definition for the usage of the division operator but I couldn't find it.
22388
How do you give a C# auto-property an initial value?  I either use the constructor, or revert to the old syntax.    Using the Constructor:  class Person  {     public Person()     {         Name = "Initial Name";     }     public string Name { get; set; } }   Using normal property syntax  (with an initial value)  private string name = "Initial Name"; public string Name  {     get      {         return name;     }     set     {         name = value;     } }   Is there a better way?
71556
I don't know how to evaluate this expression:  $A-B\cap C$  Is it true that:  $A-(B\cap C)=(A-B)\cap C$  or, in other words, that the associative property applies to these operations?
35871
How does Python evaluate the expression 1+++2?  How many ever + I put in between, it is printing 3 as the answer. Please can anyone explain this behavior  And for 1--2 it is printing 3 and for 1---2 it is printing -1
24110
Why subtraction of a negative number from a positive number is addition? Eg: $a - (-b) = a + b$ When looking through the number scale I am unable to relate this, please kindly clarify ?
82347
Okay, I'm aware that the standard dictates that a C++ implementation may choose in which order arguments of a function are evaluated, but are there any implementations that actually 'take advantage' of this in a scenario where it would actually affect the program?  Classic Example:  int i = 0; foo(i++, i++);   Note: I'm not looking for someone to tell me that the order of evaluation can't be relied on, I'm well aware of that. I'm only interested in whether any compilers actually do evaluate out of a left-to-right order because my guess would be that if they did lots of poorly written code would break (rightly so, but they would still probably complain).
56687
I am trying to understand how the logical operator precedence works in bash. For example, I would have expected, that the following command does not echo anything.  true || echo aaa &amp;&amp; echo bbb   However, contrary to my expectation, bbb gets printed.   Can somebody please explain, how can I make sense of compounded &amp;&amp; and || operators in bash?
88330
I've seen some people using void operator in their code. I have also seen this in href attributes: javascript:void(0) which doesn't seem any better than javascript:;  So, what is the justification of using the void operator?
82090
int i = 4; string text = "Player "; cout &lt;&lt; (text + i);   I'd like it to print Player 4.  The above is obviously wrong but it shows what I'm trying to do here. Is there an easy way to do this or do I have to start adding new includes?
33264
Why is operator '&amp;' defined for bool?, and operator '&amp;&amp;' is not?  How exactly does this 1) bool? &amp; bool? and 2) bool? and bool work?   Any other "interesting" operator semantics on Nullable? Any overloaded operators for generic T?
3552
According to the documentation of the == operator in ,      For predefined value types, the   equality operator (==) returns true if   the values of its operands are equal,   false otherwise. For reference types   other than string, == returns true if   its two operands refer to the same   object. For the string type, ==   compares the values of the strings.   User-defined value types can overload   the == operator (see operator). So can   user-defined reference types, although   by default == behaves as described   above for both predefined and   user-defined reference types.   So why does this code snippet fail to compile?  bool Compare&lt;T&gt;(T x, T y) { return x == y; }   I get the error Operator '==' cannot be applied to operands of type 'T' and 'T'. I wonder why, since as far as I understand the == operator is predefined for all types?  Edit: Thanks, everybody. I didn't notice at first that the statement was about reference types only. I also thought that bit-by-bit comparison is provided for all value types, which I now know is not correct.  But, in case I'm using a reference type, would the == operator use the predefined reference comparison, or would it use the overloaded version of the operator if a type defined one?  Edit 2: Through trial and error, we learned that the == operator will use the predefined reference comparison when using an unrestricted generic type. Actually, the compiler will use the best method it can find for the restricted type argument, but will look no further. For example, the code below will always print true, even when Test.test&lt;B&gt;(new B(), new B()) is called:  class A { public static bool operator==(A x, A y) { return true; } } class B : A { public static bool operator==(B x, B y) { return false; } } class Test { void test&lt;T&gt;(T a, T b) where T : A { Console.WriteLine(a == b); } }
51259
I am trying to understand the intuition behind .  Why it is called exclusive or? Wikipedia says: it gains the name "exclusive or" because the meaning of "or" is ambiguous when both operands are true  Wait! why "or" is ambiguous when both operands are true?  says nothing about ambiguation.
99786
I don't have any intuition for this because it's just something I memorized. I only understand that $|a| = a$ if $a$ is already positive (or $0$), and $|a| = -a$ if $a$ is negative since we want to turn it positive ($-(-a)$). So does that mean we will have a piecewise inequality also?  But how do we get absolute value from $-b &lt; a &lt; b$?
21013
Most properties of a single binary operation can be easily read of from the operation's table. For example, given $$\begin{array}{c|ccccc} \cdot &amp; a &amp; b &amp; c &amp; d &amp; e\\\hline a     &amp; e &amp; d &amp; b &amp; a &amp; c\\ b     &amp; d &amp; c &amp; e &amp; b &amp; a\\ c     &amp; b &amp; e &amp; a &amp; c &amp; d\\ d     &amp; a &amp; b &amp; c &amp; d &amp; e\\ e     &amp; c &amp; a &amp; d &amp; e &amp; b \end{array}$$ it is easy to check that it is closed (no elements occur in the table which don't occur as row or column index), commutative (the table is symmetric), has a neutral element (the row and column of $d$ are copies of the index row/column), and has an inverse element for each element (there's a $d$ in each row and column). In other words, almost all important properties can immediately be seen. The only part missing is associativity.  Therefore my question: Is there a simple way to see directly from the operation's table (i.e. without doing explicitly all the calculations) if an operation is associative?