-4

What is the difference between "||" and "or"?

a = false || true;
b = false or true;
NeDark
  • 1,212
  • 7
  • 23
  • 36
  • `or` is a synonym for `||`. `||` isn't supported with all non-ISO-646 character sets. – Peter Oct 14 '18 at 12:16
  • Personally, I prefer `¦¦` because of all the time I programmed on an IBM PC in the early 1980s. But that's not vogue anymore, and some characters have been moved around since that era of ANSI. – Eljay Oct 14 '18 at 12:23
  • Why downvotes?. – NeDark Oct 14 '18 at 16:38

3 Answers3

1

there are no difference, see https://en.cppreference.com/w/cpp/keyword/or

sometime (question of taste) may enforce readability (no confusion with |)

OznOg
  • 4,440
  • 2
  • 26
  • 35
1

There are a group of alternative tokens specified in the standard(a), which equate to primary tokens. One of these is or for the || token.

As per C++11/14 2.6 Alternative tokens and C++17/20 5.5 Alternative tokens (wording has remained the same across all these iterations of the standard):

In all respects of the language, each alternative token behaves the same, respectively, as its primary token, except for its spelling.

That's my emphasis to indicate that there is no real difference at all.


(a) As of C++17 (the most recent accepted standard at the time of this answer), the list of alternative tokens and their primaries is:

Alt Prim         Alt    Prim        Alt    Prim
--- ----         ---    ----        ---    ----
<%   {           and    &&          and_eq &=
%>   }           bitor  |           or_eq  |=
<:   [           or     ||          xor_eq ^=
:>   ]           xor    ^           not    !
%:   #           compl  ~           not_eq !=
%:%: ##          bitand &
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
0

No difference at all. or is simply an alternative keyword for ||.

See also https://en.cppreference.com/w/cpp/language/operator_alternative

Jesper Juhl
  • 30,449
  • 3
  • 47
  • 70