Can I do...
Code:char first[10] = "123456789";
char second[10] = "123456789";
if (first == second) {
printf("The strings are the same");
} else {
printf("The strings are not the same");
}
Printable View
Can I do...
Code:char first[10] = "123456789";
char second[10] = "123456789";
if (first == second) {
printf("The strings are the same");
} else {
printf("The strings are not the same");
}
Yes, but you actually want to use say, strcmp().
In the context you've mentioned above, the expression testing for equality is actually comparing the address of the two variables ("first" and "second"). The address of these two distinct variables will never be the same. In C++ using std::string containers you can test the variables as you've done but in C you need the strcmp function.