, 04 2017 . 15:17
+
JavaScript,
PHP 2 + 2 = 4 . .
|
|
|
False |
True |
|
C++
Pascal
FORTRAN-95
Java
C#
Go
Rust
Haskel
|
C
Lisp
Python
Lua
Ruby
|
JavaScript
PHP
Perl
|
C , C++ -fpermissive.
, , .
.
, .
C++
cout << (2 + 2 == "4") << endl;
error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
-fpermissive 4 0.
Pascal
writeln((2 + 2) = "4");
Fatal: illegal character "'"'" ($22)
FORTRAN-95
Print *, 2 + 2 == "4"
Error: Operands of comparison operator '==' at (1) are INTEGER(4)/CHARACTER(1)
, , .
Java
System.out.println((2 + 2) == "4");
error: incomparable types: int and String
, .
C#
Console.WriteLine((2 + 2) == "4");
error CS0019: Operator `==' cannot be applied to operands of type `int' and `string'
.
Go
fmt.Printf(2 + 2 == "4")
cannot convert 4 to type int
invalid operation: 4 == 2 + 2 (mismatched types string and int)
Rust
println!("{:?}", 2 + 2 == "4");
error: the trait `core::cmp::PartialEq<&str>` is not implemented for the type `_` [E0277]
,
Haskel
main = putStrLn (show ((2 + 2) == "4"))
No instance for (Num Char) arising from a use of `+'
, . Haskel .
False
, false ( - ), - .
C
printf("%i\n",(2 + 2 == "4"));
0. 4 0. , C++:
warning: comparison between pointer and integer [enabled by default]
Lisp
(write (eq "123" 123))
NIL
Python
print (2 + 2 == "4")
False
Lua
print(2 + 2 == "4")
false
Ruby
puts 2 + 2 == "4";
false
True
true .
JavaScript
console.log(2 + 2 == "4");
( ===), false
PHP
echo (2 + 2 == "4");
, JavaScript , FALSE, ( - ). ).
Perl
print 2 + 2 == "4";
, ( )
print 0x2 + 0x2 == "0x4";
Perl 0x4 0 ( JavaScript PHP, ) FALSE, .
, .
, .
https://habrahabr.ru/post/330176/
:
author igormich88