We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
If it's in C/C++, there's no array bounds checking, so there would not be an exception. But as others have said, it's still not correct. It will read from the memory location just before the start of the array. If by chance or due to the specific implementation of the compiler, that memory location happens to hold 0, it will work. On a different system, or with a different compiler, or with different conditions, that memory location may have different contents that change the result.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and Array
You are viewing a single comment's thread. Return to all comments →
If it's in C/C++, there's no array bounds checking, so there would not be an exception. But as others have said, it's still not correct. It will read from the memory location just before the start of the array. If by chance or due to the specific implementation of the compiler, that memory location happens to hold 0, it will work. On a different system, or with a different compiler, or with different conditions, that memory location may have different contents that change the result.