Monday, May 24, 2010

Answer this trick question in C language...find the output of this...?

#include%26lt;string.h%26gt;


main()


{


char str1[] = "Infosys";


char str2[] = "Infosys";


if(str1==str2)


printf("\n Equal");


else


printf("\n UnEqual");


}

Answer this trick question in C language...find the output of this...?
prints "UnEqual"





the == function will actually be checking if the strings are at the same memory location. To compare strings, you need to use strcmp() and check that the return value is zero.


No comments:

Post a Comment