I am trying to solve this enigma:  int direction = 1; char direction_name = direction["nsew"];   Like why does it compile on a first place, what exactly is it trying to prove and what is it used for ?    I spotted this code in a site with no relevant explanation other than "[] is symmetric". I mean what am I supposed to do with this information..
4478
As Joel points out in , in  (aka: K &amp; R), there is mention of this property of arrays in C: a[5] == 5[a]  Joel says that it's because of pointer arithmetic but I still don't understand. Why does a[5] == 5[a]?
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?
5812
Why does the  exist in modern languages such as C# and Java? Is it purely a self documenting code feature, or does it serve any actual purpose?  For instance the following example:  Class1 obj = new Class1();  Class1 foo() {     return new Class1(); }   Is as easy to read as the more Pythonesque way of writing it:  Class1 obj = Class1();  Class1 foo() {     return Class1(); }   EDIT:  hit the nail on the head with the clarification of the question: Why did they choose this syntax?
101584
I'm trying to solve  and I have a for loop that looks like this:   for(int i = low; i &lt;= high; ++i)         {                 res = runalg(i);                 if (res &gt; highestres)                 {                         highestres = res;                 }          }   Unfortunately I'm getting this error when I try to compile with GCC:     3np1.c:15: error: 'for' loop initial   declaration used outside C99 mode   I don't know what C99 mode is. Any ideas?
1730
I'm working in C, and I have to concatenate a few things.  Right now I have this:  message = strcat("TEXT ", var);  message2 = strcat(strcat("TEXT ", foo), strcat(" TEXT ", bar));   Now if you have experience in C I'm sure you realize that this gives you a segmentation fault when you try to run it. So how do I work around that?
4650
I was looking at an exercise where it asked the following:  $$\begin{array}{ccc} p&amp;q&amp;p\rightarrow q \\ T&amp;T&amp;T \\ &amp;\ldots \end{array}$$  So, for the third column, I just put $T$ which was correct but I didn't understand what $\rightarrow$ meant. I have seen $\implies$ but I haven't the arrow. Are they the same thing?  Thanks a bunch!
57835
says:  If the index number is @ or *, all members of an array are referenced.  When I do this: LIST=(1 2 3) for i in &quot;${LIST[@]}&quot;; do   echo &quot;example.$i&quot; done  it gives the desired result: example.1 example.2 example.3  But when I use ${LIST[*]}, I get example.1 2 3  instead. Why? Edit: when using printf, @ and * actually do give the same results.
88627
Possible Duplicate:          I'm learning C++ at the moment, and I'm coming across a lot of null-terminated strings. This has got me thinking, what makes more sense when declaring pointers:  char* string   or  char *string   ? To me, the char* format makes more sense, because the type of "string" is a pointer to a char, rather than a char. However, I generally see the latter format. This applies to references as well, obviously.  Could someone tell me if there is a logical reason for the latter format?
109023
When I was looking at someone's Verilog code, I found "+:" in Verilog. It looks like an arithmetic function but I'm not sure. I never seen before. Does anyone know this usage?  Update:  csum= csum + one_cnt[i* ('DPC_shift +1) +: ('DPC_shift +1)];   I have a query, is this synthesiable?
109558
Are these two equivalent?  char * aString = "This is a string.";  char aString[] = "This is a string.";  From my understanding, C++ stores strings by their addresses, so the pointer is getting a valid address. I assume the strings are also stored as type char? But how does it know how much memory to allocate for the string? Normally, char arrays need their array size preset. I believe the [] type arrays are counted by the compiler before compilation. Is this what happens for the string literal pointer as well?  On to my second question, what is the difference between these two:  int someNumber;  int * someNumber = new int;  The second is supposed to be dynamic allocation. If I understand the concept right, it allocates the memory as soon as it reads the declaration. But what happens in the standard declaration? Basically, I need to understand how dynamic allocation is advantageous over standard declarations.
12352
I just came onto a project with a pretty huge code base.   I'm mostly dealing with C++ and a lot of the code they write uses double negation for their boolean logic.    if (!!variable &amp;&amp; (!!api.lookup("some-string"))) {        do_some_stuff();  }                                      I know these guys are intelligent programmers, it's obvious they aren't doing this by accident.   I'm no seasoned C++ expert, my only guess at why they are doing this is that they want to make absolutely positive that the value being evaluated is the actual boolean representation. So they negate it, then negate that again to get it back to its actual boolean value.   Is this correct, or am I missing something?
110687
Vec2 a, b; // some random vector Vec2 cross = a.Cross(b); RelativeDirection(a,b,cross); // return true if the direction of                               // rotating a to b is counter-clockwise   How do I implement the function RelativeDirection()?  I got some suedo code from the textbook:  if a.Cross(b) &gt; 0 then ... else ...   but the cross product is a vector right? how do you compare it with an integer?
64302
I frequently find myself writing code like this:  List&lt;int&gt; list = new List&lt;int&gt; { 1, 3, 5 }; foreach (int i in list) {     Console.Write("{0}\t", i.ToString()); } Console.WriteLine();   Better would be something like this:  List&lt;int&gt; list = new List&lt;int&gt; { 1, 3, 5 }; Console.WriteLine("{0}\t", list);   I suspect there's some clever way of doing this, but I don't see it. Does anybody have a better solution than the first block?
115381
I'm trying to write this:  \begin{nscenter}         % $G(\psi,\chi) =          \         % \begin{cases}         % \begin{enumerate}[\rm(i)]         % \item q-1 \ se \ \psi=\psi_0 \ e \ \chi=\chi_0 \\         % \item -1 \ se \ \psi=\psi_0 \ e \ \chi \neq \chi_0 \\          % \item 0 \ se \psi \neq \psi_0 \ e \ \chi=\chi_0 \\          $ \item Se \ \chi \neq \chi_0 \ e \ \psi \neq \psi_0 \Rightarrow  $ |G(\psi,\chi)|=\sqrt{q}          $ \end{enumerate}          $ \end{cases}$      %\end{nscenter}   But the compiler of the error and I do not know what to do to remove the error
11288
I was reading Ivor Horton's Beginning Visual C++ 2008 and many of its CLR examples have this definition for main:  int main(array&lt;System::String ^&gt; ^args)   I went back, page by page, to the beginning of the book to find the first such instance with an explanation what it really means, but couldn't find one.  Obviously it means the same as the standard int main(int argc, char *argv[]), but I'd like to know when and why that ^ is really used, and why it even exists (does it do something that pointers * and references &amp; cannot represent)?
114020
Second Update: I see that some answers that reference my image are more closely answering my question. Here is a second image to clarify my point.  Take this image representing a checkerboard like configuration.  If I asked you to move the X negative 1 space it would be impossible.  You would have to make a guess as to which direction is negative. However, I can ask you to move the X 1 space/unit, since moving to any square from the center would satisfy moving 1 space/unit.  But wait!  Once you complete moving the X 1 space/unit; I could now follow up and request you move negative 1 space, since you have now already travelled in one direction. Now you are able to negate the original request by 1 space/unit  Therefore negative doesn't exists until you have already begun moving in some direction/unit/space/time/apples.      update   Maybe this helps illustrate my point.  In this image there is a line, going either direction will take you to infinity (A or B),  the number of spaces you move is always a positive number. If I moved 20 widgets closer to infinity A. or I moved 20 widgets closer to infinity B.  So, negative numbers don't exist and are only positive numbers that are increasing in the opposite direction  Negative indicates the direction of travel on a line.  the measure of movements will always be positive.  Does a negative number really exist?  I can't have -1 apples.  I can only imagine I had an apple when I really did not.  Thus, in reality I would have -1 apple as compared to my imagination.  didn't know how to tag this
96218
I came across this code and wanted others to provide their point of view... is it good or bad ? ;)  Class ReportClass {  public string ReportName {get; set;} }   Then it was used as follows in code:  displayReport(ReportClass.ReportName = cmbReportName.SelectedValue.ToString())   That is about the simplest form example I can give you. Quetion is... why can't I find examples ? What would this be called? Is this just asking for trouble?  EDIT: I'm referring to the inplace assignment. Which I wasn't aware of until today