It seems that you're using an outdated browser. Some things may not work as they should (or don't work at all).
We suggest you upgrade newer and better browser like: Chrome, Firefox, Internet Explorer or Opera

×
avatar
lupineshadow: But you wrote 1 + "1"
avatar
dtgreene: In C, 1 + "1" and "1" + 1 are the same
An integer literal and a string literal which gets upgraded to a memory address, yes.

The resulting memory address is implementation-dependent, platform-dependent, you name it.
Post edited May 23, 2023 by lupineshadow
avatar
clarry: "1"[1] would not be a pointer.
It isn't a pointer, but it is an 8-bit integer (char in C terms), and it is necessarily the integer "0".

avatar
dtgreene: In C, 1 + "1" and "1" + 1 are the same
avatar
lupineshadow: An integer literal and a string literal which gets upgraded to a memory address, yes.

The resulting memory address is implementation-dependent, platform-dependent, you name it.

So how is it any less defined than 2 + "2"?
I think you mixed things up. 1 + "1" is more defined than 2 + "2", as the former points inside the string, while the latter does not.
Post edited May 23, 2023 by dtgreene
avatar
dtgreene: I think you mixed things up. 1 + "1" is more defined than 2 + "2", as the former points inside the string, while the latter does not.
As clarry said, don't dereference it and you're fine.

Subtract 2 from it and you have yourself a valid pointer again.

In any compiler.

So please explain why it is undefined again?
avatar
dtgreene: I think you mixed things up. 1 + "1" is more defined than 2 + "2", as the former points inside the string, while the latter does not.
avatar
lupineshadow: As clarry said, don't dereference it and you're fine.

Subtract 2 from it and you have yourself a valid pointer again.

In any compiler.

So please explain why it is undefined again?
Actually, simply doing pointer arithmetic past the end of the array appears to be undefined behavior, though C++ may allow a pointer to point one past the end of the array (which might make 2 + "2" defined if you don't dereference it, but not not 3 + "3").
ADA FTW.