Reputation: 10132
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
Upvotes: 2
Views: 585
Reputation: 158
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 !
Upvotes: 0
Reputation: 31242
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 char
array.
Upvotes: 0
Reputation:
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.
Upvotes: 2