0
Problem in a line of code.
//Program to calculate even or odd #include<stdio.h> #include<string.h> int main() { char array[1000001]; long long int i,test,len; scanf("%lld",&test); for(i=0;i<test;i++) { scanf("%s",array); len=strlen(array); if(array[len-1]%2==0) printf("YES\n"); else printf("NO\n"); } } The code above works perfectly fine. My question is that why in "if(array[len-1]%2==0)" array[len-1] is taken rather than taking array[len]?
1 Respuesta
+ 1
Array[len] is out of bounds. Arrays start counting as 0, instead of 1, meaning they have one less indices than the length.