4

Quirk of C++ (also C I think)
int array[]={1,2,3,4,5};
int temp = array[0]; //valid access
int temp2 = 0[array]; // also valid

C++ is a member of the Foot Shooters Club languages of choice.

Also, this weekend I learned you cannot have a vector of references:
https://stackoverflow.com/questions...
Well, at least not without some pain.

Comments
  • 2
    int[] == int*
    a[b]==(a+b)
    a+b==b+a

    Similar to JS many quirks make sense once you understand how they occur in the first place.
  • 1
    This looks totally unnecessary but to be fair it makes sense.
  • 2
    @gitreflog not quite

    It should be

    pointer address + b * size of datatype
  • 0
  • 0
    @fuckwit not quite I think. The actual pointer offset operation is p + b. But since p is a pointer to type t, this offset operation considers the size of t in the offset operation.
Add Comment