Traditional Culture Encyclopedia - Traditional culture - char a = ' abcd

char a = ' abcd

Interesting. How to meet two similar problems in one day? Ok, I repeat it here:

In C, there is no essential difference between characters and integers. Char can be regarded as an integer of 1 byte, short as a 2-byte wide character, and int as a 4-byte wide character.

Therefore, "A" means the character "A", "ab" means a 2-byte integer or a wide character, and "abcd" means a 4-byte integer or a wide character. But only 1 byte, 2 bytes and 4 bytes are supported.

Char c =' a// Of course it is.

Char c =' ab// is equivalent to the integer char c=0x6 162. Because the' a' character means 0x6 1 and the' b' character means 0x62. But because' ab' is 2 bytes, it will give an integer truncation warning when it is assigned to char.

Char c =' abc// is equivalent to the integer char c=0x006 16263, and a warning will also be given.

Char c =' abcd// is equivalent to the integer char c=0x6 1626364, and a warning will also be given.

Char c =' abcde// exceeds the maximum integer byte length of 4. Error handling