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;
}
Discussion:
31 comments Page 2 of 4.
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.
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.
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.
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)
Prakrati said:
1 decade ago
You all please run this code. It will give some negative result cause static char str3[] = "Daffo";memory is fixed. So this concatination is not possible. Target string should have enough memory.
Neeraj said:
1 decade ago
static is used just to confuse the students, it dosen't make any difference. static is a type of storage classs.
Arjun Prasad said:
1 decade ago
Will str3 array can store dills also?? I think not as its size is just 6 byte.
So I dont agree with answer...!!!
So I dont agree with answer...!!!
Anusha.v said:
1 decade ago
I agree with @Goutham's answer, but yet I didn't understood what is the role of static char in this programme?
AASIF JAVED said:
1 decade ago
Don't pass the value.In a comparing two string return the value 0 if string are equal other wise return 1...
Kritika said:
1 decade ago
strings are immutable and of reference type, that's y this copy in str3 is allowed.
Sus said:
1 decade ago
First it will copy str1 value to str2, then it will concatenate, and then compare.
Suyash said:
6 years ago
If the string is the same it should return 1 not 0?
Please explain to me.
Please explain to me.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers