Bifalgorithm post · Computer science one · Comparisons

How does strcmp() compare the contents of two strings in C?

How does strcmp() compare the contents of two strings in C? (Computer science one · Comparisons) — "The C string library provides a standard comparator functio…

Ideas in this flowchart

  • La bibliothèque de chaînes C fournit strcmp() pour comparer le contenu de deux chaînes.
  • Signature : int strcmp(const char *a, const char *b);
  • La fonction reçoit deux chaînes, a et b.
  • La valeur retournée est un entier fondé sur l’ordre lexicographique de a et b.
  • Cas possibles de la valeur retournée.
  • strcmp() retourne une valeur négative si a précède b.
  • strcmp() retourne zéro si a et b ont le même contenu.
  • strcmp() retourne une valeur positive si b précède a.
  • Exemples d’utilisation avec une variable entière x.
  • strcmp("apple", "banana") retourne une valeur négative dans x.
  • strcmp("zelda", "mario") retourne une valeur positive dans x.
Feed/

How does strcmp() compare the contents of two strings in C?

No cover

Channel

Computer science one

1 page

"The C string library provides a standard comparator function to compare strings based on their content:\n\nint strcmp(const char *a, const char *b);\n\nThe function takes two strings and returns an integer based on the lexicographic ordering of a and b. If a precedes b, strcmp() returns something negative. It returns zero if a and b have the same content. Otherwise it returns something positive if b precedes a. Some examples:\n\n1 int x;\n\n2 x = strcmp(\"apple\", \"banana\"); //x is negative\n\n3 x = strcmp(\"zelda\", \"mario\"); //x is positive"

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.