C Programming - Strings - Discussion

Discussion Forum : Strings - General Questions (Q.No. 2)
If the two strings are identical, then strcmp() function returns
Answer: Option

Declaration: strcmp(const char *s1, const char*s2);

The strcmp return an int value that is

if s1 < s2 returns a value < 0

if s1 == s2 returns 0

if s1 > s2 returns a value > 0

14 comments Page 1 of 2.

Sandhya said:   6 years ago
I think if string1>string2 it will return +ve.
string1<string it will return -ve.
string1=string it will return 0.

Devi achsah said:   6 years ago
Why they used const keyword in the argument?

Jaimin kathrotiya said:   7 years ago
Yes, It returns zero.

Uday said:   7 years ago
Actually there is a pointer function before strings. So if we give equal values to both strings but address are different, because strings are different.

Sowmi said:   7 years ago
It returns 0. Given answer is correct.

Suganthy said:   8 years ago
Yes @Sundar is right, don't confuse yourself by searching answer for it.

Jagdish said:   10 years ago
@Sunder is right. It will return only 0 when both string are similar otherwise it will return 1 or -1.

Sanjay said:   1 decade ago
If both the strings are equal then it returns 1 otherwise 0.

Vinod said:   1 decade ago

Shri said:   1 decade ago
When you compare any two strings at that time compiler will return 0.

And this logic is used to find palindrome string.

Post your comments here:

Your comments will be displayed after verification.