+ 1
Longest string in an array in C++
I wrote this code: char a[100][100] = {"solol","a","1234567","123","1234"}; int max = -1; for(int i=0;i<5;i++) if(max<strlen(a[i])) max=strlen(a[i]); cout<<max; The output it gives is -1. But when I initialize the value of max by 0, the code works fine. Why is it so?
1 Answer
+ 2
Nevermind, I fixed my code myself. I was comparing signed value with an unsigned value returned by strlen(a[i]);