I'm wondering if someone can help explain why the following code snippet returns a and b both equal to 6.   int main(){     int a =5, b;     a++,b=a;      printf("%d %d\n", a, b); }   Is the answer that, in fact, the behaviour is implementation-specific (based on compiler)? Or, is the following the explanation (my understanding of postfix is that the incrementing only happens after the variable a has been "used" by whatever other operator exists around it). In this case, is the a "used" by the comma operator when the LHS is evaluated and then thrown away, such that incrementing happens before the RHS is evaluated?  Thanks in advance!
1679
What does the , operator do in C?
66005
In C#, does anybody know why the following will compile:  int i = 1; ++i; i++;   but this will not compile?  int i = 1; ++i++;   (Compiler error: The operand of an increment or decrement operator must be a variable, property or indexer.)
113560
I expected A::~A() to be called in this program, but it isn't:  #include &lt;iostream&gt;  struct A {   ~A() { std::cout &lt;&lt; "~A()" &lt;&lt; std::endl; } };  void f() {   A a;   throw "spam"; }  int main() { f(); }   However, if I change last line to   int main() try { f(); } catch (...) { throw; }   then A::~A() is called.  I am compiling with "Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86" from Visual Studio 2005. Command line is cl /EHa my.cpp.  Is compiler right as usual? What does standard say on this matter?
68466
I have a very simple question. When I do this:  \catcode`\@=0 \catcode`\\=11 @mycommand{a} @catcode`@\=0 \catcode`\@=11   It works perfectly and calls \mycommand correctly. However, when I try to define \mycommand with similar trickery:  \newcommand\mycommand[1]{   \catcode`\@=0   \catcode`\\=11   @textbf{Hello #1}   @catcode`@\=0   \catcode`\@=11 }   compilation stalls and gives me the * prompt. If I give it Ctrl+D, it terminates without producing any output. Indeed, it seems that changing the catcodes inside a command has no effect whatsoever, because the following works perfectly (whereas, from my understanding, it shouldn't):  \newcommand\mycommand[1]{   \catcode`\@=0   \catcode`\\=11   \textbf{Hello #1} }   Can anybody please explain to me what's happening?
52567
When is it appropriate to use an unsigned variable over a signed one? What about in a for loop?  I hear a lot of opinions about this and I wanted to see if there was anything resembling a consensus.   for (unsigned int i = 0; i &lt; someThing.length(); i++) {       SomeThing var = someThing.at(i);       // You get the idea.   }   I know Java doesn't have unsigned values, and that must have been a concious decision on ' part.
111701
I'm messing around with some C code using floats, and I'm getting 1.#INF00, -1.#IND00 and -1.#IND when I try to print floats in the screen. What does those values mean?  I believe that 1.#INF00 means positive infinity, but what about -1.#IND00 and -1.#IND? I also saw sometimes this value: 1.$NaN which is Not a Number, but what causes those strange values and how can those help me with debugging?  I'm using  which I believe uses  representation for float point numbers.  Can someone list all those invalid values and what they mean?
99037
I see this from time to time and want to know what it is. I did try google, but its filtering out the characters from the search. I have a few books that don't reference it either.   FWIW, I remember in pascal that is was the assignment operator.   Can anybody point me to the MSDN or similar page?
73942
Can someone explain to me how XOR swapping of two variables with no temp variable works?  void xorSwap (int *x, int *y) {     if (x != y) {         *x ^= *y;         *y ^= *x;         *x ^= *y;     } }   I understand WHAT it does, but can someone walk me through the logic of how it works?
81621
If I write the following class:  public class Example {        int j;       int k;        public Example(int j, int k) {            j = j;            k = k;       }        public static void main(String[] args) {            Example exm = new Example(1,2);            System.out.println(exm.j);            System.out.println(exm.k);       }  }   The program compiles, but when I run the program, the main method will print out two 0s. I know that in order to say that I want to initialize the instance variables in the constructor I have to write:  this.j = j; this.k = k;   But if I don't write it, then which variable is evaluated (or considered) in the constructor (on the left and on the write hand side of the expressions)? Is is the argument or the instance variable? Does it make a difference?  Are there other cases where the use of this is obligatory?
87194
I've been told that code such as:  for (int i = 0; i &lt; x.length(); i++) {     // blah }   is actually O(n^2) because of the repeated calls to x.length(). Instead I should use:  int l = x.length(); for (int i = 0; i &lt; l; i++) {     // blah }   Is this true? Is string length stored as a private integer attribute of the String class? Or does String.length() really walk the whole string just to determine its length?
89137
What would be better practice when giving a function the original variable to work with:  unsigned long x = 4;  void func1(unsigned long&amp; val) {      val = 5;             } func1(x);   or:  void func2(unsigned long* val) {      *val = 5; } func2(&amp;x);   IOW: Is there any reason to pick one over another?
25759
I have encountered comparisions of variables to string literals multiple times over the years which had one character prefixing the variable and the literal, e.g.  if [ "x$A" = "xtrue" ]; then   in order to check whether $A is "true".  I assume this is done to achieve shell compatibility or to work around a longterm bug, an unintuitive behavior, etc. Nothing obvious comes to mind.  Today I figured I want to know the reason, but my research didn't turn up anything. Or maybe it's just me making something out of a rather frequent exposure to rare occurances.  Is this practice still useful, maybe even best?
13470
I am a little surprised by the following.  Example 1:  char s[100] = "abcd"; // declare and initialize - WORKS   Example 2:  char s[100]; // declare s = "hello"; // initalize - DOESN'T WORK ('lvalue required' error)   I'm wondering why the second approach doesn't work. It seems natural that it should (it works with other data types)? Could someone explain me the logic behind this?
71596
expr does not seem to like parenthesis (used in mathematics to explicit operator priority):  expr 3 * (2 + 1) bash: syntax error near unexpected token `('   How to express operator priority in bash?
75336
Someone told me it's more efficient to use StringBuffer to concatenate strings in Java than to use the + operator for Strings. What happens under the hood when you do that? What does StringBuffer do differently?
58577
I have this simple test: double h; ... // code that assigns h its initial value, used below ... if ((h&gt;0) &amp;&amp; (h&lt;1)){  //branch 1 -some computations } else{  //branch 2- no computations }  I listed my values as I got some really strange results and for example if: h=1 then the first branch is reached and I do not understand why since if h=1 I want branch2 to be computed. Am I getting confused by something so obvious?  Edit: This is how I compute and then use h: double* QSweep::findIntersection(edge_t edge1,edge_t edge2) {   point_t p1=myPoints_[edge1[0]]; point_t p2=myPoints_[edge1[1]]; point_t p3=myPoints_[edge2[0]]; point_t p4=myPoints_[edge2[1]];  double xD1,yD1,xD2,yD2,xD3,yD3,xP,yP,h,denom; double* pt=new double[3];          // calculate differences   xD1=p2[0]-p1[0];   xD2=p4[0]-p3[0];   yD1=p2[1]-p1[1];   yD2=p4[1]-p3[1];   xD3=p1[0]-p3[0];   yD3=p1[1]-p3[1];      xP=-yD1; yP=xD1; denom=xD2*(-yD1)+yD2*xD1; if (denom==0) {     return NULL; } else{ h=(xD3*(-yD1)+yD3*xD1)/denom; } std::cout&lt;&lt;&quot;h is&quot;&lt;&lt;h&lt;&lt;endl; if (h &lt; 1) std::cout&lt;&lt;&quot;no&quot;&lt;&lt;endl; else std::cout&lt;&lt;&quot;yes&quot;&lt;&lt;endl; if (h==1) {     return NULL; } else{ if ((h&gt;0)&amp;&amp;(h&lt;1)){     pt[0]=p3[0]+xD2*h;       pt[1]=p3[1]+yD2*h;     pt[2]=0.00; } else{     return NULL; } }   return pt;    }  Edit: Okay, so it is clear how I should reformulate the condition. From: double h; if (h==1){    //computations here }  To: double h; if (abs(h-1)&lt;tolerance){   //computations here }  When I use double numbers. But how do I reformulate this? double h; if (h&lt;1){    //computations here }
67728
Is there any way of doing parallel assignment in C++? Currently, the below compiles (with warnings)  #include &lt;iostream&gt;   int main() {    int a = 4;   int b = 5;   a, b = b, a;   std::cout &lt;&lt; "a: " &lt;&lt; a &lt;&lt; endl             &lt;&lt; "b: " &lt;&lt; b &lt;&lt; endl;    return 0; }   and prints:  a: 4 b: 5   What I'd like it to print ... if it weren't obvious, is:  a: 5 b: 4   As in, say, ruby, or python.