53.3k views
4 votes
Which of the following statements regarding the strcmp function from string.h is TRUE?

A. The strcmp function will return the sum of the difference of two strings.
B. The strcmp function will return one when the two strings contain the same data.
C. The strcmp function is unable to identify two strings as containing the same data if the declared size of the strings is different.
D. None of the above.

User Samiles
by
8.4k points

1 Answer

3 votes

Final answer:

The strcmp function compares two strings and returns 0 if they are equal, a positive number if the first string is greater, and a negative number if it's less. It's based on actual contents, not the sizes of the strings.

Step-by-step explanation:

The correct statement regarding the strcmp function from string.h is 'None of the above'. According to the C standard library, strcmp compares two strings character by character.

If the strings are equal, strcmp returns 0. If the first string is greater than the second one, it returns a positive number, and if it's less, it returns a negative number. The comparison is based purely on the actual contents of the strings, not their declared sizes. Therefore, statements A, B, and C are all incorrect.

User Pellenberger
by
8.0k points