Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is b[2] false?

string s;
bool b[] = {s=="",  s==s.c_str(),  s.c_str()==""};

sets

b[] = {true, true, false};

why is b[2] false?

If A==B and A==C, should that not imply B==C?

like image 772
NoComprende Avatar asked Oct 17 '19 16:10

NoComprende


People also ask

Why is VLOOKUP returning the wrong value?

VLOOKUP returning incorrect resultsIf you omit to supply match type in a range_lookup argument of VLOOKUP then by default it searches for approximate match values, if it does not find exact match value. And if table_array is not sorted in ascending order by the first column, then VLOOKUP returns incorrect results.

Why sometimes VLOOKUP does not work?

Problem: The lookup value is not in the first column in the table_array argument. One constraint of VLOOKUP is that it can only look for values on the left-most column in the table array. If your lookup value is not in the first column of the array, you will see the #N/A error.

Can VLOOKUP return true or false?

Translated in plain English, the formula instructs Excel to return True if Vlookup is true (i.e. equal to the specified value). If Vlookup is false (not equal to the specified value), the formula returns False.

What does a $2 mean in Excel?

Absolute references An absolute reference is designated in a formula by the addition of a dollar sign ($) before the column and row. If it precedes the column or row (but not both), it's known as a mixed reference. You will use the relative (A2) and absolute ($A$2) formats in most formulas.


1 Answers

In this expression

s.c_str()==""

there are compared two pointers (addresses). The first one is the pointer returned by s.c_str() and the second one is the pointer to the first character (terminaring zero character) of the string literal "".

It is evident that the addresses are different (bear also in mind that the string literal has the static storage duration).

To get the expected result you should write instead

std::strcmp( s.c_str(), "" ) == 0

As for these two expressions

s==""

and

s==s.c_str()

then there are compared strings because the standard class std::string has overloaded operator == for the right operand.

like image 109
Vlad from Moscow Avatar answered Sep 28 '22 06:09

Vlad from Moscow