Sanchit Batra
Sanchit Batra

Reputation: 196

Why use a char array to store contents of a file opened in binary mode?

So from what I understand, when you open a file in binary mode using C++ the contents would be 0s and 1s right? If so, why would the official documentation about input/output with files use a char* array to store the contents? If we're only storing 0s and 1s, why not use a short/int?

Upvotes: 1

Views: 328

Answers (1)

Jonesinator
Jonesinator

Reputation: 4216

The interpretations of short and int are architecture dependent while char is not. This is due to endianness where the bytes of these datatypes can be interpreted in different orders.

Upvotes: 2

Related Questions