Question regarding Wide character

I have question regarding wide character. I have been reading article saying that this datatype is used for non latin characters for example Japanese or Chinese. but my question is according to this link
http://www.hscripts.com/tutorials/cpp/cpp-datatypes/wchart-datatype.php

"This datatype occupies "2 or 4" bytes"

My question is why this data type occupies dynamic length of data.

And how I could tell in which case it occupies what amount of data

Thanks
closed account (28poGNh0)
The size of data types probably depend on whice platform you're using
for exp int in 16-bit environment is 2 bytes ,in 32-bit environment is 4bytes

a wide character take 16 bit width which equal to 2 bytes never head about 4 bytes

you can know the size of datatypes by using the sizeof keyword as ulistrated in this simple exp

1
2
3
4
5
6
7
8
9
# include <iostream>
using namespace std;

int main()
{
	cout << sizeof(wchar_t) << endl;

	return 0;
}
It is implementation-defined, which means it differs between compilers and platforms.

Specifically, it's 2 bytes on Windows, which adopted Unicode back when it was limited to 16 bits, and failed to upgrade.

It's 4 bytes pretty much everywhere else (e.g. Linux), since that's how much is necessary to represent any single Unicode code point.

You can find out how big it is by compiling a test program and printing sizeof(wchar_t)
Last edited on
Topic archived. No new replies allowed.