質問

My professor mentioned that byte ordering (endianess) is not an issue for standard C String (Char arrays):

for ex: char[6]="abcde";

But he did not explain why?

Any explanations for this will be helpful

役に立ちましたか?

解決 2

A char takes up only one byte, thats why the ordering does not matter. for example, int has 4 bytes and these bytes could be arranged in little-endian and big-endian`.

Eg: 0x00010204 can be arranged in two ways in memory:

04 02 01 00 or 00 01 02 04

char being a single byte will be fetched as single byte to CPU. and String is just a chararray.

他のヒント

Endianess only matters when you have multi-byte data (like integers and floating point numbers). Standard C strings consist of 1-byte characters, so you don't need to worry about endianness.

Smallest Unit of memory storage is 1 Byte, If you have a 4 byte value ( ex : 0x01234567 ) It will be arranged and fetched in the order of Endianness in contigous locations

Big Endian : 01 23 45 67 Little Endian : 67 45 23 01

Whereas for a 1 byte Value it can be fetched from one memory location itself since that is the smallest block of memory , with no need for byte ordering .

Hope this Helps !

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top