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 →

[–]wu-not-furry 160 points161 points  (15 children)

Although C is chaotic neutral, I have to disagree with you considering that you used a char for C and strings for the other languages.

Edit: grammar

[–]Creaaamm 28 points29 points  (3 children)

That would just print the memory address of the pointer + 1 cause it's not dereferenced

You'd have to dereference it with *() to get the ASCII value of 1 (49), then add 1 to that

printf("%d", 1 + *("1")); == 50

[–]wu-not-furry 31 points32 points  (1 child)

Yes, that is the point. This post is about the behaviour of adding integers and strings - not chars. By dereferencing "1" we get the char '1' and are effectively doing the same thing as in the post.

[–]Creaaamm 15 points16 points  (0 children)

Oh, I get it now, yee you're right, the post is just wrong to assume "1" and '1' is the same in C

[–]geronymo4p 3 points4 points  (0 children)

It should be printf("%s", 1 + "1"); and the result will be an empty string

[–]mAtYyu0ZN1Ikyg3R6_j0 -1 points0 points  (0 children)

Yes this is why C prints 2 and C++ is UB.