ELI5: Explain Like I'm 5

Strcmp

So, imagine you have two boxes of toys with different names on them: one says "cars" and the other says "trains". Now, you want to see if these two boxes have the same name or not.

That's what strcmp does - it compares two different strings of characters (like the names on the toy boxes) to see if they are the same or different.

It looks at each individual character in both strings and compares them one by one. So, for example, it starts with the first character in each string: c from "cars" and t from "trains". It compares them and sees that they are different, so it moves on to the next character: a from "cars" and r from "trains".

This keeps going until either strcmp finds a difference in the characters and knows the strings are not the same, or it goes through all the characters and knows the strings are the same.

So, just like you compare the names on the toy boxes to see if they are the same, strcmp compares two strings of characters to see if they are the same or different.
Related topics others have asked about: