139
Comments
  • 19
    That's the Bethesda style.
  • 5
    I wish there was a zoom-in on the face of the other guy while he was pouring in the coke. imagining it like 😱
  • 1
    hahaha made my day
  • 4
    int array[] = {0,1,2,3,4,5};

    cout << 2[array] << endl;
  • 1
    @Demolishun don't tell me this actually works 😳
  • 4
    @Lensflare Yes, it does. Its pointer math with an operator []
  • 0
    @Demolishun This will fail when the sizeof(element) != sizeof(pointer)
    Correct?
  • 0
    @Lensflare no, wait. I guess that pointer + integer already takes into account the size of the the pointer type. So 2[a] should indeed work for any sizeof element.
  • 1
    @Lensflare In C++ the compiled code should be identical. This is for arrays and not more complex types that use operator[]()
  • 4
    @Demolishun yeah I just learned from stackoverflow that a[b] is translated to *(a + b)

    the plus operator takes one integer and one pointer. Order of operands doesn't matter so we get classic pointer arithmetics.

    The pointer is advanced by the integer value multiplied by the size of the pointer type.

    These are the bits I had to understand in order to understand why a[b] is the same as b[a]
  • 0
    Javascript type conversion parkour
Add Comment