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.
            Asked
            
        
        
            Active
            
        
            Viewed 57 times
        
    1
            
            
        - 
                    1`00` is zero, in the octal representation. `1-00` is the same as `1-0`. – molbdnilo May 28 '20 at 14:22
- 
                    Why did you even expect that it could still work? – SkryptX May 28 '20 at 14:35
- 
                    @molbdnilo -- fun fact: `0` is also octal. – Pete Becker May 28 '20 at 15:51
- 
                    @SkryptX i do a problem on hackerrank and it compiled and work, but only the answers are different. – deepjashan2020 May 29 '20 at 03:40
1 Answers
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
