+ 27
{Important} This thread is for weird & interesting programs! {Check it}
Friends these are the program that i thought interesting if you know some you can post yours. In C/C++ you can have as many semicolons as you want at least in the MS C++: int main(void) { cout<<"Hello World";;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;; return 0;;;;;;;;;;;;;;;;;;;;;;; } POST if you have one and explain these if you like.
20 ответов
+ 25
In JavaScript:
alert(111111111111111111111) // alerts 111111111111111110000
+ 24
In java:
int x = 1 + + + + + + + + + + + + + 1;
System.out.println(x);
Outputs 2.
+ 22
In PHP one can do:
System.out.print("hello");
+ 17
In Python:
from __future__ import braces
#Output: SyntaxError: not a chance
+ 17
try this in java:
try {
throw new AssertionError();
} finally {
return false;
}
+ 17
For java:
Integer.valueOf(127) == Integer.valueOf(127); // true, same instance
Integer.valueOf(128) == Integer.valueOf(128); // false, two different instances
+ 17
In C#, this doesn't generate a compiler warning:
public int Something
{
get { return Something; }
set { Something = value; }
}
When called, it causes your app to crash, it's a StackOverflowException.
+ 16
The following text is a single complete comment:(java)
/* this comment /* // /** ends here: */
+ 15
In C#, you can also have as many ; as you want
+ 7
My favorite in Python is:
import this
+ 7
What's interesting about this is that Python lets you override keywords. It was a typo (equals is adjacent to backspace) that I helped someone fix, which breaks the interpreter (easiest fix is reload):
aTuple=(1,2)
print=("take that"+"and that")
print(aTuple)
Error: 'str' object is not callable. (on the tuple print)
+ 6
In python,try this:
d = {True:"Sun"}
d[1] = "Moon"
print(d)
+ 6
in c++
you must know to swap you can do
a=a+b-(b=a);;;;
you must also know that
a+=b+z-x;
is evaluated to
a=a+b+z-x;
but
a=a+b-(b=a);
and
a+=b-(b=a);
don't yield same result.
+ 5
Have you found something like these in python?
+ 5
In python:
print("""""text""""")
outputs: ""text
+ 5
for (int i=0; i<5; i++, extraAction()) {
// c, c++
}
+ 5
Duff's Device. Sometimes considered skiddish, intended to save condition cycles, sometimes faster than a standard 'for' loop (but worse if ported badly):
https://code.sololearn.com/cT46etCvzTbO/?ref=app
Notice how 'case' jumps into the middle of the do..while; it sends 2 values, then loops and sends the next 8. One loop vs 10. Final byte is printed to prove it finishes.
Output is assumed to be a memory-mapped stream (so something would be watching the output byte change; this sample just couts the last value).
+ 3
oh, cool.
In python :
Swap the value of 2 variables
a,b = b,a
+ 2
In C++ :
You can override the operator ','