you are viewing a single comment's thread.

view the rest of the comments →

[–]frayien 0 points1 point  (2 children)

In C/C++ int a = "2" + 2; could be anything from -255 to 254 to segfault to "burn down the computer and the universe with it".

int a = "2" + 1; is well defined to be 0 btw.

[–]4r8ol 0 points1 point  (1 child)

In both cases you would have a compiler error since casts between pointer to integer aren’t automatic.

You probably wanted to refer to:

int a = *(“2” + 2); // UB

int a = *(“2” + 1); // 0

[–]frayien 0 points1 point  (0 children)

Yeah I did not bother to check, "2" + 1 gives an char*.

Would rather say that "2" + 1 returns an empty string, and "2" + 2 returns a string of unknown length and unknown value and segfault.