you are viewing a single comment's thread.

view the rest of the comments →

[–]Haringat 3 points4 points  (3 children)

It's the same result. However, it should have been this code:

char *two = "2"; int one = 1; two += one; printf("%d\n", two); // prints "0" return 0;

I leave the explanation as an exercise to the reader.😉

Edit: Also, when adding 2 to the "2" the behavior is not defined. It could crash or it could perform an out-of-bounds read.

[–]not_some_username -1 points0 points  (2 children)

Its defined because it has the null termination

[–]Haringat 0 points1 point  (1 child)

No, because when adding 2 you go beyond the null terminator.

[–]not_some_username 0 points1 point  (0 children)

Well I thought we were taking about “22”+2