1

When i declare array as array[1-00] by mistake i didn't get the right answer. But when i change it to normal declaration like array[100] i clear all the test cases. Can anyone provide any explanation for this type of problem? Please.

1 Answers1

2

You declared the array with a size of 1.

int arr[100]; //100 elements
int arr2[1]; //1 element
int arr3[1-00] // 1 - 0 = 1 element

accessing elements outside the array is undefined behavior, which means that the compiler can do whatever it wants. Read this for more information about undefined behavior.

Mestkon
  • 3,532
  • 7
  • 18