As other answers have mentioned, '/0'
is not a null termination character, '\0'
is.
You might expect that specifying more than one character in a character literal might generate an error; unfortunately (at least in this case) C allows 'multi-character' literal characters - but the exact behavior of multi-character literals is implementation defined (6.4.4.4/2 "Character constants"):
An integer character constant has type int. The value of an integer character constant containing a single character that maps to a single-byte execution character is the numerical value of the representation of the mapped character interpreted as an integer. The value of an integer character constant containing more than one character (e.g., 'ab'), or containing a character or escape sequence that does not map to a single-byte execution character, is implementation-defined.
So your '/0'
'character' ends up being some implementation defined int value that gets truncated when stored in d[2]
. Your compiler might generate a warning for 'multi-character' literals, but that would probably also depend on the exact options you give the compiler.
For example, I get the following warning from GCC (I happen to have -Wall set):
C:\temp\test.cpp:6:14: warning: multi-character character constant
In my tests with MSVC and MinGW, the value of '/0'
is 0x00002f30
, so d[2] = '/0'
ends up being equivalent to d[2] = '0'
.