When I was writing a program, I made a typo. I have wrote i[data] instead data[i]. However the program was successful compiled and worked right. Operator[] behavior with arrays: #include &lt;iostream&gt;  using namespace std;  int main() {   int data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};      cout &lt;&lt; data[6] &lt;&lt; endl; // prints 6   cout &lt;&lt; 6[data]; // prints 6   return 0; }  Similar operator[] behavior with pointers: #include &lt;iostream&gt;  using namespace std;  int main() {   char* str = &quot;Hello, world!&quot;;      cout &lt;&lt; str[9] &lt;&lt; endl; //prints 'r'   cout &lt;&lt; 9[str]; //prints 'r'   return 0; }  Why data[i] equals i[data]?
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]?
40034
Coming from C++ to Java, the obvious unanswered question is why didn't Java include operator overloading?  Isn't Complex a, b, c; a = b + c; much simpler than Complex a, b, c; a = b.add(c);?  Is there a known reason for this, valid arguments for not allowing operator overloading? Is the reason arbitrary, or lost to time?
52849
So I have a pointer to an array of pointers.  If I delete it like this:  delete [] PointerToPointers;   Will that delete all the pointed to pointers as well?  If not, do I have to loop over all of the pointers and delete them as well, or is there an easier way to do it?  My google-fu doesn't seem to give me any good answers to this question.  (And yeah, I know I need to use a vector.  This is one of those "catch up on C++" type assignments in school.)
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!
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?
76173
I am a little bit confused on what do these operators do differently when used in bash (brackets, double brackets, parenthesis and double parenthesis).  [[ , [ , ( , ((   I have seen people use them on if statements like this :  if [[condition]]  if [condition]  if ((condition))  if (condition)
14235
That's basically the question, is there a "right" way to implement operator&lt;&lt; ? Reading  I can see that something like:  friend bool operator&lt;&lt;(obj const&amp; lhs, obj const&amp; rhs);   is preferred to something like   ostream&amp; operator&lt;&lt;(obj const&amp; rhs);   But I can't quite see why should I use one or the other.  My personal case is:  friend ostream &amp; operator&lt;&lt;(ostream &amp;os, const Paragraph&amp; p) {     return os &lt;&lt; p.to_str(); }   But I could probably do:  ostream &amp; operator&lt;&lt;(ostream &amp;os) {     return os &lt;&lt; paragraph; }   What rationale should I base this decision on?  Note:   Paragraph::to_str = (return paragraph)    where paragraph's a string.
22978
When and how do we use the different kinds of brackets/parentheses&nbsp;— (){}[]&nbsp;— while writing English (not code)?
21215
I have just noticed that a multidimensional array in C# does not implement IEnumerable&lt;T&gt;, while it does implement IEnumerable. For single-dimensional arrays, both IEnumerable&lt;T&gt; and IEnumerable are implemented.  Why this difference? If a multi-dimensional array is IEnumerable, surely it should also implement the generic version? I noticed this because I tried to use an extension method on a multidimensional array, which fails unless you use Cast&lt;T&gt; or similar; so I can definitely see the an argument for making multidimensional arrays implement IEnumerable&lt;T&gt;.  To clarify my question in code, I would expect the following code to print true four times, while it actually prints true, false, true, true:  int[] singleDimensionArray = new int[10]; int[,] multiDimensional = new int[10, 10];  Debug.WriteLine(singleDimensionArray is IEnumerable&lt;int&gt;); Debug.WriteLine(multiDimensional is IEnumerable&lt;int&gt;); Debug.WriteLine(singleDimensionArray is IEnumerable); Debug.WriteLine(multiDimensional is IEnumerable);
16217
I've just read this  from Reddit.  They mention and and or being "Alternative Tokens" to &amp;&amp; and ||  I was really unaware of these until now. Of course, everybody knows about the , but and and or? Since when? Is this a recent addition to the standard?  I've just checked it with Visual C++ 2008 and it doesn't seem to recognize these as anything other than a syntax error. What's going on?
22625
MyClass[] array; List&lt;MyClass&gt; list;   What are the scenarios when one is preferable over the other? And why?
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).
11190
When building console applications that take parameters, you can use the arguments passed to Main(string[] args).   In the past I've simply indexed/looped that array and done a few regular expressions to extract the values. However, when the commands get more complicated, the parsing can get pretty ugly.    So I'm interested in:   Libraries that you use Patterns that you use   Assume the commands always adhere to common standards such as .
9629
I use a lot of lists and arrays but I have yet to come across a scenario in which the array list couldn't be used just as easily as, if not easier than, the linked list.  I was hoping someone could give me some examples of when the linked list is notably better.
116782
Possible Duplicate:          see this code    #define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0]))     int array[] = {23,34,12,17,204,99,16};     int main()     {         int d;         for(d=-1;d &lt;= TOTAL_ELEMENTS-2;d++)            printf("%d\n",array[d+1]);         return 0;    }    now this loop won't run. sizeof() would return an unsigned value so TOTAL_ELEMENTS has an unsigned value. now , coming to the for loop, please tell me if the unary operator '-' works on signed int 2 or an implicit conversion takes place into unsigned and then the '-' operator works.
5927
I've been told not to use for...in with arrays in JavaScript. Why not?
95859
Why does C/C++ differentiates in case of array index out of bound #include &lt;stdio.h&gt; int main() {     int a[10];     a[3]=4;     a[11]=3;//does not give segmentation fault     a[25]=4;//does not give segmentation fault     a[20000]=3; //gives segmentation fault     return 0; }  I understand that it's trying to access memory allocated to process or thread in case of a[11] or a[25] and it's going out of stack bounds in case of a[20000]. Why doesn't compiler or linker give an error, aren't they aware of the array size? If not then how does sizeof(a) work correctly?