Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a "byte" in C / C++

For example, here's a reference for fread:

size_t fread ( void * ptr, size_t size, size_t count, FILE * stream );

Reads an array of count elements, each one with a size of "size bytes"... So how many BITS will read an fread(&x, 1, 1, stream)? Eight or CHAR_BIT?

like image 837
user389419 Avatar asked Nov 28 '11 13:11

user389419


People also ask

What is a byte data type?

The BYTE data type stores any kind of binary data in an undifferentiated byte stream. Binary data typically consists of digitized information, such as spreadsheets, program load modules, digitized voice patterns, and so on. The term simple large object refers to an instance of a TEXT or BYTE data type.

What is byte example?

You can think of a byte as one letter. For example, the letter 'h' is one byte or eight bits, and the word 'hope' is four bytes or 32 bits (4*8). When looking at the size of a file, a byte is the smallest measurement size listed in operating systems.


1 Answers

C99, §3.6:

byte

addressable unit of data storage large enough to hold any member of the basic character set of the execution environment

and §5.2.4.2.1:

CHAR_BIT — number of bits for smallest object that is not a bit-field (byte)

Thus, a "byte" contains CHAR_BIT bits.

like image 128
Stephen Canon Avatar answered Sep 28 '22 06:09

Stephen Canon