What is the default encoding for C strings?

后端 未结 5 882
后悔当初
后悔当初 2020-12-01 11:34

I know that C strings are char[] with a \'\\0\' in the last element. But how are the chars encoded?

Update: I found this cool link which talks about many other prog

5条回答
  •  青春惊慌失措
    2020-12-01 11:49

    A c string is pretty much just a sequence of bytes. That means, that it does not have a well-defined encoding, it could be ASCII, UTF8 or anything else, for that matter. Because most operating systems understand ASCII by default, and source code is mostly written with ASCII encoding, so the data you will find in a simple (char*) will very often be ASCII as well. Nonetheless, there is no guarantee that what you get out of a (char*) will be UTF8 or even KOI8.

提交回复
热议问题