If you compare arrays and pointers using the equality operator, then you are comparing whether they are the same array or point to the same object. You aren't comparing the content of the arrays or pointed elements. Since argv[1]
points to a different array than the string literal, they compare unequal regardless of their content.
tried executing: if(&argv[1] == "w")
Now, you're comparing char**
to a const char*
(after array decay). Comparing pointers of unrelated types doesn't make much sense.
if(argv[1]=='w')
.
Now, you're comparing char*
to char
. Comparing a pointer to a char doesn't make much sense.
To compare the content of two strings, A good solution is to use a string view as either or both of the operands. It's a small change:
using namespace std::literals;
if (argv[1] == "w"sv)