Here in my sample code, I am comparing two char pointer and two char array and output is
Output:
case I :true
case II : false
for case II, I understood that it's evaluated false because memory allocation of arr1
and arr2
is different. But I am not getting why case I evaluated as true.
int main()
{
char *string = {"string"};
char *string2 = {"string"};
char arr1[] = {"string"};
char arr2[] = {"string"};
/******* case I **********/
if(string == string2){
printf("case I :true \n");
}
else{
printf("case I :false \n");
}
/****** case II **********/
if(arr1 == arr2){
printf("case II : true \n");
}
else{
printf("case II : false \n");
}
return 0;
}