0
How this get result -1??
What is the output of this code? #include <stdio.h> int main() { int b, p; char str1[] = "Sololearn"; char str2[] = "sololearn"; b = strcmp(str1, str2); printf("%d", b); return 0; }
4 Respostas
+ 3
soharab uddin mondal strcmp compares a string character by character , if the first character of both string are equal (i.e. have same ascii value), it will return 0 .
If a character of first string has a ascii value less than character of second string ,then it will return -1 and vice versa .
Here "S" Has ascii value of 83 , while "s" has a value of 115 .
+ 1
Ascii value of S is smaller than s
+ 1
Abhay Thank you so much. Your explanation was amazing. 👍👍👍
0
Abhay can you please explain in details ?