What will be the output of the following program?
void main()
{
char str1[] = "abcd";
char str2[] = "abcd";
if(str1==str2)
printf("Equal");
else
printf("Unequal");
}
void main()
{
char str1[] = "abcd";
char str2[] = "abcd";
if(str1==str2)
printf("Equal");
else
printf("Unequal");
}A. Equal
B. Unequal
C. Error
D. None of these.
Answer: Option B
Solution (By Examveda Team)
Strings are compared using strcmp() function defined under string.h header file.
Join The Discussion
Comments (12)
Related Questions on Arrays and Strings

How this program runs explain
String str1 = “ABCD“ ;
String str2 = str1.toLowerCase();
str2.replace(‘a’ , ‘b’ );
str2.replace(‘b’ , ‘c’ );
System.out.printIn(str2);
We can not compare string with operators so i think ans c is right .
str1 and str2 are both separate memory allocations for the array elements, when the condition says str1==str2 , we are comparing its memory allocation and not the string i.e. "abcd", and since both the strings cannot be in the same memory location , therefore the answer will always be UNEQUAL no matter what the string may be, well atleast that is what I understood.
String is not compared the way it is being compared like integers. That's why the answer is "Unequal".
i thing c answer is correct
hi, friends !!!
if(str1==str2);// we will get if(0) i.e if(false)
so the else part is executed.
ans is error , braces missing sir
ANKITA U R RIGHT !!
It's a run time error...answer is c)error
what do compare == operator. Is this match address
i am not getting.
can u tell in simple...................