The second expression will evaluate to either 1
or 0
.
Quoting the C11 standard draft:
6.5.14 Logical OR operator
- The
||
operator shall yield 1 if either of its operands compare unequal to 0; otherwise, it yields 0. The result has type int
.
So the two expressions are very different, since one of them yields a pointer, and the other one an integer.
Edit:
One of the comments claims that this answer is only valid for c, and @Lightness Races in Orbit is right.
There are also answers that are only correct for c++1, although the only difference with them is that c++ has type bool
and then it evaluates this expression as bool
instead of int
. But apparently there is an important issue with overloading ||
operator in c++, which prvents short-citcuiting to apply for the object that overloads it.
So for c++ there are more things to consider, but since this question was tagged with both languages tags, then it's necessary to mention at least the differece.
The rule still applies when short-circuiting applies, i.e. the result of the evaluation of the expressions is either 1
or 0
for c and true
or false
for c++.
1 Like these answers: 1, 2