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"); }
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().
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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.
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens