hi, every one , i am from china, here is a question about how variables be allocated on memory.
my code is as follows, Let me explain it. the complex symbol "我" is Chinese word which means "Me" or "I". here I use it for demonstration. you don't need to know its meaning, what you should know is the each word of Chinese occupy two bytes(16bits).
I found
1 me = 0xced2;
2)*pc = 0xce
3 *(pc + 1) = 0xd2
My question is why not *pc is 0xd2 and *(pc + 1) is 0xce?
Because "我" is a string literal. Actual binary value and encodingg depends on data and compiler.
'我' is a (on the first glance) character. It is only 1 byte in size. And you cannot make it larger.
However there is a thing, called multicharacter literals. They are silently created when more than single char is inside character literal. They are not chars, they are ints and their value is implementation defined. It is "feature" which should be avoided. Increase warning level of your compiler so it will warn you about this: http://puu.sh/iU5ur/6414ed1334.png
> My question is why not *pc is 0xd2 and *(pc + 1) is 0xce?
... or an ordinary character literal containing a single c-char not representable in the execution character set, is conditionally-supported, has type int, and has an implementation-defined value. - IS
On the implementation used, '我' is an ordinary character literal containing a single c-char (a member of the source character set) not representable in the execution character set.