C Programming - Strings - Discussion

Discussion Forum : Strings - Find Output of Program (Q.No. 11)
11.
What will be the output of the program ?
#include<stdio.h>
#include<string.h>

int main()
{
    static char str1[] = "dills";
    static char str2[20];
    static char str3[] = "Daffo";
    int i;
    i = strcmp(strcat(str3, strcpy(str2, str1)), "Daffodills");
    printf("%d\n", i);
    return 0;
}
0
1
2
4
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
31 comments Page 3 of 4.

Satwika said:   9 years ago
Nice explanation @Gautam.

Harish said:   8 years ago
Str1=dills
Strcpy(str2,str1) it gives str2 = dills
Strcat(str3,str2) gives str3 = daffodills
Strcmp(str3,"daffodils")=it gives 0 ,in string comparison if condition is true it will return 0 else 1.

Mohan said:   7 years ago
Str1=dills.
Strcpy(str2,str1) it gives str2 = dills.
Strcat(str3,str2) gives str3 = daffodills
Strcmp(str3,"daffodils")=it gives 0 ,in string comparison if condition is true it will return 0 else 1.
(1)

Suyash said:   6 years ago
If the string is the same it should return 1 not 0?

Please explain to me.

Deepak Johnson said:   6 years ago
@Suryash.

If we compare the strings the value should return to 0...(Not 1).
Because, if s1 = s2 value would return 0.
If s1<s2 value would be less than 0.
If s1>s2 value would be greater than 0.

Rushikesh Bhosale said:   6 years ago
Thanks @Gautam.

Uday said:   6 years ago
strcmp() will always return the value 0.
(1)

Musthak rahaman said:   6 years ago
The actual output for this is the process finished with exit code -6.

Priya said:   5 years ago
Thanks @Goutham.

Suraj gupta said:   8 months ago
Str1=dills.
Strcpy(str2,str1) it gives str2 = dills.
Strcat(str3,str2) gives str3 = daffodills
Strcmp(str3,"daffodils")= it gives 0, in string comparison if condition is true it will return 0 else 1.
(2)


Post your comments here:

Your comments will be displayed after verification.