r/ProgrammerHumor • • Jan 05 '19

You know it's true

Post image
60.6k Upvotes

1.1k comments sorted by

View all comments

Show parent comments

104

u/mrbmi513 Jan 05 '19

What is the value of x? int x = 5/2.0;

327

u/jay9909 Jan 05 '19

In Python it's a bunch of syntax errors.

98

u/RenBit51 Jan 05 '19

The correct answer

0

u/[deleted] Jan 05 '19

[deleted]

44

u/Wikipediano Jan 05 '19

Wait I thought Java has automatic type conversion from int to double?

Edit: wait no I forgot it's assigning the double to an int variable nvm

55

u/HBK05 Jan 05 '19

hahahah, java doing things the easy way. No my friend

0

u/[deleted] Jan 06 '19

[deleted]

14

u/nonamee9455 Jan 06 '19

I started in Java and Javascript made my head explode

34

u/kheup Jan 06 '19

JavaScript is easy. There are no rules so just do whatever you want and when it sometimes does something entirely unexpected just chalk it up as a fluke and carry on. Semicolons to end statements? Sometimes, sometimes not who cares. Types? Fuck it they're all var. Dates? Yeah sometimes it'll be UTC sometimes EST sometimes the time on Mars, that's the users problem.

20

u/nonamee9455 Jan 06 '19

Thanks I hate it

7

u/_Lady_Deadpool_ Jan 06 '19

I'll take JS dates any day over pythons fustercluck of a date system

Also at least JavaScript can do multi line lambdas. In fact that's 90% of the language!

4

u/kheup Jan 06 '19

This is true. It really seems like every language I've use is just so poorly equipped for dates.

→ More replies (3)
→ More replies (1)
→ More replies (14)
→ More replies (1)
→ More replies (1)
→ More replies (1)

55

u/jonny_wonny Jan 05 '19

That’s a bad one answer this: int x = rand();

0

u/[deleted] Jan 05 '19

[deleted]

→ More replies (2)

9

u/DonkeyVampireThe3rd Jan 05 '19

2?

14

u/jonny_wonny Jan 05 '19 edited Jan 05 '19

Nope the variable was modified in another thread so its value is 94626961. Any good programmer would know that

→ More replies (1)
→ More replies (1)

13

u/theXpanther Jan 05 '19

Also, what is the value of x ? x = 5/2.0 : ';'

70

u/adenosine-5 Jan 05 '19

what monstrosity of a language allows that syntax?

43

u/Thalanator Jan 05 '19

my bet is on some spawn of javascript

36

u/Cobaltjedi117 Jan 05 '19

Or maybe just JavaScript

→ More replies (2)
→ More replies (1)

15

u/theXpanther Jan 05 '19

It will work in Java, c#, or any other c based language as well

7

u/adenosine-5 Jan 05 '19

Are you sure?

Because x is not defined, there is no semicolon at the end and the ternary operator uses mixed variables - int, float and string/char...

So what is it supposed to do?

7

u/OmarRIP Jan 05 '19

He’s asking the value of the expression — never said it’s a statement. It’s an analogous question to “what’s the value of [the expression] 5 + 3.”

→ More replies (2)
→ More replies (4)
→ More replies (2)

10

u/OmarRIP Jan 05 '19 edited Jan 06 '19

This one is fun.

I’ll assume weak typing/C-syntax and rules; also going to treat this an expression rather than any sort of statement.

My answer:

If x initially had a non-zero (i.e. true) value, then the expression evaluates to 2 or 2.5 depending on if x is an integral or floating point, respectively. Also x has been assigned that same value.

Otherwise, x == 0 and the expression simply evaluates to ;.

Edits: Fixed spoiler formatting; Corrected switched cases.

4

u/Skitz-Scarekrow Jan 06 '19

C is my main focus and I was looking at that shit like "is this a trick? Isn't it 2.5 float?" Thanks for reassuring me that I can math

→ More replies (8)
→ More replies (2)
→ More replies (32)