Common term for the "value-based" OR operator
c, c++, language-agnostic, perl
Solution
The C version uses || as the logical OR between the two values. Both 44 and 99 evaluate to `true` in C as they are not `0`, so the result of an OR between them returns `1` (AKA `true` in C)
In that particular perl snippet, || is the null-coalescing operator, an binary which evaluates to the second argument if the first is null, otherwise evaluating to the first argument. Since `99` is the first argument and not null, it gets returned and printed.
EDIT: Thanks Evan for the clafication: The || operator in perl is not the null-coalescing operator, it returns the RHS if the LHS evaluates to false, other wise returning the LHS. `//` is the "proper" null-coalescing operator.
Here's the list of values in perl that evaluate to false (from wikipedia)
$false = 0; # the number zero
$false = 0.0; # the number zero as a float
$false = 0b0; # the number zero in binary
$false = 0x0; # the number zero in hexadecimal
$false = '0'; # the string zero
$false = ""; # the empty string
$false = undef; # the return value from undef
$false = 2-3+1 # computes to 0 which is converted to "0" so it is false
Problem
Just a quick question ``` printf("%d", 99 || 44) prints "1" in C print 99 || 44 prints "99" in perl ``` There are two different kinds of evaluation. Does each one have a name? edit: i'm interested to know how this Perl evaluation is commonly called when compared to C. When you say "C example is X, and perl example is not X, but Y" which words would you use for X and Y. "short circuit" is not what i'm looking for.