Computer Science, asked by chandanam0310, 1 year ago

what will be the value of x for the following code snippet?
char str1[]="dills";
char str2[20]="hello";
char str3[]="daffo";
int x;
x=strcmp("daffodills",strcat(str3,strcpy(str1,str2)));

Answers

Answered by MusicViking
2

Hello daffodills

(though it is spelled as daffodils)


chandanam0310: plzz check once its is so improtant
MusicViking: yes yes
chandanam0310: correct only naa
chandanam0310: 100%
chandanam0310: hello
MusicViking: yes
chandanam0310: thank u
MusicViking: not sure about the 100% tho.... ask your friends maybe?
chandanam0310: not the words it is the value of x in numbers
MusicViking: oh ok
Answered by sailorking
0

In this program the output of the following code snippet will be "-4". The reason is very simple, when "strcmp" function is used to compare two strings, what happens is just the ASCII code of the words to be compared are subtracted, and the difference is returned, whenever the difference is any non zero number.

Here the in the code the first character with mismatch has a difference of 4, so the value of shall become -4.

Similar questions