ExamVeda
Login
Home
This question belongs to C Program Arrays And Strings
Arrays and Strings
?

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");
}

Answer & Solution
Correct Answer: Option B

Strings are compared using strcmp() function defined under string.h header file.

Examveda
Question posted by Examveda
Community

Join the Discussion

12 Comments
Tt Y
Tt Y 4 years ago
How this program runs explain
Moza Alshkhari
Moza Alshkhari 6 years ago
String str1 = “ABCD“ ;
String str2 = str1.toLowerCase();
str2.replace(‘a’ , ‘b’ );
str2.replace(‘b’ , ‘c’ );
System.out.printIn(str2);
Vrunda Savaliya
Vrunda Savaliya 7 years ago
We can not compare string with operators so i think ans c is right .
Anti Hero
Anti Hero 8 years ago
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.
Saket Srivastava
Saket Srivastava 8 years ago
String is not compared the way it is being compared like integers. That's why the answer is "Unequal".
Dhiraj Chandanshive
Dhiraj Chandanshive 9 years ago
i thing c answer is correct
Don Satish
Don Satish 9 years ago
hi, friends !!!

if(str1==str2);// we will get if(0) i.e if(false)

so the else part is executed.
Md Iqbal
Md Iqbal 9 years ago
ans is error , braces missing sir
Mayank Thaldi
Mayank Thaldi 10 years ago
ANKITA U R RIGHT !!
Ankita Awasthi
Ankita Awasthi 10 years ago
It's a run time error...answer is c)error
Arif Saifi
Arif Saifi 10 years ago
what do compare == operator. Is this match address
Pramod Tonape
Pramod Tonape 10 years ago
i am not getting.
can u tell in simple...................