Your code raises a warning because you are casting a pointer to a char into an int. However, this compiles:
#include <stdio.h>
const char* str1 = "foo";
const char* str2 = "foo";
const char* str3 = "foobar";
int main (void)
{
printf ("str1 == %i, address == %p\n", *str1, str1);
printf ("str2 == %i, address == %p\n", str2[0], str2);
printf ("str3 == %i, address == %p\n", *str3, str3);
if (str1 == str2) printf ("str1 and str2 are equal.\n");
if (str1 == str3) printf ("str1 and str3 are equal.\n");
return 0;
}
and the output is:
str1 == 102, address == 0x555d5c435824
str2 == 102, address == 0x555d5c435824
str3 == 102, address == 0x555d5c435828
str1 and str2 are equal.
We interpret 2 things as an int here: a dereferenced pointer to a char (*str1) or the first element of a char array (str2[0]). In this context, they are the same thing and the output is the same. *str3 is also the same as the other 2 because all strings happen to begin with an 'f', that is ASCII char number 102 when interpreted as an int. We can also notice that the addresses of str1 ans str2 are the same, but the address of str3 is different. So, (str1 == str2) succeeds because it compares pointer addresses, not int values. (str1 == str3) fails for the same reason.