I have started learning C++
. And now I am learning about fundamental types. There I read that sizeof(char) = 1
always.
So my question is why is it so? Is there a intuitive reason or historical reason behind this. I mean they could've chosen any number like 2
or 3
but instead it is 1
. So there must be a reason.
PS: I know that in C++ a byte is not necessarily 8-bits. I have read that:
The fundamental storage unit in the C + + memory model is the byte. A byte is at least large enough to contain any member of the basic execution character set and is composed of a contiguous sequence of bits, the number of which is implementation-defined.
Can we find the reason for sizeof(char) = 1
using the above quote and maybe using some other quote from the C++ standard.
Edit:
I think the following quote from the standard:
Objects declared as characters (char) shall be large enough to store any member of the implementation’s basic character set.
combined with the first quote given in my question can answer my question. Also, by implementation's basic character set i suppose they mean basic source character set and not basic execution character set. But i am not sure if this is correct. Also, i am not 100% sure if these 2 quotes explain why sizeof(char) = 1
.