In this expression with the equality operator
(a==b)
the both operands having array types are implicitly converted to pointers to their first elements. In fact the expression above may be rewritten like
( &a[0] == &b[0] )
As the arrays occupy different extents of memory then this comparison will always yield 0
.
Pay attention to that if you will write for example
( "hello" == "hello" )
that may be also rewritten like
( &"hello"[0] == &"hello"[0] )
then the result of the expression is unspecified. That is the compiler can store identical string literals as separate character arrays or as one character array depending on compiler options.
For example in MS VS C++ there are compiler options /GF
and /GF-
that allow either to create one character array for identical string literals or different arrays. This option is well-documented and can be set in properties of a given project.
As for this expression
(10 == 10.0)
then to perform the operation the compiler needs to determine the common type of the operands using the usual arithmetic conversions. That is the operand with the type int
(10) is converted to the type double
and two double values are compared.