I use sizeof() method to get the memory size of char variable. i.e.,I write such a code in Xcode:
char a = '1';
size_t size = sizeof(a);
I find the size is 1.So what is this character's encoding type? UTF-8 or another?
I use sizeof() method to get the memory size of char variable. i.e.,I write such a code in Xcode:
char a = '1';
size_t size = sizeof(a);
I find the size is 1.So what is this character's encoding type? UTF-8 or another?
You'd have to know this before using the character, just as you are expected to know the encoding of a string before you can interpret it correctly.
You cannot determine the encoding without prior knowledge.
The sizeof
method is not enough to determine what the encoding of a character is.
In general, you must be told what encoding is being used before being able to interpret characters.
As stated in a comment, look here for some information on C string encoding: What is the default encoding for C strings?
For some character literals the C Standard defines a fixed value (the digits if I remembers correctly) for others (letters) the C Standard leaves it to the implementation which char-set/encoding to use.