1 / 3
Oct 2019

Please have a look at this simple code and its output :

L is supposed to be 16 when the for loop ends in both cases. I have verified this on my local g++ compiler.

Here, it stops at a random value of L in the first case, every time this code is run. It is as if the condition L < 16 was ignored and the for loop continued until String[L] != '_' became false.

  • created

    Oct '19
  • last reply

    Oct '19
  • 2

    replies

  • 1.4k

    views

  • 2

    users

  • 2

    links

If this is a bug, it’s a bug in the C++ compiler, not Spoj or IdeOne. I don’t think Sphere Labs will be fixing the compiler, although they may install a later version if there is one.

Edit: perhaps report it to GCC in Bugtracker2.

I think this comes under the definition of “undefined behaviour”. I.e. accessing an element outside the bounds of an array, namely String[16], when String is only 16 elements long.