daniyalahmad daniyalahmad - 1 year ago 59
C Question

Why char is of 1 byte in C language

Why is a

byte long in C? Why is it not
bytes or
bytes long?

What is the basic logic behind it to keep it as
byte? I know in Java a
bytes long. Same question for it.

Answer Source

char is 1 byte in C because it is specified so in standards.

The most probable logic is. the (binary) representation of a char (in standard character set) can fit into 1 byte. At the time of the primary development of C, the most commonly available standards were ASCII and EBCDIC which needed 7 and 8 bit encoding, respectively. So, 1 byte was sufficient to represent the whole character set.

OTOH, during the time Java came into picture, the concepts of extended charcater sets and unicode were present. So, to be future-proof and support extensibility, char was given 2 bytes, which is capable of handling extended character set values.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download