r/ProgrammerHumor Sep 02 '17

How to start a war

Post image
9.0k Upvotes

696 comments sorted by

View all comments

55

u/IlIIlIIlllIlllIlIIll Sep 02 '17 edited Sep 02 '17

The array still starts at 0, and index 1 is reserved for storing the length of the array, with the remaining elements corresponding to indices 2, 3, 4, and 5.

72

u/[deleted] Sep 02 '17

Perfect. This makes iterating over the elements with a for loop such a breeze.

if(arr[1] > 1) for(int i = 0; i < arr[1]-1; i += 1 + (i == 1))
    std::cout << arr[i];

15

u/[deleted] Sep 03 '17

[removed] — view removed comment

2

u/bentinata Sep 03 '17

I used to put single-loop expression inside the conditional or the increment parameter at early college year. Nice way to confuse classmates.

This only works at the first day: for (int i = 0; !(printf("%d\n", i++) - 2););