string - What does strcmp() exactly return in C? -


i wrote code in c:

#include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h>  int main() {     char string1[20];     char string2[20];     strcpy(string1, "heloooo");     strcpy(string2, "helloo");     printf("%d", strcmp(string1, string2));     return(0); } 

should console print value 1 or difference between ascii values of o , \0 character i.e. 111? on this website, written should give out put 111, when run on laptop, shows 1. why?

from the cppreference.com documentation

int strcmp( const char *lhs, const char *rhs ); 

return value

  • negative value if lhs appears before rhs in lexicographical order.

  • zero if lhs , rhs compare equal.

  • positive value if lhs appears after rhs in lexicographical order.

as can see says negative, 0 or positive. can't count on else.

the site linked isn't incorrect. tells return value < 0, == 0 or > 0 , gives example , shows it's output. doesn't tell output should be 111.


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -