Compare character arrays

bool compare(char a[], char b[]){
int lena = strlen(a);
int lenb = strlen(b);
int i=0, j=0;

while(i<=lena && j<=lenb){//comparing null char also
    if(a[i] != b[j]) return false;
    i++;
    j++;
}
return true;

}

int main()
{
char a[] = {‘a’,‘b’,‘c’,‘d’,’\0’};
char b[] = {‘a’,‘b’,‘c’,‘d’,‘e’,’\0’};
cout<<compare(a, b);

return 0;

}
//can we compare null character also in while loop or //not? As in video we are comparing it separately.

hi @The_Aishwarya
in actual there is no need to compare the null character as its just used as a terminator in char arrays…

is there anything else??

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.