1
Cコード論理演算子と割り当て
#include <stdio.h>
int main(void) {
int first = 10;
int second = 20;
int third = 30;
int x = ((first == second) || third);
printf ("%d", x);
}
Output: 1
Perlコード
#!/usr/bin/perl
use strict;
use warnings;
my $first = 10;
my $second = 20;
my $third = 30;
my $x = (($first == $second) || $third);
print $x;
Output: 30
なぜD oes Perlはこのように動作しますか?
@ikegamiは '出力されません1'? –
Perlopは 'The ||、//、&&演算子は評価された最後の値を返します。(Cの||と&&は0または1を返します)' – Dada
@Dada Ohありがとう、ありがとう。 –