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 4 of 4.
Mallesh said:
7 months ago
Here str1 [] = "dills".
str2[20]
str3[] = "Daffo"
int i
The condition is checked by the form precedence and associativity
i = strcmp(strcat(str3, strcpy(str2, str1)), "Daffodills")
printf("%d\n", i)
i = strcmp(strcat(str3, "dills"), "Daffodills")
i = strcmp("Daffodills", "Daffodills")
i = 0
Then, by the stcmp conditions,
if Str 1 == str2 -> 0.
str1 > str2 -> +ve value.
str1 < str2 -> -ve value.
str2[20]
str3[] = "Daffo"
int i
The condition is checked by the form precedence and associativity
i = strcmp(strcat(str3, strcpy(str2, str1)), "Daffodills")
printf("%d\n", i)
i = strcmp(strcat(str3, "dills"), "Daffodills")
i = strcmp("Daffodills", "Daffodills")
i = 0
Then, by the stcmp conditions,
if Str 1 == str2 -> 0.
str1 > str2 -> +ve value.
str1 < str2 -> -ve value.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers