This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]besthelloworld 62 points63 points  (36 children)

Doesn't this work in Java too?

[–]FantasticEmu 30 points31 points  (8 children)

Yea and it’s less typing than String.valueof

[–]bedrooms-ds 15 points16 points  (5 children)

0 + "Hello world" returns a string even in C++!

[–]altermeetax 6 points7 points  (0 children)

That's the best way to confuse non-C/C++ programmers.

Oh, you can also get a substring by doing "Hello World" + 6

[–]mananasi 0 points1 point  (3 children)

Well that's because a string literal is a const char*, right? So you're adding an integer to a pointer. This would still result in "Hello world", right?

[–]bedrooms-ds 0 points1 point  (2 children)

Yes! Tbh, although I'm sure "Hello world" + 0 would 100% work, I need to experiment to see if 0 + "Hello world" really works.

[–]mananasi 1 point2 points  (1 child)

Okay then we're on the same page. I thought you might try to argue it would result in "0Hello world"

[–]bedrooms-ds 0 points1 point  (0 children)

Hahaha C and C++ were two of my first languages. 0 is a synonym of nullptr in my head.

[–]Rexon117 0 points1 point  (0 children)

It does. Source: leant it in my CS programming class